Repository navigation
Description
Greetings,
I am extremely confused why my model generates consistent result w/o my rank=64 LoRA. What's even more confusing is, the LoRA works in my notebook after training. But whenn I start fresh, loading the LoRA again, it gives the output of the original model.
model_name=="Qwen/Qwen2.5-1.5B-Instruct",
vllm==0.7.3
trl==0.15.2
unsloth==2025.2.14
unsloth_zoo==2025.2.7
So I followed the tutorial notebook, trained the model using GRPO trainer. Then within the notebook, I model.save_lora("grpo_saved_lora"), then I do this using vllm with greedy decoding:
sampling_params = SamplingParams(
max_tokens=32, # Maximum number of tokens to generate
temperature=0, # Temperature of 0 means no randomness (deterministic)
top_p=1.0, # Consider all tokens in the distribution
top_k=1 # Only select the most likely token at each step
)
outputs = model.fast_generate(
test_split,
sampling_params = sampling_params,
lora_request = model.load_lora("grpo_saved_lora"),
)
These are all fine, I have different set of output compare with before training. But then, when I try to load the model lora with a separate script. The output is suddenly consistent with the original model, even I loaded the lora in this way.
cfg = load_config(args.config)
model, tokenizer = FastLanguageModel.from_pretrained(
model_name=cfg.model_name,
max_seq_length=cfg.max_seq_length,
load_in_4bit=cfg.load_in_4bit,
fast_inference=cfg.fast_inference,
max_lora_rank=cfg.lora_rank,
gpu_memory_utilization=cfg.gpu_memory_utilization,
)
lora = None
if args.lora_path is not None:
model = FastLanguageModel.get_peft_model(
model,
r=cfg.lora_rank,
target_modules=cfg.target_modules,
lora_alpha=cfg.lora_rank,
use_gradient_checkpointing="unsloth",
random_state=3407,
)
lora = model.load_lora(args.lora_path)
print('using lora ' + args.lora_path)
_, _, test_dataset = get_dataset("ecqa")
sampling_params = SamplingParams( # Greedy decoding
max_tokens=32, # Maximum number of tokens to generate
temperature=0, # Temperature of 0 means no randomness (deterministic)
top_p=1.0, # Consider all tokens in the distribution
top_k=1 # Only select the most likely token at each step
)
vllm_prompts = [x['prompt'] for x in test_dataset]
outputs = model.fast_generate(
vllm_prompts,
sampling_params = sampling_params,
lora_request = lora
)
Could you please help me? I am really confused.
Thank you very much.
Activity
JangDongHyeon11 commentedon Mar 14, 2025
I have the same issue.
When merging models using LoRA, the model does not change.
It seems that all models trained after the latest Unsloth update have this issue.
However, models trained previously do not have this problem.
FloLey commentedon Mar 14, 2025
I think this is the same issue as all those:
#1670
#1763
#1877
#1929
#1971
SpaceHunterInf commentedon Mar 14, 2025
Yeah... it seems like it's the exact same issue. I am using the lastest release though. Have you ever find any workaround for this except using the resume_training trick? How do othe people saving trained model now? I thought this should be some urgent bug that needs to be fixed.
So everyone else just finetune the entire model instead of using LoRA???
SpaceHunterInf commentedon Mar 14, 2025
Could you please share the version number that you were using? So you just downgrade and everything works again?
FloLey commentedon Mar 15, 2025
No idea, I've been waiting for this to be fixed or for someone to explain how to work around the issue, as I need the LoRA merged with the base model as well. I've seen this issue pop up multiple times already, so I'm trying to track this to get attention to it, but I don't want to put pressure on the owners of this repo.
llzllx70 commentedon Mar 16, 2025
I meet the same issue too, a big bug!
kalachx commentedon Mar 16, 2025
I would say it is not only big bug but a complete deal breaker for the project. Such issues show complete lack of testing being done before making releases.
If something as mundane as saving model doesn't work then what certainty can I have that other features work? For example whole models might have bugs because each model family needs specific support and why there are always patches for new models - since no one tests this stuff how do I know some older model family still works?
Change something, do wrong tests (read: see that training starts and not that it actually works) or no tests at all and then user sits there waiting for their model to cook to then end up disappointed. As new user I experience only frustration and zero results. Did thousands of GPRO training steps and nothing. Model behaves identical to untrained model.
danielhanchen commentedon Mar 16, 2025
Hi apologies everyone - let me investigate and I'll see what I can do to fix the issue!
Alpacolypse commentedon Mar 17, 2025
Is anyone aware of a workaround for this issue?
shimmyshimmer commentedon Mar 18, 2025
So we investigated the issue and were able to reproduce the issue (results after merging in 16-bit are same as before training).
However, we checked that
_merge_lorais working as expected and that thebase_layerweights before / after merging are indeed different by roughly the magnitude ofB @ A(since the scale factor is 1 per the defaultQwen-GRPOnotebook).We will need to conduct a deeper investigation into this thank you.
Do you guys know when this issue started firstly occuring?
danielhanchen commentedon Mar 18, 2025
Apologies on the issue - I might, but not 100% sure might have fixed the issue - if you guys still have the trained LoRA on your disk, could you try
model.load_lora( "directory", load_tensors = False)ie useload_tensors = Falseas the extra argumentllzllx70 commentedon Mar 18, 2025
[rank0]: File "~/anaconda3/envs/Unsloth/lib/python3.10/site-packages/unsloth_zoo/vllm_utils.py", line 1202, in load_lora
[rank0]: raise OSError(f"Unsloth: LoRA filepath = {save_directory} does not exist!")
[rank0]: OSError: Unsloth: LoRA filepath = grpo_saved_lora does not exist!
danielhanchen commentedon Mar 18, 2025
Hmmm ok let me see if I can bypass the checks - again apologies!
JangDongHyeon commentedon Mar 18, 2025
Currently, the issue is not only with GRPO, but also when training the model with LoRA and merging it, the model does not change.
shimmyshimmer commentedon Mar 18, 2025
Hi guys we have likely resolved the issue. Please update unsloth and let us know if it works! Thank you
24 remaining items
danielhanchen commentedon Mar 21, 2025
Hey guys - apologies on the delay - specifically for GRPO - it's fixed! I also made an advanced GRPO notebook which is actually much better than the original - it uses an A100 and does LoRA on Llama 3.2 3B, since it was faster.
NO NEED to retrain LoRA - if you saved it, then reload it! Unsloth inference is now fully fixed in the original GRPO and advanced notebook. (Please use advanced since I added many more reward functions, and it's much better for convergence!
Advanced Colab notebook: https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Advanced_Llama3_1_(3B)_GRPO_LoRA.ipynb
I also show the previous model without GRPO for the question
"What is the sqrt of 101?"The trained GRPO on the same question - which definitely show it's working!
Using the following works without changing code - I fixed
model.lora_loraI also restarted the entire Colab, and just load the LoRA via the above (without training), and it worked correctly!
You can test if the LoRA is working by just counting the formatting:
You should get more good results as GRPO follows the formatting correctly for the trained outputs - if you don't see any changes, then GRPO failed.
My training loss curves for the advanced notebook:
Steps to get the latest updates:
You do NOT need to retrain the LoRA - simply load it. I also added a LoRA error check to the advanced Colab to check if it's actually trained!
Tagging everyone since I'm assuming this was important! Again apologies on the delay - there were tonnes of new models and stuff, so hopefully this helps!
@kalachx @SpaceHunterInf @JangDongHyeon @caiqizh @accemlcc @llzllx70 @FloLey @shimmyshimmer @Alpacolypse @nazarenodefrancescomaize @YaqiWangCV @zzz1YAO @JangDongHyeon11
llzllx70 commentedon Mar 21, 2025
I think it would be better if the tests have the same prompt before and after load lora.
As it can shows that the improve come from lora but not the system_prompt
accemlcc commentedon Mar 22, 2025
Okay, I ran the notebook, made an 8bit GGUF out of it, loaded it into LMStudio, and fed it question 1000 from the training set. With the system prompt 'You are a helpful assistant. Think before you answer and place it in {reasoning_start} and {reasoning_end}. Then, provide your answer between {solution_start} and {solution_end},' it does a better job of following these instructions than the standard model. As for reasoning: it simply excludes its normal response within the reasoning tags, so it fundamentally 'thinks' before it answers. You can see this in the training log; the standard Llama 3B is already remarkably smart and can basically answer all questions correctly... This leads me to the fundamental question: Do these models even need reasoning? Would it perhaps be a new training goal to reconsider its standard response, so to speak, a 'rethink' of the normal 'think'? Would it make sense to use new tokens for this? ... Fundamentally, I consider this repo to be a great inspiration... I need to rethink my goals, everything is moving so fast.
YaqiWangCV commentedon Mar 23, 2025
I'm encountering an issue while using GRPO to train a text entity recognition model. Although the reward can reach a very high level, the reasoning process gradually degrades and eventually only outputs two words:
Can anyone tell me why the reasoning process degrades? How can I make the model expand its reasoning process to further improve performance? Very grateful for any help!
gurveervirk commentedon Mar 23, 2025
Hi @danielhanchen,
Looked at your notebook for the changes. I have saved the final grpo adapter to my hf account via push_to_hub() method. However, when trying to load the model from hf in another session, the model performed similar to the base model, without grpo tuning.
Should I be loading the model like that, or is there any other way?
The lora adapter for grpo tuned qwen model, when saved using save_lora() has a size of ~220MB, whereas the one saved via push_to_hub() has a size of ~420MB. Can someone clarify this discrepancy?
Thanks!
ngohoangnam28101995 commentedon Mar 25, 2025
I loaded in 4-bit and also have the same issued
nazarenodefrancescomaize commentedon Mar 25, 2025
I think the problem is not fixed yet.
I reloaded an already done training as suggested but the saved lora and the hf pushed ones have the same behaviour of the original model.
I'm on "unsloth==2025.3.18" "unsloth-zoo==2025.3.16"
The wird thing is that with the previous version of unlosth (2025.3.13) the saved lora worked, the merged and pushed model not.
The training code:
Macharia-Maurice commentedon Apr 4, 2025
🚨 Error loading merged float16 model from Hugging Face
I fine-tuned
Qwen2-vl-7bfor tomato leaf disease detection using Unsloth. After fine-tuning, I uploaded the merged model in float16 to Hugging Face using Lightning.AI on a T4 GPU (Colab kept crashing).Now, when I try to load the model:
On Lightning AI, I get this error:
On Colab, I get this:
The files in my repo look like this:
I successfully load the LoRA weights from my Hugging Face repository, and the model returns responses that align with the training performed.
Only issue is loading the merged model.
nazarenodefrancescomaize commentedon Apr 7, 2025
You are not alone, it is related to #1521
Macharia-Maurice commentedon Apr 7, 2025
So merging LoRA to the base model is an issue, and even for those who successfully merge and try to inference the merged model, they still face an issue where performance deteriorates ???
nazarenodefrancescomaize commentedon Apr 7, 2025
Yes. I have spent hundreds of dollars on A100 in order to finetune with GRPO Phi-4 and now that model is stuck on the virtual runtime because I cannot merge the model and push it to HF, and neither pushing only the lora works, because applying that lora gives only vanilla outputs.
I also tried retraining with latest versions of unsloth using smaller models (phi-4-mini and gemma-3), also using their own colabs without touching anything. Nothing.
For now, it is a waste of money, I'm sorry to say that.
metalwhale commentedon Apr 14, 2025
I'm not sure if this will work (since I have no way to verify), but in my case, it seems like I can load the LoRA using one of the following methods:
LORA_REQUEST_IDto a positive value before callingload_lora:My hypothesis:
LORA_REQUEST_IDis set to0, which prevents the LoRA from loading (??)model.fast_generate:0(i.e., don't use one of the methods above): it prints an emptyset(), indicating that the LoRA was not loaded{1}, indicating that the LoRA was successfully loadedPackage versions:
unsloth:2025.3.19unsloth-zoo:2025.3.17vllm:0.8.2rolandtannous commentedon Jun 6, 2025
@Alpacolypse @FloLey @JangDongHyeon @JangDongHyeon11 @Macharia-Maurice @Mtrya @Serzhanov @SpaceHunterInf @YaqiWangCV @accemlcc @adamtcdev @akbarsigit @allen20200111 @caiqizh @daegonYu @gurveervirk @ikirtanee @jeromeku @jotaefe0 @kalachx @llzllx70 @metalwhale @nazarenodefrancescomaize @ngohoangnam28101995 @shed-e @void-mckenzie @youbin2014 @zzz1YAO
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.
This has been closed for now. Feel free to comment if you face any problems.
Happy finetuning.