fix: add fallback for --save-hf when Megatron-Bridge lacks model support#1881
Open
WangHong-yang wants to merge 1 commit intoTHUDM:mainfrom
Open
fix: add fallback for --save-hf when Megatron-Bridge lacks model support#1881WangHong-yang wants to merge 1 commit intoTHUDM:mainfrom
WangHong-yang wants to merge 1 commit intoTHUDM:mainfrom
Conversation
When Megatron-Bridge doesn't support a model architecture, save_hf_model now falls back to reading the just-saved torch_dist checkpoint and converting to HF format via the existing conversion logic. Extract shared checkpoint loading/saving utilities from tools/convert_torch_dist_to_hf.py into slime/utils/torch_dist_to_hf.py so both the CLI tool and the runtime fallback can reuse them.
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.
Summary
AutoBridge.from_hf_pretrainedraises (unsupported architecture),save_hf_modelnowfalls back to reading the just-saved torch_dist checkpoint from disk and converting to HF
safetensors via slime's own
megatron_to_hfhandlers.tools/convert_torch_dist_to_hf.pyinto
slime/utils/torch_dist_to_hf.pyso both the CLI tool and the runtime fallback reusethe same code.
Motivation
Models not yet in the pinned Bridge version (e.g. Qwen3.5) or not supported
by Megatron-Bridge (e.g. GLM-5, GLM-5.1) silently fail on
--save-hf.This change makes the export work for any model that slime already has a
megatron_to_hfhandler for, without requiring a Bridge update.How it works
save_hf_modeltries the existing Megatron-Bridge path._save_hf_directruns on rank 0 only:iter_{rollout_id}torch_dist checkpoint from disk (just saved moments before).slime/utils/torch_dist_to_hf.py.--hf-checkpoint.Test plan
from the same torch_dist checkpoint: 46/46 files identical