fix(megatron-fsdp): preserve non-meta tensors during meta device materialization - #4154
fix(megatron-fsdp): preserve non-meta tensors during meta device materialization#4154xuwchen wants to merge 4 commits into
Conversation
|
This PR has been automatically converted to draft because all PRs must start as drafts. When you are ready for review, click Ready for Review to begin the review process. This will:
See the contribution guide for more details. |
During meta device initialization, the materialization path calls This becomes a problem for MoE when The fix here replaces |
|
/ok to test f13f04b |
|
/ok to test 626235a |
What does this PR do ?
During meta device initialization, the materialization path calls
m.to_empty(device, recurse=False)beforereset_parameters().to_empty()unconditionally replaces all tensors (both parameters and buffers) in the module with uninitialized memory, regardless of whether they are actually on the meta device.This becomes a problem for MoE when
--moe-router-enable-expert-biasis enabled:expert_biasis registered with an explicitdevice=torch.cuda.current_device()[link], so it bypasses the meta context and is correctly initialized to zeros on GPU. Butto_empty()clobbers it with uninitialized memory (NaN), andreset_parameters()only reinitializes parameters, not buffers, soexpert_biasstays NaN for the entire training run.The fix here replaces
m.to_empty()with a targeted helper that only materializesis_meta=Truetensors, leaving non-meta buffers (likeexpert_bias) untouched.Contribution process
Pre-checks
Code review
Feel free to message or comment the @mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!
All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.
Step 1: Mark PR as "Ready for Review"
.github/CODEOWNERS.Final Review might get declined if these requirements are not fulfilled.
Step 2: Final Review
For PRs that change
megatron/core, once all expert reviewers have approved, theFinal Reviewlabel is applied automatically and final reviewers are assigned.For PRs outside
megatron/core, this step is skipped.Step 3: Approved
Once all required reviewers have approved, the
Approvedlabel is applied automatically.Merge
Any member of mcore-engineers will be able to merge your PR.
For MRs into `dev` branch
The proposed review process for `dev` branch is under active discussion.MRs are mergable after one approval by either
eharper@nvidia.comorzijiey@nvidia.com.