cd /news/machine-learning/unsloth-vs-axolotl-vs-trl-87-of-your… · home topics machine-learning article
[ARTICLE · art-78359] src=pub.towardsai.net ↗ pub= topic=machine-learning verified=true sentiment=· neutral

Unsloth vs Axolotl vs TRL: 87% of Your Fine-Tuning VRAM Goes to a Tensor You Never Wrote

A first-principles analysis of LoRA fine-tuning memory usage reveals that 87.3% of VRAM scaling with sequence length for Llama 3.1 8B is consumed by the cross-entropy loss head tensor, not the model, optimizer, or attention activations. For gpt-oss-20b the figure is 95.2%, and at 16K context the loss tensor requires 49.1 GB while the 4-bit quantized model fits in 12.8 GB. The analysis, implemented in a 120-line calculator, shows that the primary difference between frameworks like Unsloth, Axolotl, TRL, and LLaMA-Factory lies in how they handle this single tensor, with memory savings being structural and substantial rather than the modest speed gains typically cited.

read1 min views1 publishedJul 29, 2026
Unsloth vs Axolotl vs TRL: 87% of Your Fine-Tuning VRAM Goes to a Tensor You Never Wrote
Image: Pub (auto-discovered)

Member-only story

I spent an afternoon pricing every byte of a LoRA fine-tuning step from first principles, and the result was not what I expected. For Llama 3.1 8B, 87.3% of the memory that scales with your sequence length is not the model, not the optimizer, and not the attention activations. It is the cross-entropy loss head — one tensor that exists for a few microseconds, produces a single scalar, and never appears in your training script.

For gpt-oss-20b it is 95.2%. At 16K context that one tensor wants 49.1 GB, while the entire 4-bit quantized model it is training fits in 12.8 GB. The loss function is four times the size of the thing being trained. This is the actual axis on which Unsloth, Axolotl, TRL, and LLaMA-Factory differ. Everybody reads the framework comparisons as “Unsloth is 2x faster,” files it under marketing, and moves on. That framing is wrong. The speed numbers are real but modest and model-dependent. The memory numbers are enormous and structural, and they come almost entirely from what each framework does with this one tensor.

I wrote a 120-line calculator that prices it. Then I checked it against Unsloth’s published benchmark table. On an 80 GB GPU my arithmetic predicts the Transformers + FlashAttention-2 baseline at 27,713 tokens

── more in #machine-learning 4 stories · sorted by recency
── more on @unsloth 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/unsloth-vs-axolotl-v…] indexed:0 read:1min 2026-07-29 ·