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

fix keraslayer set and get attr dunders #5008

Merged
merged 3 commits into from Jan 5, 2024
Merged

Conversation

timmysilv
Copy link
Contributor

@timmysilv timmysilv commented Jan 5, 2024

Context:
Fixes #4999. We re-implemented the default setattr and getattr dunders for KerasLayer (needed to modify the QNode saved on the layer) but we should have called super(), because keras.layer.Layer has its own custom implementation that we needed to use. Our TorchLayer already calls super in these cases.

Note - our existing tests were passing because the weights used had custom names ("w1", "w2", etc.), and this issue only comes up when your weights are named "weights" (which is a rather common case, I'm sure).

Description of the Change:

  • Replace our default-handling of get/set-attr dunders with a call to super()
  • add a test case matching the one in the bug report using the "weights" identifier

Benefits:
Models using KerasLayer can be saved and loaded properly!

Possible Drawbacks:
N/A

Related GitHub Issues:
Reported initially in #4999, same as #4611 but for Keras

@timmysilv timmysilv added this to the v0.34 milestone Jan 5, 2024
Copy link
Contributor

github-actions bot commented Jan 5, 2024

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@timmysilv timmysilv requested a review from a team January 5, 2024 19:32
@timmysilv timmysilv enabled auto-merge (squash) January 5, 2024 19:42
Copy link

codecov bot commented Jan 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (v0.34.0-rc0@30a4634). Click here to learn what that means.

Additional details and impacted files
@@              Coverage Diff               @@
##             v0.34.0-rc0    #5008   +/-   ##
==============================================
  Coverage               ?   99.66%           
==============================================
  Files                  ?      392           
  Lines                  ?    35282           
  Branches               ?        0           
==============================================
  Hits                   ?    35165           
  Misses                 ?      117           
  Partials               ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@timmysilv timmysilv merged commit c89c26c into v0.34.0-rc0 Jan 5, 2024
34 checks passed
@timmysilv timmysilv deleted the keras-attr-fix branch January 5, 2024 19:59
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.

None yet

3 participants