Lurker News
Hi HN! I'm just sharing a project I've been working on during the LLM Efficiency Challenge - you can now finetune Llama with QLoRA 5x faster than Huggingface's original implementation on your own local GPU. Some highlights:

1. Manual autograd engine - hand derived backprop steps.
2. QLoRA / LoRA 80% faster, 50% less memory.
3. All kernels written in OpenAI's Triton language.
4. 0% loss in accuracy - no approximation methods - all exact.
5. No change of hardware necessary. Supports NVIDIA GPUs since 2018+. CUDA 7.5+.
6. Flash Attention support via Xformers.
7. Supports 4bit and 16bit LoRA finetuning.
8. Train Slim Orca fully locally in 260 hours from 1301 hours (5x faster).
9. Open source version trains 5x faster or you can check out Unsloth Pro and Max codepaths for 30x faster training!
https://www.reddit.com/r/LocalLLaMA/comments/188197j/80_fast... has more info about Unsloth!
Hopefully you can try it out! Wrote a blog post at https://unsloth.ai/introducing if you want to learn more about our manual hand derived backprop or Triton kernels and stuff! Thanks once again!

Comments (119) 20 threads

Show all comments

Showing thread 1 of 20

apsec1123 replies#
I haven't run the code, but... how is this even possible? I've done PyTorch profiling on QLoRA Llama-2-70B fine tunes, and the runtime is dominated by the large matrix multiplies in the MLP layers, plus a bit for attention. Under the hood, this repo calls the same torch.matmul() for MLP and flash_attn_func() for attention as HuggingFace does. So how can it be that much faster? They have a few Triton kernels, but there appears to be no Triton on MLP or attention and that's most of the bottleneck.
apsec1121 reply#
That... doesn't really explain how they can get such a high number? Standard FLOP efficiency on fine-tuning big models is like 30-40%. How can you get 750%?
danielhanchen21 replies#
Hey! Great question! That's what I'm confused about as well!

So in GPUs the goal is to saturate the GPU with matrix multiplies instead of data movement. I'll write a more detailed blog but approximately:
1. Flash Attention v2 reduces the time taken by 17% or so
2. RoPE Triton kernels: -7.1%
3. RMS Layernorm in Triton: -3.1%
4. Cross Entropy in Triton: -1%
5. Manual autograd for MLP: -4%
6. Manual QKV autograd: -2%
7. Manual O autograd: -2%
8. Smart cache evictions and reduced data duplications etc: -30%
9. And other tricks in the Max and Pro versions makes it 30x faster
You can see it's just tricks in each step, which accumulate together to make to go faster.
I'll write up a blog post to detail it all in the future!!!

Continue this thread — 21 replies

WhitneyLand1 reply#
They say it’s due a custom optimized version of autograd which is sort of a key calculus component. They also mention simple things like function inlining or memory optimizations. It seems plausible these things could be optimized.

Whatever advantage they have I don’t see how they would be able to to keep it for long as part of their closed source “pro” version.
If it’s low hanging fruit the open source equivalents are bound to snipe them before long.

danielhanchen1 reply#
There's more as well!! I agree hypothetically in a few years people will catch up - we're well aware of that! But we made this into a startup, and so this was just one product we were releasing! We're going to be making many AI products in the coming weeks!
WhitneyLand1 reply#
That sounds really great, we need all the advancement we can get in this field.

Best of luck and all success to you!

danielhanchen#
Thanks a bunch!! Super appreciate it!
bradfox21 reply#
These are significant claims locked behind a paid 'pro' version. Red flags.
danielhanchen3 replies#
Sorry about that - I'm super new to pricing and stuff so it might seem off since I'm literally making the plans with my bro as we go along.

If you don't believe the timings, I was the author of Hyperlearn https://github.com/danielhanchen/hyperlearn which makes ML faster - I also listed the papers which cite the algos.
I also used to work at NVIDIA making TSNE 2000x faster on GPUs and some other algos like Randomized SVD, sparse matrix multiplies etc.
If you have any suggestions on a more appropriate pricing strategy - I'm all ears!!
I really don't know much about pricing and the open core model, so I'm making stuff up literally.

bradfox21 reply#
Are the 30x claims comparing full update training vs qlora/4bit weights?

Continue this thread — 1 reply

MacsHeadroom2 replies#
Pro says single GPU some places and multi-GPU others. I really hope it is multi-GPU because basically every enthusiast making finetunes is using 2-4 3090s locally or renting 8x GPU boxes on Vast for finetuning. If multi-GPU is enterprise only you will miss out on basically the largest customer segment as far as I can tell.

Continue this thread — 2 replies

bugglebeetle3 replies#
If this is all legit, you’re best trying to get an in somehow with a16z. They’re throwing money left and right at people doing this kind of stuff.

Continue this thread — 3 replies