How an 8 MB AI chatbot works

Affan AI Engine Nano is a real chat AI in a single 8.4 MB file that runs inside a web page. Here is how it is built, why it is so small, and what it can and cannot do.

The model in one paragraph

Nano is a decoder-only transformer with 14 million parameters: 8 layers, a width of 384, 6 attention heads that share 2 key-value heads (grouped-query attention), a SwiGLU feed-forward block, rotary position embeddings (RoPE) and tied input and output embeddings. It reads text as 8,192 byte-level BPE tokens (digits are split one by one, which helps arithmetic) and has a context window of 1,024 tokens. It was trained on only about 4 billion tokens in total (about 2 billion of base training plus about 2 billion of chat and facts tuning), which is very little for a language model, so expect simple, short answers and frequent factual mistakes.

Parameters14 million
Layers / width8 layers, 384 wide, feed-forward 832
Attention6 heads, 2 key-value heads, RoPE
Vocabulary8,192 byte-level BPE tokens
Context1,024 tokens
File8.4 MB int4 (.afn), tokenizer and metadata inside

Why it is only 8.4 MB: 4-bit weights

A normal model stores every weight in 16 or 32 bits. Nano stores each weight in 4 bits, two per byte, with one 16-bit scale for every group of 32 weights. That alone makes the file about a quarter of its fp16 size.

Plain rounding to 4 bits hurts a model this small. In our tests it kept only about 84 to 88 percent of the full-precision quality. So the weights are quantised in two steps: first GPTQ, which rounds using calibration data, then distillation training, where the 4-bit model is fine-tuned to copy the full-precision model. The result keeps about 99 to 100 percent of the full-precision quality on our evaluation sets, at the same file size.

Fine-tuned for casual chat

After pre-training, Nano was fine-tuned on short, human-like conversation: filtered everyday dialogues, hand-written greetings, slang, typos, moods and reactions, honest answers to questions an AI cannot answer like a person, plus generated identity, calculator and joke examples. To stop it forgetting older skills, training also kept the new model close to the original on stories and identity (a KL penalty), and the 4-bit version was trained again against the new model. Result on messages it never saw: about two thirds of replies fit the message well (about one in five before), stories, identity and the calculator still work, and the calculator was called and wrote the right expression in 38 of 40 maths questions.

Facts, and not making things up

A 14M-parameter model cannot learn the world, so instead of letting it guess, Nano was taught a closed set of verified simple facts with many different wordings, plus lots of examples of questions it should refuse to guess (made-up places and people, live data, things it was never taught). In our tests: about 88% of known facts answered correctly in new wordings (up from 28% for the previous version on the same hard test), and for unanswerable questions it said it was not sure about 68% of the time, up from 9% originally. It still invents answers sometimes, especially for real places it was not taught.

The AEN engine

AEN is the inference engine made for Nano. The native version, AEN.cpp, runs on CPUs and NVIDIA GPUs and also contains Metal and ARM code paths. This website runs the web edition: a JavaScript port of the same CPU path with its heavy loops written as hand-assembled WebAssembly SIMD128 kernels. Nothing about the model is hard-coded: layer sizes, tokenizer, special tokens and the system prompt are all read from the model file.

We checked the web engine against the native one: the tokenizer matches the Hugging Face tokenizer exactly, greedy replies are identical to AEN.cpp, and the logits agree within float rounding noise. On a desktop PC it generates roughly 300 to 500 tokens per second in the browser.

The calculator tool

Small models are bad at arithmetic, so Nano does not guess. When you ask for maths it writes a tool call such as <|calc|>17*23<|/calc|>. The engine evaluates the expression exactly and inserts <|result|>391<|/result|>, then Nano continues the sentence with the right number. You can watch the calculator chip appear in the chat.

Privacy and offline use

Everything happens in your browser. The page, the engine and the model are cached after the first visit, so Nano works with no internet, and your messages are never uploaded because there is no server to upload them to.

What it cannot do

Nano is tiny. It can be wrong about facts, it has a 1,024-token window, and every message is answered on its own, without memory of earlier ones. It is not a replacement for large assistants. It is a demonstration that a useful, friendly chat AI can fit in 8 MB, run on a phone, and even run on a microcontroller. See the FAQ or run it on an ESP32.

Talk to Nano right now

One 8.4 MB download, then it runs on your device. No sign-up, no server.

Wake up Nano