Skip to content

Fix ReversibleEmbedding failing with .summary()#22434

Merged
hertschuh merged 2 commits intokeras-team:masterfrom
rstar327:fix-reversible-embedding-summary
Mar 23, 2026
Merged

Fix ReversibleEmbedding failing with .summary()#22434
hertschuh merged 2 commits intokeras-team:masterfrom
rstar327:fix-reversible-embedding-summary

Conversation

@rstar327
Copy link
Contributor

Summary

Fix ReversibleEmbedding.compute_output_shape() failing when called by model.summary().

The build method uses inputs_shape as its parameter name, so _build_shapes_dict contains {"inputs_shape": ...}. When summary_utils calls compute_output_shape(**_build_shapes_dict), it passes inputs_shape as a keyword argument, but compute_output_shape expected input_shape (singular), causing a TypeError.

The fix renames the parameter from input_shape to inputs_shape to match the build signature.

Fixes #22432

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 TypeError encountered when attempting to generate a model summary for ReversibleEmbedding layers. The issue stemmed from a mismatch in parameter names between the build method's internal shape dictionary and the compute_output_shape method's expected argument. By standardizing the parameter name, the change ensures model.summary() can correctly process ReversibleEmbedding layers without errors.

Highlights

  • Bug Fix: Fixed a TypeError that occurred when calling model.summary() on a ReversibleEmbedding layer.
  • Parameter Renaming: Renamed the input_shape parameter to inputs_shape in the ReversibleEmbedding.compute_output_shape method to align with the build method's signature.

🧠 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
  • keras/src/layers/core/reversible_embedding.py
    • Renamed the input_shape parameter to inputs_shape in the compute_output_shape method to fix a TypeError.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines +150 to +151
def compute_output_shape(self, inputs_shape, reverse=False):
output_shape = list(inputs_shape)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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
  1. 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 Layer and Embedding classes, which use input_shape as the convention for the input shape parameter. This also aligns with respecting existing repository patterns (line 219). (link)

@codecov-commenter
Copy link

codecov-commenter commented Mar 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.07%. Comparing base (dc3bdb1) to head (9ab11ef).
⚠️ Report is 24 commits behind head on master.

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     
Flag Coverage Δ
keras 82.90% <100.00%> (-1.87%) ⬇️
keras-jax 59.99% <100.00%> (-2.34%) ⬇️
keras-numpy 54.28% <100.00%> (-0.44%) ⬇️
keras-openvino 51.19% <100.00%> (+1.01%) ⬆️
keras-tensorflow 61.23% <100.00%> (-2.35%) ⬇️
keras-torch 60.05% <100.00%> (-2.33%) ⬇️
keras.applications ?
keras.applications-jax ?
keras.applications-numpy ?
keras.applications-openvino ?
keras.applications-tensorflow ?
keras.applications-torch ?

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@hertschuh hertschuh 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 figuring out this bug!

Actually, you should do the opposite fix, i.e. change build to use input_shape instead of inputs_shape.

Copy link

@themavik themavik left a comment

Choose a reason for hiding this comment

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

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.

@rstar327
Copy link
Contributor Author

Done

@rstar327 rstar327 requested a review from hertschuh March 23, 2026 22:40
Copy link
Collaborator

@hertschuh hertschuh left a comment

Choose a reason for hiding this comment

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

Thanks!

@hertschuh hertschuh merged commit 38d9543 into keras-team:master Mar 23, 2026
8 checks passed
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.

ReversibleEmbedding fails with ".summary()"

5 participants