[Fix] Support origin HF weight backfilling in parallel converter - #2270
Open
albaNnaksqr wants to merge 3 commits into
Open
[Fix] Support origin HF weight backfilling in parallel converter#2270albaNnaksqr wants to merge 3 commits into
albaNnaksqr wants to merge 3 commits into
Conversation
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.
Motivation
convert_torch_dist_to_hf.pysupports--add-missing-from-origin-hf, which restores tensors that are present in the original Hugging Face checkpoint but absent from the Megatrontorch_distcheckpoint.This is useful when the Megatron checkpoint intentionally contains only part of the model. For example, the checkpoint may contain the trained language model weights but omit frozen visual encoder or MTP weights.
However,
convert_torch_dist_to_hf_parallel.pydid not support this option. Switching from the regular converter to the parallel converter could therefore produce an incomplete Hugging Face checkpoint.This is related to:
Changes
This PR adds
--add-missing-from-origin-hfsupport toconvert_torch_dist_to_hf_parallel.py.When enabled, the parallel converter:
--origin-hf-dir;weight_map, shard numbering, andtotal_size;--origin-hf-dir;The option remains opt-in, matching the behavior of the regular converter.
Conversion error handling
Previously, an exception raised while converting an individual Megatron parameter was printed and replaced with an empty result:
With origin-HF backfilling enabled, this could hide a real conversion failure. The missing output tensors could be copied from the original checkpoint, producing an apparently complete checkpoint containing stale pretrained weights.
This PR now collects conversion errors from all parallel workers and raises a combined error before:
Therefore, origin-HF backfilling cannot mask a parameter conversion exception.
Validation
A zero-training Qwen3.5-27B round trip was tested:
using the parallel converter with
--add-missing-from-origin-hf.Checkpoint validation:
torch_dist: 851;The 348 restored tensors consisted of:
model.visual.*tensors;mtp.*tensors.The resulting checkpoint was served with SGLang v0.5.16 and tested using short, medium, and long tool-calling prompts: