-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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 header #3619
Closed
+63
−37
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ def test_serialization(self): | |
params.__append_config__(__rand_param_config__("param_1")) | ||
|
||
for name in params.names(): | ||
param = params.get(name) | ||
param = params.get(name)[1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里只测试了[1],有没有办法也测试[0]的值?代表的是header的值对吧 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [0]代表header的值。这里header默认都是0,所以都没做测试。可以等以后mkldnn的header进来,再另加一个单测。 |
||
param[:] = numpy.random.uniform( | ||
-1.0, 1.0, size=params.get_shape(name)) | ||
params.set(name, param) | ||
|
@@ -57,8 +57,8 @@ def test_serialization(self): | |
|
||
for name in params.names(): | ||
self.assertEqual(params.get_shape(name), params_dup.get_shape(name)) | ||
p0 = params.get(name) | ||
p1 = params_dup.get(name) | ||
p0 = params.get(name)[1] | ||
p1 = params_dup.get(name)[1] | ||
self.assertTrue(numpy.isclose(p0, p1).all()) | ||
|
||
def test_initializer(self): | ||
|
@@ -75,7 +75,7 @@ def initializer(name): | |
param_attr=ParamAttr( | ||
name="fc.w", initializer=initializer)) | ||
params = parameters.create(y) | ||
val = params["fc.w"] | ||
header, val = params["fc.w"] | ||
assert val.shape == (3, 2) | ||
expected = numpy.array([[1, 1], [1, 2], [1, 1]], numpy.float32) | ||
assert numpy.logical_and.reduce(numpy.reshape(val == expected, 6)) | ||
|
@@ -86,7 +86,7 @@ def get_param(names, size): | |
for k, v in zip(names, size): | ||
p.__append_config__(__rand_param_config__(k, v)) | ||
for name in p.names(): | ||
param = p.get(name) | ||
param = p.get(name)[1] | ||
param[:] = numpy.random.uniform( | ||
-1.0, 1.0, size=p.get_shape(name)) | ||
p.set(name, param) | ||
|
@@ -112,16 +112,16 @@ def get_parames(): | |
p2.init_from_tar(file1) | ||
for name in p1.names(): | ||
self.assertEqual(p1.get_shape(name), p2.get_shape(name)) | ||
v1 = p1.get(name) | ||
v2 = p2.get(name) | ||
v1 = p1.get(name)[1] | ||
v2 = p2.get(name)[1] | ||
self.assertTrue(numpy.isclose(v1, v2).all()) | ||
|
||
p1, file1, p2, file2 = get_parames() | ||
p1.init_from_tar(file2) | ||
for name in p1.names(): | ||
self.assertEqual(p1.get_shape(name), p2.get_shape(name)) | ||
v1 = p1.get(name) | ||
v2 = p2.get(name) | ||
v1 = p1.get(name)[1] | ||
v2 = p2.get(name)[1] | ||
self.assertTrue(numpy.isclose(v1, v2).all()) | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里为什么需要改动inference的code?那么Training的时候也需要改吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
因为原来:
value = parameter.get(name)
现在:
header, value = parameter.get(name)
Training
的时候,改在parameters.py
里面了