Skip to content

[Feature] Support dense MTP construction and preserve frozen weights through export - #2379

Closed
jayhenry wants to merge 1 commit into
InternLM:mainfrom
jayhenry:feat/dense-mtp-frozen-export
Closed

jayhenry wants to merge 1 commit into
InternLM:mainfrom
jayhenry:feat/dense-mtp-frozen-export

Conversation

@jayhenry

@jayhenry jayhenry commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Build Dense MTP when the model is configured with MTPConfig(num_layers=1, frozen=True). For a composed Qwen3.5 model, set it on the text config. Frozen MTP parameters participate in HF loading, FSDP sharding, rollout weight publication, and HF export. The Dense training step uses the backbone loss.

Qwen3.5 uses one shared set of projection and norm keys in its HF MTP layout. A CPU reproduction of the source patch loaded two independent projection values as [2, 2] after saving [1, 2]. The build now rejects more than one independent physical MTP layer. A single physical layer can still be shared across multiple logical depths.

Thanks to @matrix72c and the contributors credited in #2285. This PR backports its Dense construction and frozen checkpoint support from cccbab1677ee815f39641d25862ddac7fc0a926b. The wider work in #2285 covers trainable MTP and model onboarding, and #2369 covers Qwen3.8-27B onboarding and chat templates. This PR exposes an explicit opt-in on the existing Dense configs.

Changed files

Path Change
xtuner/v1/model/base.py Make mtp_config available to Dense through TransformerConfig.
xtuner/v1/model/dense/dense.py Construct and freeze MTP before load specs are initialized, and shard it as its own FSDP unit.
xtuner/v1/model/dense/qwen3_5_text.py Map the Qwen3.5 HF keys and reject ambiguous physical-layer layouts.
xtuner/v1/model/moe/moe.py Keep the existing MTPConfig import available while inheriting the shared field.
tests/model/test_frozen_dense_mtp.py Cover construction, the backbone loss, HF key uniqueness, checkpoint round-trip, and rollout weight publication.

Verification

Ran with CUDA_VISIBLE_DEVICES='' in pt29_glm2 using Python 3.12.13, PyTorch 2.9.1, and Transformers 5.17.0.

  • test_frozen_dense_mtp.py and test_mtp_local_future_embeddings.py passed 69 tests and skipped 46 CUDA cases. This includes CPU shape and key checks against the 15 MTP tensors in the Qwen3.5-9B checkpoint. The skipped cases cover the CUDA HF round-trip, CUDA FSDP optimizer step and publication, CUDA future embeddings, and two-device NCCL sequence parallelism.
  • The combined Dense/MTP/MoE run passed 89 tests, skipped 59 CUDA cases, and deselected six cases that attempted CUDA initialization in the CPU environment. The same six failures reproduced on upstream/main at d0aead542cbf0c35c47092b40c40a4663e60224d in GLM5.2 explicit DSA, GLM5.3 init/precision, and Qwen3 VL value-head tests. The additional skips cover the GLM MTP, checkpoint and sequence-parallel cases, and the MoE grad sync and ExpertTP cases.
  • A separate two-process CPU/Gloo check ran FSDP construction, optimizer parameter selection, strict HF load, rollout weight iteration, HF save, and strict reload. All 15 frozen MTP tensor values matched exactly on both ranks, and Transformers read the exported mtp_num_hidden_layers=1. The check supplied no-ops for PyTorch accelerator profiling and synchronization calls on CPU.
  • ruff check, ruff format --check, and git diff --check passed. The applicable pre-commit style hooks and mypy passed. The repository-wide pydantic-extra-check reached a CUDA-only RMSNorm import and failed the same way on the upstream baseline.
  • The source commit f2bb6979afbb2f26f543ebd32d9a544f5ce50260 reports 23 passing historical tests including CUDA HF I/O and an FSDP optimizer update. The verification above was CPU-only.

…port

Backport the checkpoint-oriented changes from InternLM#2285.
Build frozen Dense MTP from the shared MTP config and shard it separately
so the existing load, rollout publication, and HF export paths can
retain the tensors. Dense training continues to use the backbone loss.

Reject multiple independent Qwen3.5 MTP layers because HF uses shared
projection and norm keys. Keep the legacy MoE MTPConfig import working.

Source commit f2bb6979afbb2f26f543ebd32d9a544f5ce50260
@jayhenry

jayhenry commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator Author

The Dense MTP patch is now Layer 10 of the same-repository Mini-Agent stack. Closing this fork PR in favor of #2390.

@jayhenry jayhenry closed this Dec 4, 2026
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