r/MachineLearning • u/Final-Data-1410 • Aug 22 '26
Research I developed my own quantized LLM from scratch, trained on 30B tokens, deploys in 60 MB [R]
I trained a 250M parameter model from scratch on 30B tokens of fineweb. It’s quantized to under 2 bits so the whole deployment is 60 MB and it needs about 80 MB of RAM to run. Runs around 400 tok/s on a normal laptop CPU, no GPU needed.
How the long context works: the most recent 2048 tokens stay in fp16 like a normal KV cache. Everything older gets compressed to 1 bit and written to disk, about 320 bytes per token, so 1 million tokens of history is roughly 320 MB on disk. From the start the model was trained to retrieve from that disk cache, up to 100M tokens. Due to a limited budget it wasn’t trained to reason over those tokens, only retrieve and answer from them.
Language modeling quality of the base model, measured on held-out English web text that was never seen in training (educational web pages, 2,048 token windows): cross entropy 3.15 nats per token, perplexity 23.3, 0.99 bits per byte.
The vocabulary is also not a normal embedding table. Every token is a fixed 512-bit code, 8.4 MB for all 131k tokens, zero trained parameters. I tested it on WordSim-353 (human word similarity ratings): my table scores 0.619 Spearman correlation vs 0.029 for random codes. Test script is in the repo.
Some outputs (settings included so you know I’m not cherry picking, all reproducible from the repo):
“Explain photosynthesis in two sentences.” (greedy)
Photosynthesis is a process in which plants convert sunlight into chemical energy, which is then used to produce oxygen and other chemicals. This process is called photosynthesis.
“Write a short poem about the sea.” (temp 0.25, top-k 30, rep 1.15, seed 2)
The waves had swept over, and they were crashing against each other like rocks on top of one another. The wind was strong but not very gentle as it tried to push them towards their destination without lifting any weight or pulling away from those who stood in front of her with a stiff smile that made the sea look even more majestic than before.
“What is the serial number of device Grus-189?” where the answer sits 50.6 million tokens deep in the archive on disk (archive mode, k=16)
SN-442976
It’s a 250M model so expect mistakes on open facts, I’m not claiming it beats anything big. You can also fine-tune it, the full kit with a demo and before/after numbers is included. Master weights for fine-tuning are in the repo too:
https://github.com/QLNI/SHADOW-250M-Instruct
https://huggingface.co/NODEMIND/SHADOW-250M
Edit - Just wanted to say thanks to everyone here. Honestly I was afraid to post this, I expected to get roasted, but every single comment has been curious and helpful and it genuinely made my day.
Repo is at 7 stars on GitHub now, hopefully more people try
50
u/MrSnowden Aug 22 '26
I’m somewhat amazed that 2 and 1 bit compression gets these results. Great work.
11
u/pakeke_constructor Aug 22 '26
This is incredible and fascinating. Amazing work with the 100M token disk cache stuff. It almost makes me think of a vector database kinda? Super super cool
17
u/PhilTheQuant Aug 22 '26
Fantastic stuff, what's your estimate of how this would scale to large model sizes?
And do you plan to go to reasoning next?
6
u/silenceimpaired Aug 22 '26
This sounds like it could run on raspberry pi quite well… I’m confused though. If someone has 128 gb of memory for the model why compress and write to disk? Why not leave it uncompressed in memory?
4
u/Murhie Aug 22 '26
Interesting results. I dont quite understand the offline context cache, is this something that you came up with yourself or is there anywhere I can read up on it. Is is like a collection of common patterns that might occur in context? It sounds complex.
Ah nvm see now that its custom history. Still would be interested to learn more.
2
u/CuriousExplorerer Aug 23 '26
Honestly fascinating work. But I gotta ask some questions.
I really like the idea of quantisation of the history or old context. Any specific you used for this? I myself am looking to train a model from scratch, preferably multimodal to understand how to train models to find the most efficient representation of data. This is giving me vibes of super intelligence since it’s not about how big the model is, but how capable it is given resources for a task.
Do write a technical blog this so that we can understand what decisions you have taken throughout the process and more importantly WHY?
1
u/AkumaBPS Aug 23 '26
How are you compiling the binary? It doesn't run in my local env. If you are using -march=native I think you should remove it(?
1
u/kanripper Aug 24 '26
What was training time for this and how big is datacorpus exactly?
1
u/Banality_Of_Seeking Sep 10 '26
Hello,
After sometime to really think about this, your code and idea enabled me to rethink architecture, there is a way to control certain words in Shadow, but that is not as interesting as Shadow itself. Thank you for realeasing your work.
3
u/if47 Aug 22 '26
TL;DR: An expert system based on a language model, or vice versa.
2
u/mxcw Aug 22 '26
I was actually looking for something EXACTLY like this. Good stuff, thanks for sharing!
2
u/hiepxanh Aug 22 '26
How long to train that model?
2
u/pramood8686 Aug 24 '26
Good playlist to learn on how to build model.. Please
2
u/Able_Region_5459 Aug 27 '26
Dumping the KV cache onto an SSD and tagging on a dictionary search - holy crap, that's brilliant in its stupidity. No Ring Attention or any other GPU math acrobatics needed
Pulling something like that off solo, training it from scratch, and actually replying to comments with sane answers.. mad respect, dude!
1
u/light24bulbs Aug 22 '26
How does it search the context? Was it trained on some fixed context?
1
u/Guilherme370 Aug 22 '26
I'm going to be playing around a decent bit with this, thank ya very much!
Also, name suggestion for the next scaled up model when and if ya are able to make it: UMBRA
1
u/Loud_Key_3865 Aug 23 '26
This is very cool! Would it be safe to assume one could create several duplicates of these, and train them on specific info (e.g. legal regulations, something related, etc. then delegate accordingly?)
Thank you for sharing!!!
1
u/bmurders Aug 23 '26
I'm wondering if incorporating web search functionality would help enhance the model by grounding it with relevant context. This is cool! Thanks for sharing.