Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modelopt/torch/export/plugins/megatron_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(
workspace_dir: str | None = None,
dtype=torch.bfloat16,
dequantize: bool = True,
trust_remote_code: bool = False,
trust_remote_code: bool = True,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we set default to True?

Copy link
Contributor

@meenchen meenchen Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the same question here. Is this an intended change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was True in the past. I set it to False in #769 but found that Nemotron needs this to be True. So I decide to pass through and continue using the previous default value.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why dont we pass explicitly whenever we need to set to True? I'm afraid Security team might have concerns if we set default to True

verbose: bool = False,
moe_router_dtype: torch.dtype | None = None,
):
Expand Down
9 changes: 8 additions & 1 deletion modelopt/torch/export/unified_export_megatron.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def __init__(
pretrained_model_name_or_path: str | os.PathLike | None = None,
export_extra_modules: bool = False,
dtype=torch.bfloat16,
trust_remote_code: bool = True,
trust_remote_code: bool = False,
moe_router_dtype: torch.dtype | None = None,
):
"""Create a GPTModel exporter instance."""
Expand Down Expand Up @@ -1205,6 +1205,7 @@ def export_mcore_gpt_to_hf(
export_extra_modules: bool = False,
dtype: torch.dtype = torch.bfloat16,
export_dir: Path | str = tempfile.gettempdir(),
trust_remote_code: bool = False,
moe_router_dtype: torch.dtype | None = None,
):
"""Export Megatron Core GPTModel to unified checkpoint and save to export_dir.
Expand All @@ -1225,6 +1226,7 @@ def export_mcore_gpt_to_hf(
pretrained_model_name_or_path,
export_extra_modules=export_extra_modules,
dtype=dtype,
trust_remote_code=trust_remote_code,
moe_router_dtype=moe_router_dtype,
)
exporter.save_pretrained(export_dir, pretrained_model_name_or_path)
Expand All @@ -1235,6 +1237,7 @@ def import_mcore_gpt_from_hf(
pretrained_model_path: str,
workspace_dir: str | None = None,
dtype: torch.dtype = torch.bfloat16,
trust_remote_code: bool = False,
moe_router_dtype: torch.dtype | None = None,
):
"""Import GPTModel state_dict from supported HuggingFace pretrained model path.
Expand All @@ -1243,13 +1246,17 @@ def import_mcore_gpt_from_hf(
model: The Megatron Core GPTModel instance.
pretrained_model_path: A path to a *directory* containing model weights saved using
[`~PreTrainedModel.save_pretrained`], e.g., `./my_model_directory/`.
workspace_dir: The directory to save the workspace.
dtype: The weights data type to import.
trust_remote_code: If True, this allows importing from a wider range of sources.
moe_router_dtype: The data type to import the moe router weights.
"""
importer = GPTModelImporter(
model,
pretrained_model_path,
workspace_dir=workspace_dir,
dtype=dtype,
trust_remote_code=trust_remote_code,
moe_router_dtype=moe_router_dtype,
)
importer._import_state_dict()