[dev] Fix FSDP TP metadata for LinearCrossEntropyModule - #4888
Merged
Conversation
Signed-off-by: conver334 <conver334@gmail.com>
conver334
force-pushed
the
codex/linear-crossentropy-fsdp-tp
branch
from
May 20, 2026 07:56
b3450b7 to
5f8041f
Compare
Victarry
approved these changes
May 20, 2026
|
Hi @conver334 , could you please also submit a fix PR to the main branch? |
|
/ok to test 5f8041f |
5 tasks
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/26213051081 |
HaochenYuan
pushed a commit
to HaochenYuan/Megatron-LM
that referenced
this pull request
Jun 12, 2026
Signed-off-by: conver334 <conver334@gmail.com> Signed-off-by: HaochenYuan <haocheny@nvidia.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do ?
Preserve column tensor-parallel DTensor metadata for
LinearCrossEntropyModulewhen wrapping Megatron modules with FSDP.Reference: https://github.com/NVIDIA-NeMo/Megatron-Bridge/blob/9c5dcea6e8233be4033d10fcc552880ddf32687a/src/megatron/bridge/models/conversion/param_mapping.py#L1200
Issue tracking
Problem
When converting a Qwen2.5-Math-7B / Qwen3.5-35B-A3B checkpoint through the Megatron-Bridge HF -> Megatron-FSDP roundtrip with TP=2,
lm_head.weightwas exported with only the local tensor-parallel shard instead of the full vocabulary dimension.Brief failure output:
Root cause
LinearCrossEntropyModule was not registered in the FSDP adapter's column-parallel module registry. As a result, FSDP did not preserve the column tensor-parallel metadata for output_layer.weight.
Before this fix, the parameter metadata looked like:
Fix
Add LinearCrossEntropyModule to _MODULE_TYPE_REGISTRY["column"] in the FSDP adapter.
After this change, output_layer.weight keeps the expected column TP metadata:
Validation
Megatron-Bridge Megatron-FSDP -> HF roundtrip on Qwen2.5-Math-7B with TP=2, CP=1 is correct.
Contribution process
Pre-checks