You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Gemma2b merging LoRA doesn't work properly on new tokens. #1971
I fine-tuned Gemma 2B (unsloth/gemma-2b-bnb-4bit) on new tokens.
My checkpoint works fine, but when I try to merge it to 16-bit or 4-bit, it doesn't recognize the newly added tokens. However, the general output still aligns with the LoRA model.
I know that Gemma has tied embeddings, so the PEFT model creates two separate weight matrices:
One for embeddings
One for lm_head
These weights are different during fine-tuning. However, after merging, they become tied (i.e., they share the same data pointer). I suspect that after merging, my lm_head weight matrix no longer exists, which is causing the issue.
@shimmyshimmer purely Lora.I also tried to patch Lora model lm_head into lm_head's merged model 16bit and 4 bit and it works.
But it's like using the Lora model without any merge.
I am also training LoRA using the unsloth/gemma2-9b-it model, and when I resume training, I found that the log does not continue the checkpoint reward.
A fix has now been merged into pypi for both vision and language models and extensively tested.
Should in principle also solve your problem here unless this is caused by something else.
reference: unslothai/unsloth-zoo#135 unslothai/unsloth-zoo#158 #2673
Merging and saving should work now.
Best Practice is save to 16bits (which is the default operation if you do not specify anything), and load in 4 bits if you have to.
For production systems, you might wanna consider post training quantization methods with calibration. These take longer but can also be more reliable.
Saving and merging to 4bits might degrade performance of the model.
To access this recent fix, and if you're running this in a local python environment, please make sure to upgrade your python environment using
Activity
FloLey commentedon Mar 14, 2025
I think this is the same issue as all those:
#1670
#1763
#1877
#1929
shimmyshimmer commentedon Mar 18, 2025
Is this for GRPO or purely Lora?
Serzhanov commentedon Mar 18, 2025
@shimmyshimmer purely Lora.I also tried to patch Lora model lm_head into lm_head's merged model 16bit and 4 bit and it works.
But it's like using the Lora model without any merge.
Serzhanov commentedon Mar 18, 2025
Also this solution is not satisfied because Gemma's embeddings kind huge.
daegonYu commentedon Apr 14, 2025
I am also training LoRA using the unsloth/gemma2-9b-it model, and when I resume training, I found that the log does not continue the checkpoint reward.
rolandtannous commentedon Jun 6, 2025
@FloLey @Serzhanov @daegonYu
A fix has now been merged into pypi for both vision and language models and extensively tested.
Should in principle also solve your problem here unless this is caused by something else.
reference:
unslothai/unsloth-zoo#135
unslothai/unsloth-zoo#158
#2673
Merging and saving should work now.
Best Practice is save to 16bits (which is the default operation if you do not specify anything), and load in 4 bits if you have to.
For production systems, you might wanna consider post training quantization methods with calibration. These take longer but can also be more reliable.
Saving and merging to 4bits might degrade performance of the model.
To access this recent fix, and if you're running this in a local python environment, please make sure to upgrade your python environment using
If you're in colab, the notebooks install cell will also be updated shortly but should be something like
as we're no longer pinning transformers or trl.
Also note that whenever you need to merge while saving or while pushing to hub, make sure to use
and
If you are not merging at all, use
and
instead.
I'll close this for now. Feel free to comment if you face any problems.
Happy finetuning.