~/satyajit

Tiny 2.1: a 367,000-parameter transformer under MS-DOS, and where its 540 KB go

mdjsonmcp

2026-11-24 · 18 min · small-models · quantization · inference · c · speech

A 2:22 narrated explainer, drawn in code. Every number and picture in it is this article's own; the sources are below.

› transcript

Is a whale a fish? No, a whale is a mammal. That answer came from a transformer running under MS-DOS. So did this one: seventeen times twenty-three is ninety-six. It isn't. Hi, I'm Doskey. Tiny is a small GPT that fits next to DOS in conventional memory. Its tricks are the same ones modern runtimes use. There is no tokenizer. Every printable character is a token, so the whole vocabulary is ninety-seven entries. Each letter gets a token embedding plus a learned position, out of a context of 128. Four layers of attention and a small ReLU block, with RMS norms and no biases. The output reuses the token embedding, so one table does two jobs. Then it picks a letter, and feeds it back in. Every answer letter is a full pass. Weights are signed bytes. But the sum is a float, so the multiply-add runs on the math coprocessor. The row's scale is applied once, after the dot product. That is why it wants a 486DX, and crawls on an SX. I ran it in DOSBox-X. Three answers took under a minute with the coprocessor. With it switched off, the software emulator took about thirty-one times as long. Add it up. The weight file, an eight-bit cache of keys and values, and the program. That is most of the five hundred and forty kilobytes the README asks for. And it talks. The PC speaker can play one square wave, at one pitch, and nothing else. So for a vowel, it flips between two pitches every two milliseconds, and your ear blurs them together. S and F become hiss, a new random pitch every millisecond. P and T are a tiny click. String those together with the rhythm of speech, and you get a film robot. On questions it never saw, it gets sixty-one percent right. Its arithmetic stops at small sums and the twelve times table. Outside its facts, it invents answers with full confidence. The model is a toy. The engineering is not: store in bytes, compute in floats, quantize the cache, and count every byte. Letters as tokens, bytes for weights, and a vowel made of two pitches. Thanks for watching! Every source is in the full article. I'm Doskey. Bye!

Why read this

Solidtop 85%

A full read of a DOS transformer's C source: the int8-storage, float-math design, the byte-exact memory budget and the PC-speaker voice, each made interactive.

  • Runs on a laptop CPU
  • Original analysis
  • A lasting reference

Quantization & compressionMixed licencesPractitioner teardown

How this was scored
Is it new?
1 of 3: An incremental tweak
Can I trust it?
2 of 3: Measures key facts from files, code or configs
Can I run it?
3 of 3: Open, permissive, runs on reader hardware with instructions
Will I understand it?
2 of 3: Mechanism from first principles with figures
Can I act on it?
1 of 3: General advice
Will it last?
2 of 3: A reference for a year or more
Does it affect many?
0 of 3: A niche paper or one-off repo
Only here?
2 of 3: A teardown or measurement few others did

Score 57 of 100, ranked 566 of 780 rated articles. Each question is answered 0–3 by hand, and a 3 is rare. How articles are scored

A transformer that answers trivia on a 486 sounds like a stunt, and partly it is. It is also a complete, readable inference engine in about 1,400 lines of 1989-vintage C, with every decision a modern runtime makes (weight format, quantization, KV cache, sampling) made again under a 640 KB ceiling. That makes it a good thing to read closely.

The post that sent me there (@0x0SojalSec on X) and the Tom's Hardware piece it links both point at the primary source: WollyMonjac/Tiny-2.1 on GitHub, MIT-licensed code, with the program source, a prebuilt TINY.EXE, the weights and the full training kit. Everything below comes from reading that repository at commit 4934844. The README credits the code to "Fable 5.2" and the training to "Opus 5.5", which is its own small sign of the times.

A DOS text-mode screen in neon colours. Left, a conversation: is a whale a fish, No, a whale is a mammal; what is 17 times 23, 17 times 23 is 96; who invented the telephone, Alexander Graham Bell; who is the king of france, It was Antarce Newton. Right, a neural monitor with four layer-activity bars, confidence 100%, a last-letters heat strip, speed 4.4 letters/s, network 4 layers, 96 wide, creativity 0.
Tiny 2.1's full-screen interface. Two answers are right, and two are confidently wrong: 17 × 23 is 391, and France has no king. The status bar reads 22 letters in 5.0 s on the developer's machine, which is not named (the Tiny-2.1 repository, tiny21.png).

The model, in numbers you can check

The header of TINY.BIN is the string TNY2 and four 16-bit integers. Read them and you get D = 96, L = 4, H = 4, and a middle (MLP) width of 256. TINY.C fixes the vocabulary at 97 and the context at 128 letters. From those, the parameter count is arithmetic:

PieceShapeNumbers
Token embedding97 × 969,312
Position embedding128 × 9612,288
Per layer: q, k, v, o4 × 96 × 9636,864
Per layer: MLP in and out2 × 256 × 9649,152
Norm gains9 × 96864
Total366,528

The four layers contribute 4 × (36,864 + 49,152) = 344,064 of that. There are no biases anywhere, the norm is RMSNorm with a learned gain, the MLP is ReLU, and the output layer reuses the token embedding (matvec(&emb, bh, score) at the end of step()), so the 97 × 96 table is used twice. 366,528 rounds to the advertised 367,000.

This is a small GPT, not a clever new architecture. The interesting work is all in how it is stored and run.

Letters as tokens

There is no tokenizer file, because there is no tokenizer. The vocabulary is printable ASCII:

#define VOCAB  97      /* 0 pad, 1 newline, 2.. the letters ' '..'~' */

Token 0 is padding, 1 is newline, and every printable character from space (32) to tilde (126) maps to its code minus 30. The training script's encode() does the same thing in Python. A question is fed one letter per step, then a newline, then the model writes letters until it emits a newline (or pad). Question plus answer must fit in 128 letters, and TINY.C cuts a typed question at 72.

Character-level is the right call at this size. A BPE vocabulary of even a few thousand tokens would cost more in its embedding table than the whole network has in layers. The price is that every answer letter costs a full forward pass, and "Alexander Graham Bell." is 22 of them.

int8 is how it is stored, not how it computes

"8-bit weights" reads like integer math, the kind that would run on any 386. The source says otherwise, and so does its own README: "It uses floating point. With a math coprocessor (any Pentium, any 486DX or 486DX2) an answer takes a few seconds. Without one (386SX/386DX, 486SX) the coprocessor is emulated in software and an answer can take several minutes."

Every weight table is a row-major block of signed bytes with one 32-bit float scale per row:

typedef struct {
    float *scale;
    signed char *w;
    int rows, cols;
} Table;

And the one matrix-vector product in the program accumulates in float and applies the row's scale at the end:

static void matvec(const Table *t, const float *x, float *y)
{
    int r, c, cols = t->cols;
    const signed char *w = t->w;
    float s;
    for (r = 0; r < t->rows; r++) {
        s = 0.0f;
        for (c = 0; c < cols; c++)
            s += w[c] * x[c];
        y[r] = s * t->scale[r];
        w += cols;
    }
}

So the activations x are floats, each w[c] is a signed byte promoted to float, and the multiply-add runs on the x87. Pulling the scale out of the inner loop is the one trick: the row's dot product is computed on the raw bytes and scaled once, instead of dequantizing 96 or 256 weights per row. The quantization itself is per-row absmax, from export() in train2.py: divide the row by its largest magnitude over 127, round, clip to ±127.

That design is why the README asks for a 486DX and warns off the SX. Turbo C's "Emulation" floating-point option links a software x87 that steps aside when a coprocessor is present, so the same EXE runs on both. On an SX every s += w[c] * x[c] goes through the emulator.

How well does 8 bits fit these weights? Reading all 365,664 weight bytes out of TINY.BIN myself: 3,238 of them sit at ±127 (roughly one per row, the row's own maximum), 3,445 are zero, and 54.3% have a magnitude of 32 or less. More than half of all weights sit in the bottom quarter of the range, which is what per-row absmax gives you when a row has a few large weights. The training script reports two scores after a run, one for the float model and one for the rounded copy (quantized_copy()). The README's 61% doesn't say which of the two it is.

A full integer path would be possible (int8 activations, 16- or 32-bit accumulators, fixed-point softmax and RMSNorm) and would free it from the FPU. It would also mean rewriting exp, sqrt and the norm in fixed point. The author chose floats and a DX.

The K/V cache is int8 too

A step processes one letter at one position, so earlier keys and values have to be kept. alloc_memory() gives every layer two 128 × 96 byte arrays and a float scale per position:

static float store(signed char *dst, const float *src)
{
    int i;
    float big = 0.0f, v, k;
    for (i = 0; i < D; i++) {
        v = src[i] < 0 ? -src[i] : src[i];
        if (v > big) big = v;
    }
    if (big < 1e-20f)
        big = 1e-20f;
    k = 127.0f / big;
    for (i = 0; i < D; i++) {
        v = src[i] * k;
        dst[i] = (signed char)(v < 0 ? v - 0.5f : v + 0.5f);
    }
    return big / 127.0f;
}

Each new key and value vector is quantized on the way in with its own absmax scale, shared across the four heads. Attention then takes the dot product of a float query against the stored bytes and multiplies by that position's scale, the same pattern as matvec. A float cache would have been 4 bytes a number instead of 1. For a 4-layer, 96-wide, 128-position model that is the difference between 102,400 bytes and 393,216, and the second number would not fit next to the weights.

Where 540 KB comes from

The README says Tiny needs "about 540 KB of free conventional memory". The pieces are all countable from the source, so I added them up:

That sums to 537,800 bytes. The C runtime's allocation overhead (about 80 separate malloc calls), the static work buffers and the stack come on top, so "about 540 KB" is the honest round-up, not a marketing figure. DOS, its drivers and TSRs come out of the same 640 KB first, which is why the README walks you through DOS=HIGH,UMB, LOADHIGH and MEMMAKER.

The widget also shows the limit you hit if you try to grow the model. Under Turbo C's large memory model, data pointers are far pointers, but a single object still lives in one 64 KB segment. load_table() refuses any table over 65,000 bytes:

if ((long)rows * cols > 65000L)
    fail("a table in TINY.BIN is too big for DOS.");

The largest table in the released model is an MLP matrix, 256 × 96 = 24,576 bytes. Go to the program's own maximums, 128 wide with a 512-wide middle, and the MLP table is 65,536 bytes: 536 over.

Two smaller details are DOS-specific and easy to miss. The scratch buffers (bx, bh, bq, bm and the attention scores) are static, with the comment "so they do not use the small DOS stack". And the loader checks sizeof(char *) != 4 && sizeof(int) == 2 and refuses to run unless the program was built with the large model, because in the small model a malloc of the tables would run out of its single 64 KB data segment long before 380 KB.

The cost of one letter

Every letter, read or written, is one call to step(): four layers of RMSNorm, three D × D projections for q, k and v, attention over every earlier position, the output projection, the MLP, and finally the 97 × 96 output product. Counting only the matrix-vector products, that is 4 × (4 × 96 × 96 + 2 × 96 × 256) + 97 × 96 = 353,376 multiply-adds per letter. Attention adds roughly 2 × 96 multiply-adds per earlier position per layer, small next to that until p gets large.

The interface reports "SPEED" in letters per second, and per the README it counts "letters per second, including reading the question": answer letters divided by total time, so reading the question is in the denominator but not the numerator. The screenshot above shows 4.4 letters/s, from 22 letters in 5.0 s. The machine is not stated, so that number tells you the order of magnitude and nothing more.

DOSBox-X at 10,000 to 100,000 cycles

I ran the released TINY.EXE and TINY.BIN (checked by SHA-256 against the repository) in DOSBox-X 2025.02.01, headless, inside a throwaway container on a Linux server. That is the "never on my laptop" rule for third-party code. The input was 12 questions from the README's "Things to try" list, fed in plain mode with TINY 0 /P < Q.TXT, so creativity 0 and the same answer every time. The timings are Tiny's own, from its clock() calls, so they are emulated DOS time, not wall time. A "step" is one forward pass: every question letter, the newline and every answer letter.

DOSBox-X settingSteps per secondAnswer letters per second12 answers took
486, coprocessor on, 10,000 cycles0.830.30587.6 s
486, coprocessor on, 25,000 cycles2.090.76234.3 s
486, coprocessor on, 50,000 cycles4.201.52116.8 s
Pentium, coprocessor on, 50,000 cycles4.201.52116.8 s
Pentium, coprocessor on, 100,000 cycles8.453.0558.0 s
486, coprocessor off, 25,000 cycles (3 questions)0.070.031,580.8 s

All 12 answers were right and identical across runs: "Lima.", "No, a whale is a mammal.", "7 times 8 is 56.", "Latvia and Russia.", "E-L-E-P-H-A-N-T.", "It is Au.", "In Spanish it is gracias.", "A pride.", "It is 200.", "Eight.", "Alexander Graham Bell." and "The Pacific Ocean.". Together they took 490 steps for 177 answer letters.

Speed is linear in the cycle count: double the cycles, double the steps per second. That is what you expect when every step is the same 353,376 multiply-adds plus a little attention. At 10,000 cycles a step takes about 1.2 seconds, so 12 million cycles a step, or roughly 34 per multiply-add on my arithmetic. A DOSBox-X cycle is roughly one emulated instruction, and the float loop in matvec loads a byte, converts it, multiplies, adds and loops.

Choosing a Pentium instead of a 486 changes nothing at a fixed cycle count, because DOSBox-X's cycle setting sets the speed, not the CPU model. These rows are not real 486 or Pentium timings, and I am not going to map cycles to megahertz. The "Lima." answer took 39.1 s at 10,000 cycles and 15.6 s at 25,000, against the README's "a few seconds" with a coprocessor. That fits a real machine running well above 25,000 DOSBox-X cycles, but I didn't measure one.

Then the coprocessor. With the emulated FPU switched off, Turbo C's software emulator takes over, as the README says it will. On the same three questions, the 25,000-cycle run with the coprocessor took 51.7 s and the one without it took 1,580.8 s, about 31 times longer. "Lima." alone went from 15.6 s to 476.2 s. The README's "several minutes" on a 486SX is, if anything, kind.

At 100,000 cycles the host could not keep up in real time (162 s of wall clock for 58.0 s of emulated time), which does not change the emulated numbers. On a slow host, expect the wall clock to run behind.

Sampling, with a creativity knob

pick() is greedy at creativity 0. Above that it divides the scores by creativity / 5 as a temperature, throws away any letter whose relative weight falls below 0.15 of the best, and samples from what is left with rand(). The 0.15 cut is a crude top-p, and its comment states its purpose: "never pick unlikely letters". At creativity 5 (the default) answers are reworded between runs. At 9 it makes, in the README's words, "more mistakes". For quizzes and arithmetic the README says to start it as TINY 0.

The monitor's CONFIDENCE bar is the softmax probability of the chosen letter, computed in chosen() as 1/∑iesi−stok1 / \sum_i e^{s_i - s_{\text{tok}}}, which is the same thing written without a division per term.

A voice from one square wave

The PC speaker is wired to channel 2 of the 8253/8254 timer. It plays one square wave at one frequency, on or off. Turbo C wraps it as sound(hz) and nosound(), and delay(ms) waits. No samples, no mixing, no volume. The README is upfront: "The robot voice is not real speech". say_letter() maps each letter to a gesture:

case 'a': buzz(730, 1090, 64, shift); break;
case 'e': buzz(530, 1840, 56, shift); break;
case 'i': case 'y': buzz(300, 2290, 52, shift); break;
/* ... */
case 's': case 'z': case 'c': case 'x': hiss(46); break;
/* ... */
case 'p': case 't': case 'k': case 'q':
    tone(3200, 2); quiet(18); break;

buzz() alternates between its two frequencies every 2 ms for the letter's duration. The source calls the pairs "formant-like": 730 and 1,090 Hz for "a", 300 and 2,290 Hz for "i", a low and a high pitch per vowel. A real vowel has both formants at once, shaping a voiced source. The speaker can only play one, so it flips between them 250 times a second and lets your ear blur them. hiss() picks a new random pitch between 2,500 and 7,000 Hz every millisecond, a passable fricative. Plosives are a 2 ms click and a gap. Every buzz is scaled by a shift that falls from 115% to 85% across the answer, so sentences droop at the end the way spoken ones do.

While the voice plays, speak() highlights each word on screen in time with it, and any key stops it. The README's reason for not doing real text-to-speech is memory, not ambition: "Real text-to-speech does not fit next to the network in 640 KB of memory." A formant synthesizer driving the speaker through pulse-width tricks (the way 1980s speech software did it) would need a sample-rate timer interrupt and a phoneme table, and the conventional memory is already spoken for.

What it knows, and how it was taught

The training kit is the most useful part of the repository if you want to make one of these. Facts live in plain files (question | question => answer | answer lines, and tab-separated relation, subject, answer tables), and gen2.py turns them into an endless stream of question-answer pairs: many phrasings per relation, reversed questions ("Paris is the capital of which country?"), yes/no, two-part questions, sums and times tables, spelling, "I do not know" for made-up countries and words, and typing noise (swapped, dropped and doubled letters, a neighbouring key, CAPS LOCK, "hey tiny"). The mix is weighted: 31% table facts, 23% one-off facts, 10% numbers, and the rest spread over the other generators.

TRAINING.TXT gives the history. Version 2 started from the version 1 network, grown from 3 to 4 layers and from a 192 to a 256-wide middle. The grow() function does this without changing what the network computes at the start: the new MLP units and the whole new layer get zero output weights, so they begin as no-ops and learn from there. Then 20, 15, 150 and 180 minutes of training on two CPU cores, about 15 million examples in all. That is about six hours.

The README's own evaluation: 61% on 780 test questions in wordings and combinations it never saw (version 1 got 6% on the same set), and about 90% on questions worded the way it was taught. It lists its weak spots honestly: two countries in one question, coast and landlocked, rare elements, division, and invented names, where "it sometimes invents an answer instead of saying it does not know". Sums go up to 20 + 20 and the times table to 12, which is why the screenshot's 17 × 23 comes out as 96.

One small irony in the file sizes: a 3.5-inch 1.44 MB disk holds 1,474,560 bytes raw, the full-precision checkpoint tiny2.pt is 1,476,049, and so the training checkpoint is the one file in the project that would not fit on the floppy. The DOS files (TINY.EXE and TINY.BIN, 435,412 bytes together) fit with room for the source.

Running it

The repository ships a prebuilt TINY.EXE, so you do not need Turbo C. Copy TINY.EXE and TINY.BIN into one directory on a DOS machine (or DOSBox), check that MEM reports at least 540K for the largest executable program, and run TINY. A few options are useful:

TINY 0                    always the surest answer
TINY /DEMO                it asks itself sample questions
TINY 0 /P < Q.TXT > A.TXT plain text, questions from a file

To rebuild, TCC -ml TINY.C with Turbo C 2.0 (the -ml is the large model, and the README warns that the 8087-only floating-point option makes an EXE that crashes without a coprocessor). The training kit needs Python 3, NumPy and PyTorch, and the README notes that exporting tiny2.pt unchanged gives exactly the released TINY.BIN.

WollyMonjac/Tiny-2.1@4934844 · snapshot 2026-11-24

Language model for DOS that fits on a floppy disk

stars
484
license
MIT
branch
main
forks
68
open issues
4
source
121.8 kB
commit date
2026-11-17
source by language
Python80.4 kBC41.2 kBBatchfile0.2 kB

GitHub REST API, 2026-11-24 — branch, commit, commitDate, createdAt, description, forks, languages, license, openIssues, pushedAt, stars

The code is MIT. Three fact files derived from public datasets keep their own licences (ODbL for the country tables, CC BY-SA 3.0 for the elements), and the README notes that the trained weights were trained partly on that data.

The model is the least of it

367,000 parameters trained on 3,500 facts is a lookup table with good manners, and it says so: outside its facts it makes things up with full confidence, as the king of France demonstrates.

The engineering is what I'd keep, and it transfers. Store in int8 with a per-row scale and keep the math in float. Quantize the KV cache per position. Count every byte against a hard budget before you write a line. Reuse the embedding as the output layer. Pick a character vocabulary when the model is too small to pay for a BPE table. Small models elsewhere live under the same kind of budget: MimiModel puts a 45M model on a five-dollar chip, and the tiny browser models run inside a browser tab. The ceiling here is 640 KB, which makes each decision visible.

The voice is the bit I'd show people. Two pitches swapped every 2 ms to fake a vowel is the kind of hack that only exists because the hardware gives you exactly one wire. If you want the modern end of small speech, Paradee fits a Kokoro-style voice in 8M parameters, and the small TTS roundup compares three more.

Cite this article

For attribution, please use the following reference or BibTeX:

Satyajit Ghana, "Tiny 2.1: a 367,000-parameter transformer under MS-DOS, and where its 540 KB go", ai.satyajit.si, November 2026.

bibtex
@misc{ghana2026tiny21dostransformer,
  author = {Satyajit Ghana},
  title  = {Tiny 2.1: a 367,000-parameter transformer under MS-DOS, and where its 540 KB go},
  url    = {https://ai.satyajit.si/articles/tiny-2-1-dos-transformer},
  year   = {2026}
}
share