{"by":"quesomaster9000","descendants":122,"id":46417815,"kids":[46418327,46419112,46418332,46421671,46419454,46418318,46420947,46418299,46420509,46421533,46418769,46418925,46418121,46420245,46484661,46423441,46418707,46418678,46418252,46419268,46424458,46418460,46418180,46418634,46418626,46421390,46418336,46418382,46434089,46422527,46419819,46422615,46419826,46418861,46418227,46421649],"score":514,"text":"How small can a language model be while still doing something useful? I wanted to find out, and had some spare time over the holidays.<p>Z80-μLM is a character-level language model with 2-bit quantized weights ({-2,-1,0,+1}) that runs on a Z80 with 64KB RAM. The entire thing: inference, weights, chat UI, it all fits in a 40KB .COM file that you can run in a CP&#x2F;M emulator and hopefully even real hardware!<p>It won&#x27;t write your emails, but it can be trained to play a stripped down version of 20 Questions, and is sometimes able to maintain the illusion of having simple but terse conversations with a distinct personality.<p>--<p>The extreme constraints nerd-sniped me and forced interesting trade-offs: trigram hashing (typo-tolerant, loses word order), 16-bit integer math, and some careful massaging of the training data meant I could keep the examples &#x27;interesting&#x27;.<p>The key was quantization-aware training that accurately models the inference code limitations. The training loop runs both float and integer-quantized forward passes in parallel, scoring the model on how well its knowledge survives quantization. The weights are progressively pushed toward the 2-bit grid using straight-through estimators, with overflow penalties matching the Z80&#x27;s 16-bit accumulator limits. By the end of training, the model has already adapted to its constraints, so no post-hoc quantization collapse.<p>Eventually I ended up spending a few dollars on Claude API to generate 20 questions data (see examples&#x2F;guess&#x2F;GUESS.COM), I hope Anthropic won&#x27;t send me a C&amp;D for distilling their model against the ToS ;P<p>But anyway, happy code-golf season everybody :)","time":1766986884,"title":"Show HN: Z80-μLM, a 'Conversational AI' That Fits in 40KB","type":"story","url":"https://github.com/HarryR/z80ai"}