feat(nnx): add out_sharding to recurrent cells
What does this PR do?
adds out_sharding parameter to the __call__ methods of recurrent cell classes in flax/nnx/nn/recurrent.py: LSTMCell, OptimizedLSTMCell, SimpleCell, and GRUCell.
split from #5179 for easier review.
changes:
- adds
*, out_sharding=Noneto__call__of all 4 cell types - forwards
out_shardingto all internalLinear.__call__()invocations - adds
__call__docstrings without_shardingdocumented forSimpleCell
tests:
- adds
test_out_sharding_signatureforSimpleCellinrecurrent_test.py
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).
- [x] The documentation and docstrings adhere to the documentation guidelines.
- [x] This change includes necessary high-coverage tests. (No quality testing = no merge!)
Summary of Changes
Hello @aarushisingh04, I'm Gemini Code Assist[^1]! 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 introduces an out_sharding parameter to the __call__ methods of various recurrent neural network cells within the Flax NNX library. This enhancement allows users to specify sharding configurations for the outputs of internal linear layers, providing greater flexibility for distributed training and memory management in large-scale models. The changes ensure that sharding preferences are respected throughout the recurrent cell computations.
Highlights
- API Enhancement: The
__call__methods ofLSTMCell,OptimizedLSTMCell,SimpleCell, andGRUCellnow accept anout_shardingparameter. - Sharding Propagation: The
out_shardingparameter is propagated to internalLinearlayer invocations within these recurrent cells, enabling finer-grained control over output sharding. - Documentation Update: Docstrings for the
__call__methods of the affected recurrent cells, specificallySimpleCell, have been updated to include the newout_shardingparameter. - Test Coverage: A new test,
test_out_sharding_signature, has been added forSimpleCellto ensure theout_shardingparameter is correctly handled.
🧠 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/recurrent.py
- Added
out_shardingparameter to the__call__method signatures ofLSTMCell,OptimizedLSTMCell,SimpleCell, andGRUCell. - Modified the internal calls to
Linearlayers within these cells to pass the newout_shardingargument. - Updated the docstrings for the
__call__methods to document theout_shardingparameter.
- Added
- tests/nnx/nn/recurrent_test.py
- Added
TestSimpleCellclass withtest_out_sharding_signatureto verify theSimpleCell's__call__method correctly accepts theout_shardingparameter.
- Added
Activity
- This pull request was split from a larger PR (#5179) to facilitate an easier review process.
- The author, aarushisingh04, has ensured that documentation and docstrings adhere to guidelines and that necessary high-coverage tests are included.
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 :thumbsup: and :thumbsdown: 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.
[^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.
/gemini review