refactor(tree_attn): decouple FSDP and Megatron implementations#844
Conversation
Summary of ChangesHello @rchardx, 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 refactors the Highlights
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request effectively refactors the tree_attn module to decouple the FSDP and Megatron implementations. The changes improve modularity by splitting the code into separate files for constants, FSDP-specific logic, and Megatron-specific logic, while maintaining backward compatibility. My review includes a suggestion to improve the robustness of the monkey-patching mechanism in the FSDP module to prevent potential state management issues.
There was a problem hiding this comment.
Pull request overview
This PR refactors the tree attention module to decouple FSDP and Megatron implementations, allowing the FSDP engine to use tree attention functionality without requiring Megatron dependencies. The refactoring splits the monolithic module.py into separate focused files while maintaining backward compatibility.
Changes:
- Split module.py into constants.py (shared), module_fsdp.py (FSDP-only), and module_megatron.py (Megatron-specific)
- Updated module.py to provide backward-compatible re-exports with conditional Megatron imports
- Updated tree.py to import directly from module_fsdp, eliminating unnecessary Megatron dependencies
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| areal/models/tree_attn/constants.py | New file defining shared BLOCK_SIZE constant with no external dependencies |
| areal/models/tree_attn/module_fsdp.py | New file with FSDP-specific functionality using PyTorch-only dependencies |
| areal/models/tree_attn/module_megatron.py | New file with Megatron-specific PytorchFlexAttention and bridge patching |
| areal/models/tree_attn/module.py | Refactored to provide backward-compatible re-exports with conditional Megatron imports |
| areal/models/tree_attn/tree.py | Updated imports to use module_fsdp directly, avoiding Megatron dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Split module.py into separate files to allow FSDP engine to import tree attention functionality without requiring Megatron dependencies: - constants.py: shared BLOCK_SIZE constant (lightweight, no deps) - module_fsdp.py: FSDP-only functionality (PyTorch only) - module_megatron.py: Megatron-specific functionality (mbridge, megatron.core) - module.py: backward-compatible re-exports with conditional Megatron imports
…l-project#844) Split module.py into separate files to allow FSDP engine to import tree attention functionality without requiring Megatron dependencies: - constants.py: shared BLOCK_SIZE constant (lightweight, no deps) - module_fsdp.py: FSDP-only functionality (PyTorch only) - module_megatron.py: Megatron-specific functionality (mbridge, megatron.core) - module.py: backward-compatible re-exports with conditional Megatron imports
…l-project#844) Split module.py into separate files to allow FSDP engine to import tree attention functionality without requiring Megatron dependencies: - constants.py: shared BLOCK_SIZE constant (lightweight, no deps) - module_fsdp.py: FSDP-only functionality (PyTorch only) - module_megatron.py: Megatron-specific functionality (mbridge, megatron.core) - module.py: backward-compatible re-exports with conditional Megatron imports
Description
Split module.py into separate files to allow FSDP engine to import tree attention functionality without requiring Megatron dependencies:
Type of Change
work as expected)
Checklist
jb build docs/gemini review)