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

wrap Module properties #2541

Merged
merged 1 commit into from
Dec 12, 2022
Merged

Conversation

cgarciae
Copy link
Collaborator

Co-authored-by: Marcus Chiam marcus.chiam@hotmail.com

What does this PR do?

Fixes #2537. Adds wrappers for property attributes for Module primarily to catch AttributeErrors in order to give a better error message (see discussion in #2537). Implementation follows the same strategy for our current method wrapper but specializes it for propertys.

@google-cla
Copy link

google-cla bot commented Oct 17, 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).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@codecov-commenter
Copy link

codecov-commenter commented Oct 17, 2022

Codecov Report

Merging #2541 (63ffcfb) into main (521f516) will increase coverage by 0.08%.
The diff coverage is 88.46%.

@@            Coverage Diff             @@
##             main    #2541      +/-   ##
==========================================
+ Coverage   79.47%   79.55%   +0.08%     
==========================================
  Files          49       49              
  Lines        5204     5249      +45     
==========================================
+ Hits         4136     4176      +40     
- Misses       1068     1073       +5     
Impacted Files Coverage Δ
flax/linen/module.py 92.27% <87.75%> (-0.45%) ⬇️
flax/errors.py 87.75% <100.00%> (+0.38%) ⬆️
flax/core/scope.py 89.77% <0.00%> (-0.03%) ⬇️
flax/training/prefetch_iterator.py 0.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@cgarciae cgarciae force-pushed the fix-property-error branch 2 times, most recently from ca6c3e3 to 1afd873 Compare October 18, 2022 21:52
flax/linen/module.py Show resolved Hide resolved
flax/linen/module.py Outdated Show resolved Hide resolved
flax/linen/module.py Outdated Show resolved Hide resolved
flax/errors.py Show resolved Hide resolved
Copy link
Collaborator

@levskaya levskaya left a comment

Choose a reason for hiding this comment

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

Looks good - thank you!

Just one Q: and forgive me since we talked about this before and I'm spacing, but just for posterity: why do we check for staticmethod/classmethod inside _get_local_descriptor_names after excluding callables?

@cgarciae
Copy link
Collaborator Author

@levskaya curiously staticmethod and classmethod objects are not callable themselves, their __get__ method returns a callable.

@cgarciae cgarciae force-pushed the fix-property-error branch 5 times, most recently from 5a7ba97 to b9ca59e Compare December 6, 2022 00:23
@copybara-service copybara-service bot merged commit 063f541 into google:main Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AttributeError isn't raised correctly from properties of linen modules
3 participants