Repository navigation
[qwen3.5] Tie embeddings for the 0.8B, 2B, and 4B flavors - #4916
Merged
Merged
Conversation
The Hugging Face Qwen3.5-0.8B, 2B, and 4B checkpoints set tie_word_embeddings=true and store no lm_head.weight. Their torchtitan configs kept a separate lm_head, so loading those checkpoints failed with "Missing key in checkpoint state_dict: lm_head.weight". Enable weight tying for these flavors, as the Qwen3 small flavors do; the Qwen3.5 state dict adapter already restores lm_head from embed_tokens on load and drops it on save. The 9B and larger checkpoints do not tie embeddings and are unchanged.
test_hf_adapter_restores_local_shards builds a partial state dict that carries lm_head.weight but not tok_embeddings.weight. With Qwen3.5-0.8B now tying embeddings, to_hf drops lm_head and from_hf finds neither key. The test checks TP shard restoration, not tying, so untie its config.
tianyu-l
approved these changes
Sep 28, 2026
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
The Hugging Face Qwen3.5-0.8B, 2B, and 4B checkpoints set
tie_word_embeddings=trueand store nolm_head.weight. The torchtitan configs for these flavors kept a separatelm_head, so loading one of these checkpoints failed:This PR enables
enable_weight_tying=Truefor the 0.8B, 2B, and 4B flavors, as the Qwen3 small flavors already do, and replaces the stale "torchtitan doesn't support tied embeddings yet" notes. No other code changes are needed:Decoderalready tiestok_embeddingstolm_head, and the Qwen3.5 state dict adapter already restoreslm_headfromembed_tokenson load and drops it on save.The 9B and larger HF checkpoints do not tie embeddings and are unchanged.
Why
The HF tied flavors could not be loaded through the HF checkpoint path (
initial_load_in_hf,convert_from_hf.py). For example, the RL GDN full-cudagraph test (test_gdn_full_runner_matches_eager) builds a vLLM engine from a Qwen3.5-0.8B checkpoint. CI does not provide one and skips the test; pointed at the official checkpoint, it failed for this reason.Affected configs
qwen3_5model registry flavors0.8B,2B,4B, and the recipes intorchtitan/models/qwen3_5/config_registry.pythat use them.debugmodel,9B, and27Band are unaffected.Test plan
Qwen3.5-0.8B, official HF checkpoint (
Qwen/Qwen3.5-0.8B):scripts/checkpoint_conversion/convert_from_hf.py --model_name qwen3_5 --model_flavor 0.8B:Missing key in checkpoint state_dict: lm_head.weight;tok_embeddings.weightandlm_head.weightare both bitwise equal to HFmodel.language_model.embed_tokens.weight;to_hfround trip reproduces the HF key set exactly (no extralm_head.weight), with all 473 tensors bitwise equal. The 15 HFmtp.*(multi-token prediction) weights are not part of the torchtitan model, before or after this change.tests/unit_tests/rl/test_vllm_wrapper.py::test_hf_adapter_restores_local_shardsbuilds a partial Qwen3.5-0.8B state dict withlm_head.weightbut notok_embeddings.weight; with tying,to_hfdropslm_headandfrom_hffound neither key. The test checks TP shard restoration, not tying, so it now unties its config.pytest tests/unit_tests/rl/: 439 passed, 0 failed.pytest tests/unit_tests/cpu/test_qwen3_5.py tests/unit_tests/cpu/test_weight_tying.py: 27 passed. The same 4test_qwen35_shared_expert_uses_explicit_tp_boundariescases fail with and without this change in the local environment.Note:
scripts/checkpoint_conversion/numerical_tests_qwen3_5.pyno longer runs againstmain(the model and collator moved to packed inputs), so a logit comparison against HF is not included here.