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

Copy loss and metric to prevent side effect #16360

Merged
merged 2 commits into from
Apr 7, 2022

Conversation

drauh
Copy link
Contributor

@drauh drauh commented Apr 4, 2022

This is a possible solution for #16356, a possible error that could be raised when saving weights. This happens because the inputted dict to the compile method is modified by a side effect, modifying also the keras.Model.loss attribute.

@google-cla
Copy link

google-cla bot commented Apr 4, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

For more information, open the CLA check for this pull request.

@gbaned gbaned requested a review from fchollet April 5, 2022 14:35
@google-ml-butler google-ml-butler bot added the keras-team-review-pending Pending review by a Keras team member. label Apr 5, 2022
Copy link
Member

@fchollet fchollet left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.

This happens because the inputted dict to the compile method is modified by a side effect

Do you know where this happens, specifically?

keras/engine/compile_utils.py Outdated Show resolved Hide resolved
keras/engine/compile_utils.py Outdated Show resolved Hide resolved
@fchollet fchollet removed the keras-team-review-pending Pending review by a Keras team member. label Apr 6, 2022
@drauh
Copy link
Contributor Author

drauh commented Apr 6, 2022

It's happening in map_missing_dict_keys. Here, after the check, it's guaranteed to be a dict so I made the copy there. The test I wrote to check this issue is passing also with this solution.

Copy link
Member

@fchollet fchollet left a comment

Choose a reason for hiding this comment

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

That looks good! Thank you.

@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Apr 6, 2022
@copybara-service copybara-service bot merged commit 3148d05 into keras-team:master Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to pull Ready to be merged into the codebase size:S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants