DEV Community

Borjan Ladinski
Borjan Ladinski

Posted on Originally published at borjan.ladinski.com

I Ran a 500M-Parameter LLM on an ESP32-C3 Microcontroller

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
Enter fullscreen mode Exit fullscreen mode

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.

Explore my AI projects and consulting work

Top comments (8)

Collapse
 
iictp profile image
IICTP •

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?

Collapse
 
borjanladinski profile image
Borjan Ladinski •

Thanks! I didn't measure weight streaming and computation separately in that benchmark, so I can't give an exact breakdown. The 167s → 19s improvement was for a partial benchmark, not full inference. Weight streaming is a major bottleneck in the full model since the ESP32 has to receive the weights while doing all the computation locally. Separating the two timings is something I'd like to benchmark next.

Collapse
 
analista_83 profile image
Sammi De Blas •

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?

Collapse
 
borjanladinski profile image
Borjan Ladinski •

The full run took 4,164 seconds to process 4 input tokens and generate 1 output token. That's roughly 0.00024 tokens/sec end to end, not a steady-state generation benchmark.

The KV cache stayed entirely on the ESP32, so there was no cache spilling to the PC. Only model weights and embeddings were streamed.

For quantization, INT8 produced the same next token (" Paris") as the original floating point model on the tested prompt. I haven't verified whether this holds across other prompts.

Collapse
 
gautamtalksdev profile image
Gautam K •

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?

Collapse
 
borjanladinski profile image
Borjan Ladinski •

The final verified run took about 69 minutes to process a 4-token prompt and generate one token using all 24 transformer layers. The ESP32 generated “Paris” from “Capital of France:”.

The weights were streamed over USB from the PC, not read from flash. I haven't measured streaming and compute time separately, so I can't say which dominated. That's something I'd like to benchmark next.

Collapse
 
userxnom profile image
Abdullah Naseer •

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?

Collapse
 
borjanladinski profile image
Borjan Ladinski •

The next step is to loop the inference process: take the selected token, feed it back into the model, update the KV cache on the ESP32, and repeat.

I think streaming will remain the biggest bottleneck, since the model weights still need to pass through the device for each generated token. Memory is also tight, especially as the KV cache grows.

So multi-token generation is the next milestone. Speed is a separate problem, and even a few generated tokens would be a useful proof of concept.