Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 API save and load param with V1 API #3574

Closed
wants to merge 4 commits into from

Conversation

tensor-tang
Copy link
Contributor

fix #3519

@tensor-tang tensor-tang requested a review from luotao1 August 18, 2017 13:34
@tensor-tang tensor-tang changed the title save and load param with V1 API V2 API save and load param with V1 API Aug 18, 2017
@tensor-tang
Copy link
Contributor Author

ERROR: test_init_from_tar (main.TestParameters)
[13:53:24] : [Step 1/1] ----------------------------------------------------------------------
[13:53:24] : [Step 1/1] Traceback (most recent call last):
[13:53:24] : [Step 1/1] File "test_parameters.py", line 112, in test_init_from_tar
[13:53:24] : [Step 1/1] p2.init_from_tar(file1)
[13:53:24] : [Step 1/1] File "/paddle/build/python/build/lib-python/paddle/v2/parameters.py", line 377, in init_from_tar
[13:53:24] : [Step 1/1] tar_param = Parameters.from_tar(f)
[13:53:24] : [Step 1/1] File "/paddle/build/python/build/lib-python/paddle/v2/parameters.py", line 364, in from_tar
[13:53:24] : [Step 1/1] params.deserialize(param_name, f)
[13:53:24] : [Step 1/1] File "/paddle/build/python/build/lib-python/paddle/v2/parameters.py", line 306, in deserialize
[13:53:24] : [Step 1/1] self.set(name, arr.reshape(self.get_shape(name)))
[13:53:24] : [Step 1/1] ValueError: cannot reshape array of size 0 into shape (1,256)

Test_parameters failed since no gradient machine have initialed, so to_tar saved non tar.

Will update.

And maybe we need add more test case with gradient machine initialed

@luotao1
Copy link
Contributor

luotao1 commented Aug 21, 2017

@reyoung 要在v2的parameter里面用header,而不是直接写死

f.write(struct.pack("IIQ", 0, 4, size))

请问你觉得什么方式比较好?

  • 目前PR的方式,即调用c++端parameter
  • 其他?比如在python端写个获取c++端header的接口?

while buf: # f.write crashes with big data blog.
f.write(buf)
wrote_size += 65535
if len(self.__gradient_machines__) == 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(self.__gradient_machines__) == 0len(self.__gradient_machines__) != 0 分别是什么情况下? 为啥要用这个判断?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一般来说,以DeepSpeech2为例,在真正保存参数之前,实际是已经有了self.__gradient_machines__,所以走进len(self.__gradient_machines__) != 0的分支。

在现有的单测里面,是会进入len(self.__gradient_machines__) == 0的分支。

param = __get_parameter_in_gradient_machine__(
each_gradient_machine, name)
assert isinstance(param, api.Parameter)
filename = 'tmp_param_file'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filename是写死的,每次保存都会覆盖?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是写死的,但是每次用完后会删掉,所以只是一个临时的。
之所以要这么用,是因为已有的V1 API接口目前只提供了从文件名的saveload

@luotao1
Copy link
Contributor

luotao1 commented Aug 22, 2017

由于目前这样的写法和c++端更加紧密了,v2的目的是尽可能和c++端解耦。所以有几个问题:

  1. 这个header的format什么时候会填充呢?是paddle.init(use_mkldnn=True)的时候进行填充?默认填充都是0,4,size?
  2. 不同param间的format应该也可以不一样,这部分是在trainer/config_parser.py端可以确定,还是必须c++端确定?

@tensor-tang
Copy link
Contributor Author

这个header的format什么时候会填充呢?是paddle.init(use_mkldnn=True)的时候进行填充?默认填充都是0,4,size?

MKLDNN的param里的header format会在MKLDNN layer里面到forward之前才能被确认。默认是0。

不同param间的format应该也可以不一样,这部分是在trainer/config_parser.py端可以确定,还是必须c++端确定?

不同param间的format是可以不一样的,但是format的确认首先还是在C++端,不过要从Python端取出来是需要另外加接口才可以。

@luotao1
Copy link
Contributor

luotao1 commented Aug 22, 2017

如果只是header问题,那么可以写一个接口,这里从c++端获取header即可。

@tensor-tang
Copy link
Contributor Author

Can refine later if necessary.

@tensor-tang tensor-tang deleted the v2saveheader branch September 12, 2017 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Parameter Header in V2 API
3 participants