Skip to content

docs: Improve docstring for RMSNormalization layer#22503

Open
xingzihai wants to merge 1 commit intokeras-team:masterfrom
xingzihai:docs-rms-normalization-clean
Open

docs: Improve docstring for RMSNormalization layer#22503
xingzihai wants to merge 1 commit intokeras-team:masterfrom
xingzihai:docs-rms-normalization-clean

Conversation

@xingzihai
Copy link
Copy Markdown

Summary

This PR improves the docstring for the RMSNormalization layer to provide better documentation for users.

Changes

  1. Fixed misleading statement about scale parameter: The docstring previously said "If scale is enabled, the layer will scale the normalized outputs via a learnable scaling factor." This was misleading because the layer always uses a scale parameter (created in build()). Updated to clarify that the layer always scales the normalized outputs.

  2. Added default values for parameters: Added default values (-1 for axis, 1e-6 for epsilon) to the Args section for clarity.

  3. Improved axis parameter description: Added more detail about the axis parameter, mentioning that it is typically the features axis and -1 is the last dimension.

  4. Added Input shape and Output shape sections: Added these sections to match the documentation style of other normalization layers (e.g., GroupNormalization).

  5. Removed redundant call method docstring: The call method docstring was inconsistent with other normalization layers (LayerNormalization, GroupNormalization) which do not have call method docstrings. The shape description in the docstring was also inaccurate for arbitrary input shapes.

Testing

  • The code changes are documentation-only and do not affect functionality.
  • The example in the docstring works as expected.

Related

This follows the Keras documentation style as described in CONTRIBUTING.md.

- Fixed misleading statement about 'scale' parameter (layer always uses scale)
- Added default values for 'axis' and 'epsilon' parameters
- Added more detailed description for 'axis' parameter
- Added Input shape and Output shape sections
- Removed redundant call method docstring for consistency with other normalization layers
@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 25, 2026

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.

@gemini-code-assist
Copy link
Copy Markdown
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 focuses on enhancing the documentation for the RMSNormalization layer. The changes aim to provide clearer, more accurate, and consistent information for users by refining parameter descriptions, adding default values, and standardizing the documentation structure to align with Keras's established style.

Highlights

  • Scale Parameter Clarification: The docstring was updated to accurately state that the RMSNormalization layer always scales normalized outputs via a learnable scaling factor, correcting a previous misleading statement about conditional scaling.
  • Parameter Default Values: Default values for the axis (-1) and epsilon (1e-6) parameters were explicitly added to the Args section of the docstring for improved clarity.
  • Axis Parameter Description: The description for the axis parameter was enhanced to provide more detail, specifying that it typically refers to the features axis and that -1 denotes the last dimension.
  • Input/Output Shape Documentation: New sections for Input shape and Output shape were added to the docstring, aligning the documentation style with other normalization layers in Keras.
  • Redundant Call Method Docstring Removal: The docstring for the call method was removed to maintain consistency with other Keras normalization layers (e.g., LayerNormalization, GroupNormalization) which do not include call method docstrings.

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

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.

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
Copy Markdown
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 refines the docstrings for the RMSNormalization layer. The changes include clarifying the description of the scale parameter, adding more detailed explanations for the axis and epsilon arguments, and incorporating Input shape and Output shape sections to align with Keras documentation standards. Additionally, a redundant docstring for the call method was removed. The review feedback points out that the axis argument's type hint in the docstring should be updated to reflect its support for a list or tuple of integers, not just a single integer.

@@ -39,7 +37,18 @@ class RMSNormalization(Layer):

Args:
axis: int. The axis on which to perform the normalization.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The type hint for the axis argument is not entirely accurate. While it's often an integer, this layer also supports a list or tuple of integers for normalization over multiple axes, as shown in rms_normalization_test.py. To be more precise and align with the implementation, please update the type to reflect this.

Suggested change
axis: int. The axis on which to perform the normalization.
axis: int or list of ints. The axis or axes on which to perform the normalization.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please address this comment.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.20%. Comparing base (cc7078b) to head (79cf430).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #22503   +/-   ##
=======================================
  Coverage   83.20%   83.20%           
=======================================
  Files         596      596           
  Lines       67621    67621           
  Branches    10531    10531           
=======================================
  Hits        56266    56266           
  Misses       8630     8630           
  Partials     2725     2725           
Flag Coverage Δ
keras 83.03% <ø> (ø)
keras-jax 59.99% <ø> (ø)
keras-numpy 54.25% <ø> (ø)
keras-openvino 51.16% <ø> (ø)
keras-tensorflow 61.23% <ø> (-0.01%) ⬇️
keras-torch 60.09% <ø> (ø)

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
Copy Markdown
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.

Please accept the CLA.

@@ -39,7 +37,18 @@ class RMSNormalization(Layer):

Args:
axis: int. The axis on which to perform the normalization.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please address this comment.

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.

3 participants