-
Notifications
You must be signed in to change notification settings - Fork 575
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
Fixes bug in tape.set_parameters() #923
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -704,7 +704,7 @@ def set_parameters(self, params, trainable_only=True): | |
[4, 1, 6] | ||
""" | ||
if trainable_only: | ||
iterator = zip(self.trainable_params, params) | ||
iterator = zip(sorted(self.trainable_params), params) | ||
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. How come that sortedness only mattered here, wouldn't we want the sorting to happen always when querying the trainable parameters? So as to change the def of the 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. Hey @antalszava, in fact, this is the only place in the code base where the order of I suppose this was just me being cautious wrt overhead - rather than sorting + converting to a list everywhere 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. That's good to know, thanks! Yes, I also think that the overhead aspect necessitates that sorting only happens at certain times. One thing that could be nice is to leave a comment explaining why the sorting is needed here, but not elsewhere. |
||
required_length = self.num_params | ||
else: | ||
iterator = enumerate(params) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -498,6 +498,24 @@ def test_setting_free_parameters(self, make_tape): | |
params[4], | ||
] | ||
|
||
def test_setting_parameters_unordered(self, make_tape, monkeypatch): | ||
"""Test that an 'unordered' trainable_params set does not affect | ||
the setting of parameter values""" | ||
tape, params = make_tape | ||
new_params = [-0.654, 0.3] | ||
|
||
with monkeypatch.context() as m: | ||
m.setattr(tape, "_trainable_params", {3, 1}) | ||
tape.set_parameters(new_params) | ||
|
||
assert tape.get_parameters(trainable_only=False) == [ | ||
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. How about moving the 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. done! |
||
params[0], | ||
new_params[0], | ||
params[2], | ||
new_params[1], | ||
params[4], | ||
] | ||
|
||
def test_setting_all_parameters(self, make_tape): | ||
"""Test that all parameters are correctly modified after construction""" | ||
tape, params = make_tape | ||
|
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.
A result of my text editor fixing incorrect markdown syntax!