feat(archon): use meta device + DCP for memory-efficient model init#860
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 introduces a significant performance improvement to the Archon engine by refactoring its model initialization process. By leveraging PyTorch's meta device functionality and a distributed checkpoint loading pattern, the system can now construct and load large language models with drastically reduced peak memory usage, making it more scalable and efficient for distributed training environments. 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 introduces a significant performance improvement by adopting the meta device initialization pattern for the Archon engine. This is a great change that will substantially reduce peak memory usage during model loading. The refactoring to separate model structure creation, materialization, and weight/buffer initialization is well-executed.
My review includes a couple of suggestions for improving code clarity and diagnostics:
- Updating a docstring in the base model class to reflect the new separation of concerns between
init_weightsandinit_buffers. - A note on a minor regression in diagnostic logging for missing weights during model loading.
There was a problem hiding this comment.
Pull request overview
This PR optimizes Archon engine initialization to use meta device + FSDP + DCP loading, significantly reducing peak memory usage from N × model_size to ~1/N × model_size per rank during distributed model loading.
Changes:
- Refactored model initialization to create model structure on meta device first, then materialize after FSDP parallelization
- Split buffer initialization from weight initialization by adding
init_buffers()method to BaseArchonModel - Replaced direct weight loading with DCP-based distributed loading where each rank reads only its shard
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| areal/experimental/engine/archon_engine.py | Refactored _create_device_model() to create meta device model structure; added _materialize_and_load_weights() to handle materialization and DCP loading after FSDP; removed unused import |
| areal/experimental/models/archon/base.py | Added abstract init_buffers() method to BaseArchonModel for buffer-only initialization |
| areal/experimental/models/archon/qwen2/model/model.py | Moved rope_cache initialization from init_weights() to new init_buffers() method |
| areal/experimental/models/archon/qwen3/model/model.py | Moved rope_cache initialization from init_weights() to new init_buffers() method |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8e88c77 to
1e151a4
Compare
1e151a4 to
b5590f2
Compare
b5590f2 to
b7dfeda
Compare
be7f45b to
31d52e5
Compare
Optimize Archon engine initialization to use meta device + FSDP + DCP loading pattern, reducing peak memory from N × model_size to ~1/N × model_size per rank. Changes: - Create model structure on meta device (no memory allocation) - Apply FSDP/TP/EP parallelization to meta device model - Materialize tensors with to_empty() after FSDP - Load weights via DCP (each rank reads only its shard) - Add init_buffers() to BaseArchonModel for buffer-only initialization - Separate init_weights() (parameters) from init_buffers() (rope_cache)
31d52e5 to
cf52eab
Compare
…real-project#860) Optimize Archon engine initialization to use meta device + FSDP + DCP loading pattern, reducing peak memory from N × model_size to ~1/N × model_size per rank. Changes: - Create model structure on meta device (no memory allocation) - Apply FSDP/TP/EP parallelization to meta device model - Materialize tensors with to_empty() after FSDP - Load weights via DCP (each rank reads only its shard) - Add init_buffers() to BaseArchonModel for buffer-only initialization - Separate init_weights() (parameters) from init_buffers() (rope_cache)
…real-project#860) Optimize Archon engine initialization to use meta device + FSDP + DCP loading pattern, reducing peak memory from N × model_size to ~1/N × model_size per rank. Changes: - Create model structure on meta device (no memory allocation) - Apply FSDP/TP/EP parallelization to meta device model - Materialize tensors with to_empty() after FSDP - Load weights via DCP (each rank reads only its shard) - Add init_buffers() to BaseArchonModel for buffer-only initialization - Separate init_weights() (parameters) from init_buffers() (rope_cache)
Description
Optimize Archon engine initialization to use meta device + FSDP + DCP loading pattern, reducing peak memory from N × model_size to ~1/N × model_size per rank.
Changes:
Related Issue
Fixes #857
Type of Change
work as expected)
Checklist
jb build docs/gemini review)