I wanted to see how far I could push a tiny microcontroller.
My ESP32-C3 has a 160 MHz processor, around 400 KB of SRAM, and 4 MB of flash storage.
The model I chose was Qwen2.5-0.5B-Instruct, a language model with approximately 500 million parameters.
That's far larger than the memory available on the ESP32-C3.
Still, I wanted to find out whether the microcontroller could perform the actual transformer calculations.
The Challenge
Running an LLM normally requires enough memory to store model weights, intermediate calculations, and the attention cache.
An ESP32-C3 doesn't have anything close to the memory needed to hold a 500M-parameter model.
The obvious solution would be to send requests to a PC or server and let it run the model.
But that wasn't what I wanted.
My goal was to perform the neural network computations on the ESP32 itself.
My Approach
I separated model storage from computation.
The PC acts as temporary storage for model weights and other required model data.
The ESP32 receives the data it needs, processes the transformer operations, and keeps its working state on the device.
The PC does not perform the neural network inference calculations.
The architecture looks like this:
PC
Model Weight Storage
|
| Stream weights
v
ESP32-C3
Transformer Compute
Activations / KV Cache
|
v
Token Selection
This approach trades memory requirements for a major increase in data transfers and execution time.
It doesn't make the hardware powerful. It makes a much larger model possible to evaluate within the device's limited memory.
Quantization Experiments
I also benchmarked different integer representations on the ESP32-C3.
For a vector size of 256 and 10,000 iterations, I recorded:
| Format | Execution Time |
|---|---|
| INT8 | 273,440 µs |
| INT4 | 530,232 µs |
| INT2 | 546,245 µs |
INT8 was the fastest in this specific test.
Lower bit widths reduce storage requirements, but they don't automatically make computation faster. Unpacking smaller representations can introduce additional work.
These are microbenchmarks, not full-model inference timings.
Running the Transformer
After validating smaller components, I progressively tested larger parts of the model.
The experiments included individual transformer layers, multiple token positions, and eventually processing a four-token prompt through all 24 transformer layers.
I compared intermediate results against an independent reference implementation to check numerical correctness.
In a verified run, the ESP32 completed the transformer processing and selected a next-token ID.
That was the main milestone: the microcontroller was performing real pretrained-model computations, rather than calling an LLM running somewhere else.
The Performance Problem
The biggest limitation was speed.
Streaming large quantities of model weights to a small device creates substantial overhead.
I worked on reducing that overhead and optimizing parts of the execution pipeline.
One partial benchmark improved from approximately 167 seconds to 19 seconds, an 8.64× speedup.
That improvement was specific to the measured workload, not the total time required to generate a response.
Complete inference remained very slow.
What This Does and Doesn't Prove
The experiment demonstrates that a tiny microcontroller can execute substantial parts of a pretrained language model when its weights are supplied from external storage.
But there are important limitations.
- The ESP32 does not store the complete model locally.
- The PC is still required as a source of model data.
- Inference is extremely slow compared with conventional hardware.
- The verified milestone is device-side transformer computation and token selection, not practical real-time conversation.
- This does not yet demonstrate a fully standalone multi-token chatbot.
Those distinctions matter. I wanted to prove what the hardware actually executed, not imply a level of performance it hadn't reached.
What I Learned
This project changed how I think about running AI on constrained hardware.
The key challenges weren't just implementing matrix multiplication or attention.
They included memory management, streaming, numerical verification, quantization, and finding performance bottlenecks.
The experiment also reinforced something I've learned from other AI engineering projects:
A system should be judged by what can be independently verified, not just by whether a demo appears to work.
I plan to keep that principle at the center of my future experiments.
Read the full article here:
Running a 500M-Parameter LLM on an ESP32-C3
About the Author
I'm Borjan Ladinski, an AI Engineer, AI Expert, and AI Consultant based in Skopje, North Macedonia.
I specialize in AI agents, LLM applications, RAG systems, machine learning, and business automation. My work includes production AI systems, original retrieval benchmarks, and experimental AI inference on microcontrollers.
I'm available for AI consulting, custom AI solutions, and engineering projects.
Top comments (4)
The INT8 result is the part that surprised me most — 273,440 µs beating both INT4 and INT2 is a good reminder that lower bit widths save storage without automatically speeding up computation. I also appreciated the honesty about what the milestone actually is: verified transformer computation and next-token selection on the chip, not a standalone chatbot. The 167s → 19s partial-benchmark improvement makes me curious how much of that overhead was weight streaming versus the compute itself — did one dominate?
Separating weights from compute is the only way 400 KB of SRAM can touch a 500M parameter model. What matters here is the per-layer latency on a 160 MHz core and where the attention cache spills. How many tokens per second did the ESP32 actually produce, and did quantisation change the output on the same prompt?
The honesty here is what makes it land — you don't claim a standalone chatbot, you claim a verified next-token ID from real transformer computation on a 160 MHz chip with 400 KB of SRAM, with the PC only streaming weights. The INT8 result surprised me too: 273,440 µs versus 530,232 for INT4 and 546,245 for INT2 — lower bits shrink storage but don't automatically speed up the math, and your microbenchmark says that plainly. And the 167s to 19s speedup is a good reminder that the bottleneck was streaming and pipeline overhead, not the transformer itself. What would it take to get from one verified token to a slow but real multi-token reply — is the next wall streaming, memory, or just patience?
Doing the actual transformer math on the chip instead of offloading is the fun constraint. With about 400 KB of SRAM the weights have to stream in piece by piece. What did a token cost in the end, and was flash read speed or compute the bottleneck?