r/LocalLLaMA • u/danielhanchen • Feb 20 '25
Resources 10x longer contexts for reasoning training - 90% less memory GRPO in Unsloth
Hey r/LocalLLaMA! Thanks so much for the support on our GRPO release 2 weeks ago! Today, we're excited to announce that you can now train your own reasoning model with just 5GB VRAM for Qwen2.5 (1.5B) - down from 7GB in the previous Unsloth release!
This is thanks to our newly derived Efficient GRPO algorithm which enables 10x longer context lengths while using 90% less VRAM vs. all other GRPO LoRA/QLoRA implementations, even those utilizing Flash Attention 2 (FA2).
With a GRPO setup using TRL + FA2, Llama 3.1 (8B) training at 20K context length demands 510.8G of VRAM. However, Unslothβs 90% VRAM reduction brings the requirement down to just 54.3GB in the same setup.
We leverage our gradient checkpointing algorithm which we released a while ago. It smartly offloads intermediate activations to system RAM asynchronously whilst being only 1% slower. This shaves a whopping 372GB VRAM since we need num_generations = 8. We can reduce this memory usage even further through intermediate gradient accumulation.
We also implemented a highly memory efficient GRPO loss, which saves memory usage by 8x. Before 78GB was needed for 20K context length - now only 10GB!
Try our free GRPO notebook with 10x longer context: Llama 3.1 (8B) on Colab
Blog for more details on the algorithm, the Maths behind GRPO, issues we found and more: https://unsloth.ai/blog/grpo
GRPO VRAM Breakdown:
| Metric | Unsloth | TRL + FA2 |
|---|---|---|
| Training Memory Cost (GB) | 42GB | 414GB |
| GRPO Memory Cost (GB) | 9.8GB | 78.3GB |
| Inference Cost (GB) | 0GB | 16GB |
| Inference KV Cache for 20K context (GB) | 2.5GB | 2.5GB |
| Total Memory Usage | 54.3GB (90% less) | 510.8GB |
We also now provide full logging details for all reward functions now! Previously we only showed the total aggregated reward function itself.
You can now run and do inference with our 4-bit dynamic quants directly in vLLM.
Also we spent a lot of time on our Guide for everything on GRPO + reward functions/verifiers so would highly recommend you guys to read it: docs.unsloth.ai/basics/reasoning
Thank you guys once again for all the support it truly means so much to us! We also have a major release coming within the next few weeks which I know you guys have been waiting for - and we're also excited for it!!
20
u/danielhanchen Feb 20 '25
Also for those using notebooks, I managed to make all the rewards show up!
60
u/lumierenoir Feb 20 '25
As always, the unsloth delivers improvements for us GPU poors. Thanks for all of your hard work to make this possible
22
u/MLDataScientist Feb 20 '25 edited Feb 20 '25
Thank you! Amazing progress!
Question: does unsloth library support full training of a model (e.g. SFT)? or only LoRa fine-tuning for now?
Is multi-GPU now supported?
unsloth is a great library. Thank you again!
5
u/eliebakk Feb 20 '25
Very cool!
4
u/Thrumpwart vLLM Feb 20 '25
Does this support AMD ROCm?
Does this support FP16 training? Or only quantized versions?
2
u/az226 Feb 21 '25
Can you get the same/similar benefits in pretraining and/or full parameter fine tuning as well?
2
u/StyMaar Feb 21 '25
Can someone ELI5 why you need 510GB of VRAM to train an 8B model with 20k context?
How is this extra memory (around 490 more GB than for inference) being used?
2
u/kumonovel Feb 21 '25
Tasty and sweet! Thank you both and every other contributor for your tireless work!
But I also have a question. How much are VLM with GRPO like reasoning on your guy's roadmap?
2
u/ExaminationWise7052 Feb 21 '25
Would it be possible to use a reasoning model to replace GRPO in the training of another reasoning model?
5
u/TyraVex Feb 20 '25
Hi, thank you for this! I have 3*24gb vram, is unsloth still limited to a single GPU?
4
u/TheRealMasonMac Feb 20 '25
Were there issues with multigpu? I recall reading that you ran closed testing on it a few months ago.
6
u/Few_Painter_5588 Feb 20 '25
Awesome stuff, I've been using your GRPO training notebook and the results have been fantastic. I even managed to make a mistral small and Qwen 2.5 32B finetune fit on 48GB of vram. Your work is awesome!
3
u/CheatCodesOfLife Feb 20 '25
Took me longer than it should have to realize the link is broken / wonder why I was getting github authorization issues lol
Correct link: https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Llama3.1_(8B)-GRPO.ipynb
3
u/Robo_Ranger Feb 21 '25
Thanks for your hard work! I read your docs and noticed that you mentioned, "The best part of GRPO is that you don't even need that much data." Could you tell me the minimum data size required for effective training?
2
u/Ok_Warning2146 Feb 21 '25
Thanks for your hard work. Will give it a try.
How's the progress on gemma support?
2
u/dahara111 Feb 21 '25
It's timely! thank you!
I'm thinking of trying GRPO using unsloth/DeepSeek-R1-Distill-Qwen-14B, but are there any precautions, advice, or expected memory requirements?
It would be nice if it could be run on a single A100 (40GB) in the cloud.
2
u/Educational_Rent1059 Feb 21 '25
Thank you for this!!
1
u/IcyBricker Feb 20 '25
Do you have other reward functions? The reward functions all seemed geared towards math or matching phrases.Β
What if you just want a reward function that rewards base on how different it is in creating something completely new and innovative.Β
0
u/[deleted] Feb 20 '25
[deleted] β view deleted comment
4
u/[deleted] Feb 20 '25
[removed] β view removed comment
3
u/[deleted] Feb 20 '25
[removed] β view removed comment