Fix ReversibleEmbedding failing with .summary()#22434
Fix ReversibleEmbedding failing with .summary()#22434hertschuh merged 2 commits intokeras-team:masterfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses a TypeError in ReversibleEmbedding.compute_output_shape that occurs during model.summary() calls. The change aligns the method's signature with the build method by renaming input_shape to inputs_shape. While this fixes the bug, I have added a comment with a suggestion to improve overall API consistency.
| def compute_output_shape(self, inputs_shape, reverse=False): | ||
| output_shape = list(inputs_shape) |
There was a problem hiding this comment.
While this change fixes the TypeError by making compute_output_shape internally consistent with this class's build method, it moves further away from the established Keras API convention. Base layers like Embedding and Layer use input_shape for the shape parameter in build and compute_output_shape methods.
The root of the issue is the build method's use of inputs_shape. For better long-term maintainability and API consistency, I'd recommend changing the build method's parameter to input_shape and reverting this change. This would align ReversibleEmbedding with its base classes and the rest of the Keras API.
| def compute_output_shape(self, inputs_shape, reverse=False): | |
| output_shape = list(inputs_shape) | |
| def compute_output_shape(self, input_shape, reverse=False): | |
| output_shape = list(input_shape) |
References
- The Keras API design guidelines emphasize naming consistency, both internally and with established conventions (line 71). The suggested change aims to restore consistency with the base
LayerandEmbeddingclasses, which useinput_shapeas the convention for the input shape parameter. This also aligns with respecting existing repository patterns (line 219). (link)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #22434 +/- ##
==========================================
- Coverage 84.93% 83.07% -1.87%
==========================================
Files 596 596
Lines 66936 67451 +515
Branches 10449 10512 +63
==========================================
- Hits 56855 56034 -821
- Misses 7292 8700 +1408
+ Partials 2789 2717 -72
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
hertschuh
left a comment
There was a problem hiding this comment.
Thanks for figuring out this bug!
Actually, you should do the opposite fix, i.e. change build to use input_shape instead of inputs_shape.
themavik
left a comment
There was a problem hiding this comment.
Good fix for the summary display issue with ReversibleEmbedding. The approach correctly handles the case where the layer has a different output shape format. Clean and minimal change.
|
Done |
Summary
Fix
ReversibleEmbedding.compute_output_shape()failing when called bymodel.summary().The
buildmethod usesinputs_shapeas its parameter name, so_build_shapes_dictcontains{"inputs_shape": ...}. Whensummary_utilscallscompute_output_shape(**_build_shapes_dict), it passesinputs_shapeas a keyword argument, butcompute_output_shapeexpectedinput_shape(singular), causing aTypeError.The fix renames the parameter from
input_shapetoinputs_shapeto match thebuildsignature.Fixes #22432