Skip to content

Add examples and fix docstrings in nnx.nn.dtypes#5283

Open
us wants to merge 1 commit intogoogle:mainfrom
us:worktree-dtypes-docstring
Open

Add examples and fix docstrings in nnx.nn.dtypes#5283
us wants to merge 1 commit intogoogle:mainfrom
us:worktree-dtypes-docstring

Conversation

@us
Copy link
Contributor

@us us commented Feb 26, 2026

What does this PR do?

Improve docstrings for canonicalize_dtype and promote_dtype in flax/nnx/nn/dtypes.py.

Changes:

  • Fix broken sentence in canonicalize_dtype summary (dangling "from the input arguments..." line)
  • Fix typos in promote_dtype: extra " in opening, "convinience" → "convenience", "garantuee" → "guarantee"
  • Fix misleading *args in promote_dtype Args section (function takes a tuple, not variadic args)
  • Fix inaccurate reference to jax.numpy.promote_types (function wraps canonicalize_dtype)
  • Add Example usage sections with doctests for both functions
  • Add Raises sections documenting ValueError for non-inexact dtypes
  • Add .. note:: highlighting the tuple-vs-variadic difference from the Linen version
  • Improve Args/Returns descriptions for accuracy and clarity

Checklist

  • This PR fixes a minor issue (e.g.: typo or small bug) or improves the docs (you can dismiss the other checks if that's the case).
  • This change is discussed in a Github issue/discussion (please add a link).
  • The documentation and docstrings adhere to the documentation guidelines.
  • This change includes necessary high-coverage tests. (No quality testing = no merge!)

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @us, 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 significantly enhances the documentation for the canonicalize_dtype and promote_dtype utility functions within flax.nnx.nn.dtypes. The changes aim to improve clarity, accuracy, and provide practical examples, making these functions easier to understand and use for developers. The updates address misleading information, correct typos, and add comprehensive usage examples and error documentation.

Highlights

  • Docstring Improvements for canonicalize_dtype: Corrected a broken sentence in the summary, added an 'Example usage' section with doctests, clarified argument descriptions, and included a 'Raises' section for ValueError.
  • Docstring Improvements for promote_dtype: Fixed typos, corrected the opening quote, updated the description to accurately reflect its relationship with canonicalize_dtype, added a note about argument handling differences from the Linen version, included an 'Example usage' section with doctests, and updated argument and return descriptions.
  • Argument Clarity: The Args section for promote_dtype was updated to correctly state that it takes a tuple of arguments, rather than variadic *args.

🧠 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
  • flax/nnx/nn/dtypes.py
    • Improved docstrings for canonicalize_dtype and promote_dtype functions.
    • Added example usage sections with doctests for both functions.
    • Corrected typos and misleading information in promote_dtype's description.
    • Clarified argument and return descriptions for both functions.
    • Added Raises sections to document potential ValueError exceptions.
Activity
  • No human activity has occurred on this pull request yet.
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 significantly improves the docstrings for canonicalize_dtype and promote_dtype in flax/nnx/nn/dtypes.py. The changes fix broken sentences, correct typos, clarify argument descriptions, and add comprehensive examples with doctests, which greatly enhances the clarity and usability of the documentation. The changes are well-executed. I have one minor suggestion to improve consistency within the new examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant