Repository navigation
Closed
Labels
currently fixingAm fixing now!
Description
Hello,
I've fine-tuned a model (unsloth/mistral-7b-instruct-v0.3-bnb-4bit) and successfully uploaded the LoRA to Hugging Face. Using the LoRA directly works as expected, and the fine-tuned behavior is clearly visible.
Here's how I use the LoRA:
from unsloth import FastLanguageModel
from transformers import TextStreamer
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "Betha/fen_with_cot_base_lora",
max_seq_length = max_seq_length,
dtype = dtype,
load_in_4bit = load_in_4bit,
token = access_token
)
FastLanguageModel.for_inference(model)
text_streamer = TextStreamer(tokenizer)
messages = [
{"role": "user", "content": "2rq1rk1/pp3pb1/3p1pp1/3P3P/8/5p2/PPPQ4/2KR1B1R b - - 0 17"},
]
inputs = tokenizer.apply_chat_template(
messages,
tokenize = True,
add_generation_prompt = True,
return_tensors = "pt",
).to("cuda")
_ = model.generate(input_ids=inputs, streamer=text_streamer, max_new_tokens=2048,
use_cache=True, temperature=1.5, min_p=0.1)
I then tried to merge the base and LoRA and push it to Hugging Face like this:
model.save_pretrained_merged("fen_cot_base", tokenizer, save_method="merged_16bit")
model.push_to_hub_merged("Betha/fen_cot_base", tokenizer, save_method="merged_16bit", token=access_token)
However, when I load the merged model:
from unsloth import FastLanguageModel
from transformers import TextStreamer
model, tokenizer = FastLanguageModel.from_pretrained(
model_name="Betha/fen_cot_base",
max_seq_length=max_seq_length,
dtype=dtype,
load_in_4bit=load_in_4bit,
token=access_token
)
FastLanguageModel.for_inference(model)
text_streamer = TextStreamer(tokenizer)
messages = [
{"role": "user", "content": "2rq1rk1/pp3pb1/3p1pp1/3P3P/8/5p2/PPPQ4/2KR1B1R b - - 0 17"},
]
inputs = tokenizer.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_tensors="pt",
).to("cuda")
_ = model.generate(input_ids=inputs, streamer=text_streamer, max_new_tokens=2048,
use_cache=True, temperature=1.5, min_p=0.1)
The results seem to reflect the base model rather than the fine-tuned one. The distinct style visible when using the LoRA directly is missing after merging.
Am I missing something during the merge or the loading process? Is there an additional step needed to ensure the merged model includes the LoRA weights correctly?
Thanks in advance for your help! 🙏
Metadata
Metadata
Assignees
Labels
currently fixingAm fixing now!
Activity
lucky-bai commentedon Feb 20, 2025
Likely the same issue as this one: #1670
FloLey commentedon Feb 22, 2025
Hello and thanks for taking the time to respond. It seems related indeed. I just want to point out that I'm not using GRPO to fine-tune the mistral model.
Thanks!
wofeishenling commentedon Feb 24, 2025
same problem!!!
shimmyshimmer commentedon Apr 6, 2025
@FloLey do you have the full script of what you did? Because we tested it and it works
rolandtannous commentedon Jun 6, 2025
@FloLey @Mtrya @lucky-bai @wofeishenling @yuiseki
A fix has now been merged into pypi for both vision and language models and extensively tested.
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.
jasonkhadka commentedon Jul 26, 2025
#3045
Still facing the same issue.