Retrieved article excerpt
Open article · Retrieved 2026-10-26T19:27:44.171960+00:00
[Back to Articles](https://huggingface.co/blog)
# How I Made It Possible to Pretrain a 1B LLM on 6GB VRAM
[Community Article](https://huggingface.co/blog/community)
Published
September 26, 2026
[Upvote
15](https://huggingface.co/login?next=%2Fblog%2FRitishReal%2F1b-petrain-llm-in-4gb-vram)
- +9
[Rambarun Komaljeet's avatar](https://huggingface.co/RitishReal)
[Rambarun Komaljeet
RitishReal
Follow](https://huggingface.co/RitishReal)
[DOI 10.5281/zenodo.22725431](https://zenodo.org/records/22725431) ·
[30 min run video of a 1B param LLM pretrain on the laptop](https://youtu.be/8m0Hwrzfmaw?si=bDE6Gen5Sey_2wNg) ·
[code on GitLab](https://gitlab.com/komalbarun/kramba-ai)
## The problem
I wanted to train a language model from scratch. Not fine-tune one, not call an API for
one — actually watch a model learn from nothing, on my own machine, because I was curious
whether it was possible and because I couldn't afford to find out any other way.
Every forum, every blog post, every "getting started" guide said the same thing: you need
a real GPU for this. An A100, a cluster, at minimum a desktop card with 24GB of memory.
What I had was a gaming laptop with a 6GB graphics card in it — the kind of card that's
fine for games and a joke for anything people call "AI."
So I didn't do the sensible thing. I opened Claude and started asking: is that actually
true, or is it just what everyone assumes because nobody's tried hard to make it not true?
It took weeks. It is not a joke anymore. The training pipeline — building a real 1.1
billion parameter model, running real steps, saving a checkpoint, killing the process and
resuming it correctly — works, start to finish, on that same 6GB laptop GPU. I want to be
precise about what that does and doesn't mean: nobody, including me, has sat through an
entire training run yet. A full run takes months, not hours, so "it works end to end"
means the machinery is correct and measured, not that a finished model is sitting on my
disk. Every number below is something I actually watched happen on my own machine, over
real measured stretches of training — not a finished model, and not a projection dressed
up as one.
Here's the honest before-and-after, same laptop, from the first working version to now:
| | First working version | Now |
| --- | --- | --- |
| Time for one training step | 21.81 seconds | **12.335 seconds** (-43%) |
| Tokens processed per second | 1,579 | **2,656** |
| Estimated time for a full pretrain | about 375 days | **about 132-211 days** |
| Peak memory used | 4.51 GB of 6 GB | **5.24 GB of 6 GB** |
That "132-211 days" range, not a single number, is itself an honest admission: the cheap
way of fitting the model (described next) costs some quality, and the range is "if you
accept that cost" versus "if you insist on matching full-quality training instead."
## Why a laptop GPU can't just "fit" a model this size
A model's size in parameters isn't really the problem. The problem is that *training* a
model needs a lot more memory than just storing it does. For every number in the model's
weights, training also needs to remember the direction that number should move in (the
gradient), and a running history of how it's been moving (the optimizer's memory of past
updates) — and on top of the model itself, there's the scratch space for the actual
calculation as it works through a chunk of text.
Add all that up with no tricks at all, and a billion-parameter model needs somewhere
around 16-17 times its own weight in GPU memory. A 6GB card can hold maybe 350-400 million
parameters that way. Not 1.1 billion. Not close.
This is the real reason "you need an A100" is the standard advice: it's true if you train
the obvious way. Everything that follows is about not training the obvious way.
## Idea one: only wake up the part of the model that's learning right now
Here's the trick that made the biggest difference. A deep model is really a stack of
blocks — layer after layer. The usual way to train is to wake all of them up at once:
every block sits in GPU memory, every block gets updated every step.
Instead: freeze all but one block. Train just that one for a while. Move on to the next
block, and freeze the one before it. Rotate through the whole stack, one block "live" at
a time.
The win is memory, not speed. A frozen block doesn't need its training-memory (the
gradient history, the optimizer's running average) sitting around — only the one active
block does. And since a frozen block isn't being touched, it doesn't even need to stay on
the graphics card at all; it can sit in ordinary system RAM until its turn comes back
around, and get swapped in just before it's needed.
That's two separate tricks working together: training one block at a time (so most of the
model needs no training-memory at any given moment), and parking the blocks that aren't
"live" in regular RAM instead of the graphics card's precious memory. Together they're
most of the reason a 6GB card can hold a model many times its own naive capacity.
There's a real cost to this, and I want to be upfront about it rather than bury it:
training one block at a time is not quite as good as training the whole model together.
Right now, measured honestly, it costs about 1.6x worse perplexity (a measure of how
surprised the model is by real text — lower is better) compared to training everything at
once with the same data and the same time. It used to cost about 4x worse, until I found
a dumb inefficiency in how the blocks were split up — one of them was sized to fit the
vocabulary table and ended up way bigger than the others, which wasted memory that could
have gone to training more of the model live at once. Fixing that split cut the quality
cost by more than half. It's still a real cost, not a free lunch, and I'd rather say that
plainly than let anyone think this is a trick with no tradeoff.
## Idea two: shrink the weights themselves
Separately from all of that: the model's weights don't need to be stored as full-precision
numbers. There's a technique (not mine — it's from a paper called BitNet) where each
weight, once trained, can be rounded down to one of exactly three values: minus one, zero,
or plus one, plus a single shared scale number per layer to stretch those three values
back out to the right range.
That sounds like it should destroy the model, and it would if you tried to do it after
training normally. The trick is to quantize *during* training, from the start, so the
model learns weights that are already comfortable being three values instead of a
continuous range. Done that way, it works — the model trains fine, and the compressed
weights take up a fraction of the space the original ones would have.
It doesn't shrink the memory used *during* training, to be clear — while the model is
actively learning, a full-precision shadow copy of each weight still has to exist so the
gradient updates have something precise to nudge. The saving shows up afterward: in the
saved checkpoint file, and later, when the model is actually being used to generate text
rather than being trained.
## Idea three: do the arithmetic in a cheaper number format, safely
Modern graphics cards can do their core multiplication-and-addition arithmetic in several
different levels of numerical precision. Lower precision is faster and uses less memory,
but every level down is a little less accurate.
Most of the training here runs in a middle-precision format that's a good balance already.
But most recently, I moved the single most common operation in the whole model — the big
matrix multiplications inside every layer — onto the graphics card's lowest-precision,
fastest tensor format, specifically for the parts of the computation where a few digits of
precision genuinely don't matter.
I didn't take that on faith. I measured the actual output of the model with and without
it, on real data, to make sure the answers didn't change in any way that mattered — and
they didn't. What changed was speed: about 8% faster across a full cycle through all the
blocks. Nothing about training the model got worse to get that.
Here's what each real idea above actually removes, side by side, plus two more small ones
that don't earn a whole section of their own: the input and output vocabulary tables are
really the same lookup used twice, so sharing one copy instead of two is a clean cut with
no real cost; and instead of keeping every intermediate result from the forward pass
sitting in memory until it's needed for the backward pass, most of it gets thrown away and
quickly recalculated when it's actually needed — more GPU work, far less memory held open
at once.
| Idea | What it removes | How much |
| --- | --- | --- |
| Train one block at a time | Training-memory for every block but the active one | about 8x less optimizer memory |
| Park frozen blocks in system RAM | Those blocks leave the graphics card entirely | scales with how deep the model is |
| Three-value weights | Full-precision weight storage | 2.33x smaller, checkpoint and inference only |
| Share one vocabulary table instead of two | A whole duplicate table of weights | 103M parameters at this model's size |
| Recompute instead of store | Saved activations from the forward pass | activation memory down to about 50 MB |
## The part nobody finds exciting but that added up anyway
A lot of the rest of the speed came from doing dozens of small, boring things slightly
better: combining two or three separate small calculations into one so the graphics card
doesn't have to keep stopping and restarting; not recomputing something twice when the
first result is still sitting right there; moving data around in the order the hardware
actually likes instead of the order that was easiest to write first.
None of these individually sound like much. Stacked together, over weeks, they're a big
part of why the step time came down by more than 40% since the very first working version.
The lesson I keep re-learning: "I think there's nothing left to speed up" has been wrong
multiple times in a row now. I try to say it a lot less confidently these days.
## What doesn't work (and why I'm telling you)
I spent real time on things that didn't pan out, and I think that's worth being honest
about instead of only showing the wins.
Mixture-of-experts — splitting the model's "thinking" layer into several smaller specialist
pieces that only partially activate — looked promising on paper but cost almost twice the
compute for a modest quality gain here. Not worth it at this scale.
A scheme to automatically detect when the model was about to have a sudden jump in ability,
so training could react to it — it never found a real jump. Every "detection" also fired on
pure random noise, which means it wasn't detecting anything at all.
Compiling the model with PyTorch's automatic compiler, which usually speeds things up —
here it made things more than twice as slow, every single time I tried it, because this
particular architecture recompiles itself constantly in a way that eats the benefit. I
stopped trying it a while ago.
Teaching the model to read exact facts out of provided text turned out to need a
completely different ability than holding a fluent conversation. The chat-tuned model
responds naturally and correctly to small talk and simple factual questions, but asking it
to recall something specific from a document it was just given is a separate, much weaker
skill — fluency and grounded recall are not the same thing, and I'd misjudged how much one
implies the other.
And one I'll be fully honest about because it happened a few hours before I wrote this:
I tried to work out how much faster a nicer graphics card would make all of this, and I
got it wrong — twice, in two different ways, before getting a defensible number. The first
mistake assumed a much bigger card would run at exactly the same speed as this laptop's,
which badly understated it. The second mist