Skip to content

Sanbao/gpt#1137

Open
susanbao wants to merge 3 commits intomainfrom
sanbao/gpt
Open

Sanbao/gpt#1137
susanbao wants to merge 3 commits intomainfrom
sanbao/gpt

Conversation

@susanbao
Copy link
Collaborator

Resolves #<issue_number_goes_here>

It's a good idea to open an issue first for discussion.

Reference

Colab Notebook

Checklist

  • I have added all the necessary unit tests for my change.
  • I have verified that my change does not break existing code and all unit tests pass.
  • I have added all appropriate doc-strings/documentation.
  • My PR is based on the latest changes of the main branch (if unsure, rebase the code).
  • I have signed the Contributor License Agreement.
  • I have followed Contribution Guidelines.

@gemini-code-assist
Copy link

Summary of Changes

Hello @susanbao, 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 enhances the model generation and sharding utilities. It introduces support for complex model architectures that utilize interleaved layers, ensuring that parameters are correctly processed during tree intersection. Additionally, it improves compatibility with JAX's sharding mechanisms by explicitly recognizing GSPMDSharding, which is crucial for distributed training setups.

Highlights

  • Inhomogeneous Scan Support: Implemented logic within the intersect_trees function to support inhomogeneous scanning, specifically for models with interleaved layers (e.g., GPT-OSS 120B). This allows for correct parameter slicing when layers follow a cyclical pattern.
  • JAX Sharding Compatibility: Extended the reshard_pytree utility to recognize and correctly handle GSPMDSharding objects from JAX, ensuring broader compatibility with different sharding configurations.

🧠 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
  • tunix/generate/utils.py
    • Added logic to intersect_trees to detect and handle inhomogeneous scanning patterns, such as those found in models with interleaved layers (e.g., 'layers_0', 'layers_1').
    • Introduced a scan_idx variable to correctly index parameters based on the detected layer cycle.
    • Updated the call to _slice_scanned_param to use the new scan_idx.
  • tunix/rl/reshard.py
    • Imported GSPMDSharding from jax._src.sharding_impls.
    • Modified the _get_dst_sharding helper function to include GSPMDSharding in its type check, allowing it to correctly identify this sharding type.
Activity
  • No human activity has been recorded 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

@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 adds support for loading models with inhomogeneous scanned layers and updates the JAX resharding utility. The new layer mapping logic in tunix/generate/utils.py seems correct for its purpose.

However, I've found a high-severity maintainability issue in tunix/rl/reshard.py. The code now imports GSPMDSharding from a private jax._src module, which is an unstable API that could break in future JAX updates. I've provided a suggestion to use the public jax.sharding.Sharding base class instead, which is a more robust and future-proof solution.

Comment on lines 452 to 454
if isinstance(
x, jax.sharding.NamedSharding | jax.sharding.SingleDeviceSharding
x, jax.sharding.NamedSharding | jax.sharding.SingleDeviceSharding | GSPMDSharding
):

Choose a reason for hiding this comment

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

high

Using GSPMDSharding requires importing from a private JAX _src module (line 31), which is risky as these internal APIs can change without warning. This violates the maintainability principle from the style guide (line 12).

A more robust and future-proof approach is to check against the public abstract base class jax.sharding.Sharding. This will cover all sharding types (NamedSharding, SingleDeviceSharding, GSPMDSharding, etc.) and allows you to remove the import from jax._src.sharding_impls.

    if isinstance(x, jax.sharding.Sharding):
References
  1. The style guide states that code should be maintainable and easy to modify and extend. Relying on private, unstable APIs from dependencies makes the code harder to maintain as it can break with dependency updates. (link)

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.

2 participants