Starts Nov 23Live Cohort 3 of Vibe Coding & AI Agents (Nov 23, 18:30 MSK): 3 weeks, 9 live hands-on sessionsCohort 3 (Nov 23) →
ReleaseInsight · On RadarHabr AI→ original

A 15M-parameter model pushed to 9.5 tokens per second on an ESP32-S3

The stories15M model, with 15 million parameters, does not fit into the ESP32-S3's memory, so the weights are read from slow flash on every token. The author cut the vocabulary from 32,000 to 6,144 tokens, compressed the layers to 4 bits, and added draft tokens generated by the model itself. Speed rose from 2.96 to 9.5 tokens per second. Quality dropped by about 5.2% in bits per byte of text, so when memory is the bottleneck, it pays to read fewer bytes rather than compute faster.

AI-processed from Habr AI; edited by Hamidun News
A 15M-parameter model pushed to 9.5 tokens per second on an ESP32-S3
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
Key metric #1Flash delivers 31.5 MB/s, while internal SRAM delivers 3,779 MB/s, which is 120 times faster
Key metric #2The ×16 trick with no unpacking of 4-bit weights: 2.31 → 4.01 tokens/s
Key metric #3Two draft tokens per pass yield 9.05–9.50 tokens/s, while four yield only 7.2

Can a real language model run on a chip that costs about as much as a cup of coffee? The author of a series of articles on Habr says yes, and fairly fast. In the second part, he ran stories15M, a full Llama-2 with 15.

2 million parameters, on an ESP32-S3 microcontroller and pushed the speed to 9.5 tokens per second. (A token is a piece of a word, so the model produces several words per second.)

The problem is that the board has only 512 KB of fast SRAM and 2 MB of PSRAM, while the model weighs 58 MB in float32 and 15 MB when compressed to int8, meaning weights stored as 8-bit integers. It fits in neither, so every token requires rereading all the weights from flash memory. It's like having to walk to a library on the other side of the city for every word: speeding up how fast you read the book is pointless; you have to carry fewer pages.

In the first part, the tiny stories260K model, with 260 thousand parameters, fit entirely in SRAM and produced 406 tokens per second. Here the model is 58 times larger, and the main resource becomes not the processor but the data bus.

Why everything comes down to flash

Flash and PSRAM sit on the same SPI bus. On the author's board, flash delivers 31.5 MB/s, PSRAM delivers 32.8 MB/s, and internal SRAM delivers 3,779 MB/s, which is 120 times faster. To produce one token, all the weights must be read once, and the processor multiplies them faster than flash can supply them. As a result, generation speed equals flash throughput divided by the model's size, and the whole task reduces to reading fewer bytes per token. A useful reference point is the NanoMind-S3 project with the same stories15M model: 1.49 tokens per second in int8 and 2.96 in int4.

A notable detail: 9.2 million of the 15.2 million parameters are the embedding table for 32,000 tokens, which must be read in full at the output on every step. The transformer layers themselves total only 6 million.

How the amount read was reduced

The first step was the vocabulary. The model was trained on children's stories, and across 305 thousand tokens it generated itself, only 4,287 distinct tokens out of 32,000 appeared. The author kept 6,144 tokens, selected by the probability mass the model assigns to them rather than by simple frequency.

All 256 byte tokens were preserved, so any text can still be encoded. The cost was about 1.4% in bits per byte of text, while the classifier became nearly five times lighter (1.

7 MB instead of 8.8 MB). A first attempt that simply removed tokens from the tokenizer produced a +267% error increase: long tokens are built through a chain of merges, and without the intermediate pieces you cannot reach the target word.

The second step was 4-bit weights. Simple rounding with one scale per row gives a +28% increase in perplexity, meaning the model predicts text noticeably worse. Groups of 32 weights with their own scales helped, along with the GPTQ algorithm (which adjusts not-yet-rounded weights to compensate for the error), a zero point, and column ordering by importance. The result was +3.9% instead of +28%. The GPTQ statistics were gathered from stories the model itself had written, and quantization takes about half a minute in numpy. The layers now weigh 3.3 MB instead of 5.8 MB.

The third step was arithmetic without unpacking. The PIE vector instructions have no arithmetic shift by bytes, so honest unpacking of nibbles is expensive. The author used the fact that a signed nibble in the high half of a byte already equals 16·q as a regular int8. A mask and a single shift are enough, and the extra factor of 16 goes into the row scale. Scalar int4 in C turned out slower than int8 (2.31 versus 2.96 tokens per second), while with PIE it reached 4.01.

Next came smaller optimizations, each with its own gain. The second core gave +15% (4.63 tokens per second). A 64 KB data cache with 64-byte lines raised flash reads from 26.1 to 31.5 MB/s and speed to 5.51, and this took just two lines in sdkconfig. Undocumented cache autoloading from ROM added only 1.5%. A two-stage classifier first scores all tokens at 4 bits, keeps the top 16, and recomputes them in int8, which gave +16% without changing the text. Moving the remaining data into SRAM as whole matrices brought the speed to 6.56 tokens per second.

The model prompts itself

The final step targets the other part of the fraction: a single pass over the weights should yield several tokens. This is speculative decoding. A cheap "draft" proposes several next tokens, and the model verifies them in one pass, so the output is exactly what it would have chosen on its own. The draft is built from text already written and from a trigram table of 22 thousand entries (130 KB), which the model compiled from its own stories.

On the board, two draft tokens worked best: 9.05 tokens per second on a familiar opening and 9.50 on a new one. Three drafts gave 7.94 and 8.33, and four gave 7.20 and 7.27, because the extra arithmetic eats the gain. Each pass accepts 1.8–2.0 tokens.

What follows

The total cost of compression is about +5.2% in bits per byte, of which 1.6% comes from trimming the vocabulary. Speed rose from 2.96 tokens per second for NanoMind to roughly 9.5. The limitations are candid: speculation in the firmware is implemented only for greedy token selection, and the trimmed vocabulary suits only a narrow domain such as children's stories. The practical lesson extends beyond this board: if a model is limited by memory rather than computation, the wins come from reducing bytes read, storage formats tailored to specific instructions, and techniques that take more tokens from each weight read.

Story

Key Questions Answered

Why everything comes down to flash?

Flash and PSRAM sit on the same SPI bus. On the author's board, flash delivers 31.5 MB/s, PSRAM delivers 32.8 MB/s, and internal SRAM delivers 3,779 MB/s, which is 120 times faster. To produce one token, all the weights must be read once, and the processor multiplies them faster than flash can supply them. As a result, generation speed equals flash throughput divided by the model's size, and the whole task reduces to reading fewer bytes per token.

How the amount read was reduced?

The first step was the vocabulary. The model was trained on children's stories, and across 305 thousand tokens it generated itself, only 4,287 distinct tokens out of 32,000 appeared. The author kept 6,144 tokens, selected by the probability mass the model assigns to them rather than by simple frequency. All 256 byte tokens were preserved, so any text can still be encoded. The cost was about 1.4% in bits per byte of text, while the classifier became nearly five times lighter (1.7 MB instead of 8.8 MB).

What are the key details on The model prompts itself?

The final step targets the other part of the fraction: a single pass over the weights should yield several tokens. This is speculative decoding. A cheap "draft" proposes several next tokens, and the model verifies them in one pass, so the output is exactly what it would have chosen on its own. The draft is built from text already written and from a trigram table of 22 thousand entries (130 KB), which the model compiled from its own stories.

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Unified AI Workspace · Nomad

Test Frontier LLMs & Autonomous Agents in One Workspace

Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.

Try Nomad AI →Launch Nomad Agent
What do you think?
Loading comments…