mirror of
https://github.com/NVIDIA/Model-Optimizer.git
synced 2026-12-06 04:57:17 +08:00
Deprecate export_mcore_gpt_to_hf in favor of Megatron-Bridge
export_mcore_gpt_to_hf now emits a DeprecationWarning; removal is planned for 0.51.0. Megatron-Bridge's AutoBridge.save_hf_pretrained_modelopt replaces it, except for GGML / IQ formats and EAGLE / Medusa modules, which it doesn't export yet. examples/megatron_bridge/export_quantized_megatron_to_hf.py picks the exporter itself, so it doesn't pass the warning on to its users. Part of OMNIML-5979. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
7b3e7db8eb
commit
9241b1f67b
@@ -50,6 +50,8 @@ Changelog
|
||||
|
||||
**Deprecations**
|
||||
|
||||
- ``modelopt.torch.export.export_mcore_gpt_to_hf`` is deprecated and will be removed in 0.51.0; it now emits a ``DeprecationWarning``. Export quantized Megatron-Core models to Hugging Face checkpoints with Megatron-Bridge (``AutoBridge.save_hf_pretrained_modelopt``) instead. Megatron-Bridge doesn't export GGML / IQ formats or EAGLE / Medusa modules (``export_extra_modules=True``) yet.
|
||||
|
||||
**Bug Fixes**
|
||||
|
||||
*Quantization*
|
||||
|
||||
@@ -51,6 +51,7 @@ See `README.md` in this directory for more details.
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
|
||||
import torch
|
||||
@@ -227,14 +228,19 @@ def export_unified_hf(unwrapped_model, args: argparse.Namespace, trust_remote_co
|
||||
f"Exporting to HuggingFace (unified) checkpoint at {args.export_unified_hf_path}..."
|
||||
)
|
||||
# TODO: Gemma3-VL is not in export_mcore_gpt_to_hf's per-arch mappings yet.
|
||||
export_mcore_gpt_to_hf(
|
||||
unwrapped_model,
|
||||
args.local_checkpoint_path,
|
||||
export_extra_modules=export_extra_modules,
|
||||
dtype=torch.bfloat16,
|
||||
export_dir=args.export_unified_hf_path,
|
||||
trust_remote_code=trust_remote_code,
|
||||
)
|
||||
# This script picks the exporter, so its users get no deprecation warning they can't act on.
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings(
|
||||
"ignore", "export_mcore_gpt_to_hf is deprecated", DeprecationWarning
|
||||
)
|
||||
export_mcore_gpt_to_hf(
|
||||
unwrapped_model,
|
||||
args.local_checkpoint_path,
|
||||
export_extra_modules=export_extra_modules,
|
||||
dtype=torch.bfloat16,
|
||||
export_dir=args.export_unified_hf_path,
|
||||
trust_remote_code=trust_remote_code,
|
||||
)
|
||||
|
||||
|
||||
def main(args: argparse.Namespace):
|
||||
|
||||
@@ -2438,7 +2438,20 @@ def export_mcore_gpt_to_hf(
|
||||
dtype: The weights data type to export the unquantized layers.
|
||||
export_dir: The target export path.
|
||||
clamp_kv_cache_scales: Whether to clamp FP8 KV cache scaling factors to at least 1.0.
|
||||
|
||||
.. deprecated:: 0.50.0
|
||||
Use Megatron-Bridge's ``AutoBridge.save_hf_pretrained_modelopt`` instead. It doesn't
|
||||
export GGML / IQ formats or EAGLE / Medusa modules yet.
|
||||
"""
|
||||
warnings.warn(
|
||||
"export_mcore_gpt_to_hf is deprecated as of 0.50.0 and will be removed in 0.51.0. Export "
|
||||
"quantized Megatron-Core models with Megatron-Bridge instead, e.g. "
|
||||
"AutoBridge.from_hf_pretrained(path).save_hf_pretrained_modelopt(model, export_dir, "
|
||||
"source_path=path). Megatron-Bridge doesn't export GGML / IQ formats or EAGLE / Medusa "
|
||||
"modules (export_extra_modules=True) yet; those still need this function.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
exporter = GPTModelExporter(
|
||||
model,
|
||||
pretrained_model_name_or_path,
|
||||
|
||||
@@ -321,12 +321,13 @@ def test_export_mcore_gpt_to_hf_passes_kv_cache_clamping_option(
|
||||
|
||||
monkeypatch.setattr(unified_export_megatron, "GPTModelExporter", FakeExporter)
|
||||
|
||||
unified_export_megatron.export_mcore_gpt_to_hf(
|
||||
object(),
|
||||
tmp_path,
|
||||
export_dir=tmp_path,
|
||||
clamp_kv_cache_scales=clamp_kv_cache_scales,
|
||||
)
|
||||
with pytest.warns(DeprecationWarning, match="export_mcore_gpt_to_hf is deprecated"):
|
||||
unified_export_megatron.export_mcore_gpt_to_hf(
|
||||
object(),
|
||||
tmp_path,
|
||||
export_dir=tmp_path,
|
||||
clamp_kv_cache_scales=clamp_kv_cache_scales,
|
||||
)
|
||||
|
||||
assert exporter_args["clamp_kv_cache_scales"] is clamp_kv_cache_scales
|
||||
|
||||
|
||||
Reference in New Issue
Block a user