Skip to content

feat(megatron): allow custom HF weight loaders and exporters - #2542

Open
gusario wants to merge 2 commits into
THUDM:mainfrom
gusario:feat/custom-hf-weight-mappers
Open

gusario wants to merge 2 commits into
THUDM:mainfrom
gusario:feat/custom-hf-weight-mappers

Conversation

@gusario

@gusario gusario commented Nov 12, 2026

Copy link
Copy Markdown

Custom Megatron model providers still need changes to slime's built-in HF loader/exporter registries before they can load a checkpoint and sync weights to rollout engines. This adds two optional import-path callbacks to keep model-specific tensor mappings outside slime:

  • --custom-hf-weight-loader-path: maps a Megatron parameter/buffer name to its HF tensor. Checkpoint detection honors the callback; loading retains the shared padding, sharding, shape validation and dtype/device copy.
  • --custom-hf-weight-converter-path: maps a Megatron tensor to HF named tensors after shared normalization/unpadding, before shared quantization. An explicit callback also takes precedence over the vision-weight passthrough.

The default path is unchanged. This applies to direct Megatron conversion, not Megatron-Bridge. The customization guide documents both contracts.

Validation:

  • python -m pytest tests/test_hf_to_megatron.py -q: 64 passed on CPU, including new real-safetensors loading, shape-mismatch rejection, invalid callback lookup, vocabulary unpadding, vision callback dispatch and quantization handoff checks. This file already runs in cpu-unittest.
  • Black 24.3.0, isort 5.13.2, Ruff and git diff --check passed for the changed files.

No end-to-end GPU training or quantization-kernel run was performed; quantization handoff is checked with a test double.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant