Skip to content

improve scaling up guide#5354

Open
cgarciae wants to merge 2 commits intonnx-basics-treefrom
improve-scaling-up-guide
Open

improve scaling up guide#5354
cgarciae wants to merge 2 commits intonnx-basics-treefrom
improve-scaling-up-guide

Conversation

@cgarciae
Copy link
Copy Markdown
Collaborator

No description provided.

@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@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 improving the clarity and user experience within Flax NNX, particularly by refining error messages related to tree-mode and graph-mode interactions. It also updates and expands the documentation to ensure it accurately reflects the latest API usage and provides comprehensive guidance for new and existing users, especially concerning state management and transformations.

Highlights

  • Improved Error Messages and Guidance: Enhanced error messages for aliasing and cyclic references in NNX's tree-mode, providing clearer explanations and actionable suggestions for resolution, including options for graph mode or nnx.compat.
  • Documentation Updates: Updated the 'Scaling Up' (GSPMD) guide to reflect recent API changes, such as the transition from Module.sow and Module.perturb to nnx.capture, and the use of nnx.eval_shape instead of nnx.get_abstract_model. A new foundational guide, 'NNX Basics', was also added to introduce core concepts like Pytrees, Variables, Rngs, and NNX Transforms.
  • API Refinements: The flax.nnx.graph module was simplified to directly re-export APIs from flax.nnx.graphlib, streamlining the internal structure. The nnx.Optimizer was generalized to accept any type, removing its previous binding to nnx.Module.
  • Internal Consistency Checks: Introduced check_no_aliases calls across various NNX transforms (grad, jit, vmap, scan, etc.) to enforce stricter aliasing rules in tree-mode and provide more context-specific error messages.

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

@cgarciae cgarciae force-pushed the improve-scaling-up-guide branch from f752185 to 7033647 Compare March 18, 2026 19:32
@cgarciae cgarciae changed the base branch from transforms_tree_guide to nnx-basics-tree March 18, 2026 19:32
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 improves the scaling up guide by adding Samuel Anklesaria as a co-author, updating code examples to reflect recent API changes in NNX, and fixing some errors in the flax_gspmd.ipynb notebook. The review focuses on identifying and addressing issues of medium or higher severity.

I am having trouble creating individual review comments. Click here to see my feedback.

docs_nnx/guides/flax_gspmd.ipynb (408)

critical

The return statement is missing the optimizer variable. This will cause the training loop to not update the optimizer state, leading to incorrect training. The optimizer should be returned to ensure its state is updated in the training loop.

    "  return model, optimizer, loss\n

docs_nnx/guides/flax_gspmd.ipynb (475)

critical

The training loop is not updating the optimizer. This will cause the model to train incorrectly. The optimizer should be included in the return statement.

    "    model, optimizer, loss = train_step(model, optimizer, input, label)\n

docs_nnx/guides/flax_gspmd.ipynb (50)

high

This line appears to be incomplete or a remnant of editing. It should be removed or completed to provide meaningful content.

docs_nnx/guides/flax_gspmd.ipynb (386-450)

high

The traceback indicates a ShardingTypeError due to sharded contracting dimensions in jnp.dot. This suggests an ambiguity in how the output should be sharded. To resolve this, explicitly specify the out_sharding parameter in the jnp.dot call within the DotReluDot.__call__ method.

docs_nnx/guides/flax_gspmd.ipynb (529-531)

high

The variable model is not defined in this scope, leading to a NameError. This is likely due to the code being executed in a different context than where model was defined. Ensure that model is accessible within this code block, or that the relevant code is moved to where model is defined.

docs_nnx/flip/5310-tree-mode-nnx.md (70)

medium

This line introduces a new function call. It's important to ensure that check_no_aliases is well-documented and that its purpose is clear to anyone reading the code. Also, consider adding a brief description of what kind of aliases are being checked and why they are problematic in this context.

docs_nnx/guides/flax_gspmd.ipynb (145)

medium

Consider using kernel_metadata instead of kernel_init for specifying the output sharding. This approach is more consistent with the style used for w2 and avoids the need for nnx.with_partitioning.

      kernel_metadata={'out_sharding': (None, 'model')},

@cgarciae cgarciae force-pushed the improve-scaling-up-guide branch from 7033647 to 4444c93 Compare March 19, 2026 14:12
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