Repository navigation
Closed
Labels
unsure bug?I'm unsure
Description
I am following unsloth colab notebook for pretriaining. Followed by save_pretrained_merge and reloading the merged with FastVisionModel.from_pretrained(...). The reloaded model has very different output from the non-merged finetuned model.
model, processor = FastVisionModel.from_pretrained(
# "unsloth/gemma-3-4b-it",
"unsloth/gemma-3-4b-pt",
load_in_4bit = False, # Use 4bit to reduce memory use. False for 16bit LoRA.
use_gradient_checkpointing = "unsloth", # True or "unsloth" for long context
)
# train the model on latex dataset from unsloth notebook
# wrap model to Lora: I am not doing vision FT
model = FastVisionModel.get_peft_model(
model,
finetune_vision_layers = False, # False if not finetuning vision layers
finetune_language_layers = True, # False if not finetuning language layers
finetune_attention_modules = True, # False if not finetuning attention layers
finetune_mlp_modules = True, # False if not finetuning MLP layers
r = 16, # The larger, the higher the accuracy, but might overfit
lora_alpha = 16, # Recommended alpha == r at least
lora_dropout = 0,
bias = "none",
random_state = 3407,
use_rslora = False, # We support rank stabilized LoRA
loftq_config = None, # And LoftQ
target_modules = "all-linear", # Optional now! Can specify a list if needed
modules_to_save=[
"lm_head",
"embed_tokens",
],
)
FastVisionModel.for_training(model) # Enable for training!
trainer = SFTTrainer(...)
trainer.train()
# infer and save the model
FastVisionModel.for_inference(model) # Enable for inference!
out1 = model(**inputs)
# save the merged model, model should be merged and saved in fp16
model.save_pretrained_merged("/tmp/unsloth_finetune", processor,)
# reload the merged model
merged_model, merged_processor = FastVisionModel.from_pretrained(
"/tmp/unsloth_finetune",
load_in_4bit = False, # Use 4bit to reduce memory use. False for 16bit LoRA.
use_gradient_checkpointing = "unsloth", # True or "unsloth" for long context
)
FastVisionModel.for_inference(merged_model) # Enable for inference!
merged_out = merged_model(**inputs)
print((out1.logits - merged_out.logits).mean())
>>> tensor(-0.1275, device='cuda:0', grad_fn=<MeanBackward0>)
print((out1.logits - merged_out.logits).max())
>> tensor(25.7500, device='cuda:0', grad_fn=<MaxBackward1>)Unsloth versions:
unsloth 2025.7.8
unsloth_zoo 2025.7.10
Metadata
Metadata
Assignees
Labels
unsure bug?I'm unsure
Activity
jasonkhadka commentedon Jul 26, 2025
This issue should have been fixed and was discussed before, but apparently not.
@rolandtannous
#1670 (comment)
rolandtannous commentedon Aug 30, 2025
we've discussed this at length in a separate discord thread. will turn this into a discussion for now.