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

Ensures that the layer is marked as built when the build is not overriden #20880

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

james77777778
Copy link
Contributor

@james77777778 james77777778 commented Feb 8, 2025

Fix #20871

This PR ensures that the layer is marked as built when the build is not overriden.

Additionally, this PR cleans up the redundant self.built = True.

@codecov-commenter
Copy link

codecov-commenter commented Feb 8, 2025

Codecov Report

Attention: Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.

Project coverage is 82.25%. Comparing base (b5261a0) to head (1e65b51).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
keras/src/testing/test_case.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #20880      +/-   ##
==========================================
- Coverage   82.25%   82.25%   -0.01%     
==========================================
  Files         561      561              
  Lines       52680    52665      -15     
  Branches     8144     8146       +2     
==========================================
- Hits        43334    43318      -16     
- Misses       7342     7343       +1     
  Partials     2004     2004              
Flag Coverage Δ
keras 82.06% <96.55%> (-0.01%) ⬇️
keras-jax 64.16% <93.10%> (-0.03%) ⬇️
keras-numpy 58.97% <68.96%> (-0.03%) ⬇️
keras-openvino 32.55% <37.93%> (+<0.01%) ⬆️
keras-tensorflow 64.81% <93.10%> (-0.01%) ⬇️
keras-torch 64.23% <86.20%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@@ -23,7 +24,13 @@ def __init__(self, alpha=1.0, **kwargs):
super().__init__(**kwargs)
self.alpha = alpha
self.supports_masking = True
self.built = True

# We can only safely mark the layer as built when build is not
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code snippet seems to be recurring a lot -- could it be added to the base class instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I have moved the logic to Layer._build_at_init() and applied it everywhere.
Note: We cannot directly apply it at the end of Layer.__init__() because it would break some corner cases in the codebase.

Copy link
Collaborator

@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.

LGTM, thank you!

@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review ready to pull Ready to be merged into the codebase size:M
Projects
Status: Approved by Reviewer
5 participants