Repository navigation
Description
Latest version of Unsloth (Unsloth 2026.2.1)
After a full training run, I noticed the adapter_config.json, the key target_modules didn't include the lm_head, but the modules_to_save did include the lm_head, this resulted in this error when attempting to merge:
RuntimeError: Unsloth: Extracted keys = {'lm_head.weight'} do not match!
in the saving_utils from unsloth_zoo here: Exact line asserting the issue saving_utils.py#L303
Cause: the lm_head is silently getting filtered out or included somewhere within the code and causing issues down the line later on.
How to reproduce (Reproducible in Colab):
- Load the peft module with the
lm_headintarget_modules(inside theget_peft_model)- if there's weight tying involved, it will automatically do the right thing (LoRA on top or not during training)
(Colab Example) Qwen3-4B-Thinking Notebook; modify the code for the get_peft_model
model = FastLanguageModel.get_peft_model(
model,
r = 32, # Choose any number > 0 ! Suggested 8, 16, 32, 64, 128
target_modules = ["lm_head", "q_proj", "k_proj", "v_proj", "o_proj",
"gate_proj", "up_proj", "down_proj",], # Added "lm_head" to target_modules
lora_alpha = 32,
lora_dropout = 0, # Supports any, but = 0 is optimized
bias = "none", # Supports any, but = "none" is optimized
# [NEW] "unsloth" uses 30% less VRAM, fits 2x larger batch sizes!
use_gradient_checkpointing = "unsloth", # True or "unsloth" for very long context
random_state = 3407,
use_rslora = False, # We support rank stabilized LoRA
loftq_config = None, # And LoftQ
)
- Train the model
- Verify the
adapter_config.jsonof the resulting trained LoRA adapter (to validate thelm_headshows, you'll see nolm_headin thetarget_moduleswithin theadapter_config.json, butlm_headwill be in themodules_to_save) - Attempt merging using
save_pretrained_merged
Within the same notebook, at the Saving float16 for VLLM, you switch the first if clause to True
if True:
model.save_pretrained_merged("qwen_finetune_16bit", tokenizer, save_method = "merged_16bit",)
- and then the specified exception appears
RuntimeError: Unsloth: Extracted keys = {'lm_head.weight'} do not match!
Additional related information (What are the expected behaviors):
Activity
marcandrelarochelle commentedon Feb 23, 2026
Using Qwen3-8B-unsloth-bnb-4bit, also reproducible in Colab (used the Qwen3_(4B)-Instruct.ipynb notebook since the 14B would OOM if the
lm_headis added when trying to reproduce the issue), was able to reproduce with 100% on 3 different environment.marcandrelarochelle commentedon Feb 24, 2026
Potentially related PRs: unslothai/unsloth-zoo#369, #3711
Datta0 commentedon Feb 24, 2026
@oKatanaaa any thoughts here?
kirawi commentedon Mar 5, 2026
I don't think this is actually fixed for Qwen3.5-35B? I had to force
tie_word_embeddings = Trueinunsloth-zooto get it to merge.Edit: Actually, not 100% sure since I was using the release version of unsloth-zoo for training rather than master.