Borjan Ladinski

Back to Articles

Running a 500M-Parameter LLM on an ESP32-C3

ESP32-C3 Super Mini microcontroller performing transformer inference using model weights streamed from a PC.
Running a 500M-Parameter LLM on an ESP32-C3

What happens when you try to run a language model with roughly 500 million parameters on a microcontroller that has only a few hundred kilobytes of RAM?

That's the question behind my ESP32-C3 LLM inference project.

The ESP32-C3 is a small, inexpensive RISC-V microcontroller designed for embedded applications, not large-scale machine learning. Even heavily quantized language models require far more storage than the device provides.

Instead of trying to fit an entire model into memory, I approached the problem differently: stream the model weights from an external computer while performing the neural computations on the ESP32-C3 itself.

The goal was to investigate how far an extremely memory-constrained device could go toward executing real transformer inference.

1. The Hardware Constraints

The experiment uses an ESP32-C3 Super Mini with the following hardware characteristics:

Component Specification
Microcontroller ESP32-C3
CPU Single-core RISC-V, up to 160 MHz
Flash 4 MB
Main internal SRAM Approximately 400 KB class
External PSRAM None
Wireless Wi-Fi and Bluetooth LE
Development framework ESP-IDF

A model containing 500 million parameters needs approximately:

Weight precision Approximate raw storage
FP32 2 GB
FP16 / BF16 1 GB
INT8 500 MB
INT4 250 MB
INT2 125 MB

These figures represent raw weight storage estimates, excluding quantization metadata, runtime state, and other overhead.

Even at two bits per parameter, the weights are vastly larger than the microcontroller's available memory.

The challenge isn't simply loading a model. It is finding a way to execute its computations when the full weight matrices cannot remain in RAM.

2. The Architecture: Streaming Weights, Computing Locally

My solution separates model storage from model computation.

The PC serves as a temporary source of model weights. It transfers the required data to the ESP32-C3 in manageable pieces.

The ESP32-C3 performs the transformer computations using those streamed weights.

Conceptually, the architecture is:

           External Computer
         Model Weight Storage
                  |
                  |
           Weight Streaming
                  |
                  v
              ESP32-C3
       -----------------------
       Transformer Computation
       Quantized Matrix Math
       Activations / KV State
       Token Selection
       -----------------------
                  |
                  v
             Token Output

The important distinction is that the PC is not being used as a remote inference processor.

The intended division of responsibility is:

  • The PC stores and supplies model weights.
  • The ESP32-C3 performs neural-network arithmetic.
  • The ESP32-C3 manages the working inference state within its memory constraints.
  • The device is responsible for producing the selected token.

This is PC-assisted, device-computed inference, not fully standalone inference.

The external connection is a significant limitation, but it allows the experiments to focus on the central question: can the microcontroller execute the model's computations correctly?

3. Quantization on a Small RISC-V Processor

Quantization is essential for reducing the amount of data that must be transferred and processed.

I benchmarked integer multiply-accumulate workloads using INT8, INT4, and INT2 representations.

The benchmark used vectors of length 256 over 10,000 iterations.

Integer Arithmetic Benchmark

Precision Execution time Throughput
INT8 273,440 µs 9.36 million MAC/s
INT4 530,232 µs 4.83 million MAC/s
INT2 546,245 µs 4.69 million MAC/s

An interesting result was that the lower-bit representations were not automatically faster.

In this benchmark, INT8 achieved the highest throughput.

Why?

Lower numerical precision reduces storage requirements, but it can introduce unpacking overhead and additional bitwise operations. On hardware without specialized low-bit matrix instructions, the extra processing can outweigh the benefits of transferring fewer bytes.

This illustrates an important embedded ML trade-off:

Smaller weights do not necessarily mean faster computation.

The best representation depends on the architecture, arithmetic implementation, memory bandwidth, and cost of decoding packed values.

These numbers are microbenchmark results, not end-to-end language-model throughput.

4. Executing Transformer Layers

After establishing the arithmetic primitives, I moved toward transformer-layer execution.

The implementation processes the model's major linear transformations, including:

  • Query, key, and value projections
  • Attention output projection
  • Feed-forward gate projection
  • Feed-forward up projection
  • Feed-forward down projection

These operations are executed as part of the device-driven inference pipeline.

Rather than allocating complete large matrices, the implementation works with streamed weight data and constrained intermediate buffers.

The objective is to keep memory usage within the device's capabilities while preserving numerical correctness.

Numerical Verification

Correctness matters as much as execution.

For one of the verification stages, independent checks reported:

Checked values: 896
Failures:       0
Maximum absolute difference: ~1e-5

This result supported the numerical consistency of the tested implementation against its reference calculations.

It does not prove that every possible prompt, sequence length, or execution path has been validated.

5. Moving from Layers to Token Selection

Executing individual matrix operations is only part of the problem.

For useful language-model inference, the device must execute the complete transformer computation, evaluate the output representation, and select a token.

A later experiment progressed to a 24-layer prefill sequence across four input positions.

The implementation completed those positions and performed a device-driven BF16 output-head calculation.

In two recorded runs, the ESP32-C3 selected token IDs:

Run 1: 198
Run 2: 12095

The output-head verification also recorded a numerical difference on the order of 1e-5 in its comparison.

These experiments represent meaningful progress toward end-to-end inference because token selection was performed on the device rather than simply returned by the PC.

However, there is an important limitation.

A selected token ID is not the same as a demonstrated working multi-token text-generation system.

At this stage, the verified work included the transformer execution path, streamed weight processing, output-head evaluation, and device-selected tokens.

Reliable multi-token generation remained a further integration and validation objective.

6. Performance: Where the Time Goes

Memory capacity was not the only challenge.

Streaming large quantities of weight data and performing transformer operations on a 160 MHz microcontroller makes execution expensive.

In a partial benchmark, optimization reduced execution time from approximately 167 seconds to 19 seconds.

That represents an improvement of approximately 8.64× for the measured workload.

It is important to describe this correctly.

The 8.64× improvement applies to the optimized benchmark stage. It does not mean that full language-model inference became 8.64× faster or that the system can generate tokens in 19 seconds.

The later multi-layer prefill experiments still required substantially longer execution times, measured in thousands of seconds.

This distinction matters when evaluating embedded inference performance.

A fast isolated kernel does not automatically translate into fast complete-model inference.

End-to-end performance depends on:

  • Weight streaming and communication overhead
  • Matrix computation
  • Attention operations
  • Memory allocation and reuse
  • Output-head processing
  • The number of transformer layers
  • The number of input and generated tokens

Understanding these costs is essential before making claims about practical inference speed.

7. What Worked and What Remains Difficult

The experiments established several useful findings.

What Worked

Device-side computation

The ESP32-C3 executed meaningful transformer workloads using streamed model weights.

Numerical verification

Independent reference comparisons helped confirm the correctness of tested arithmetic paths.

Memory-constrained execution

The implementation progressed without requiring the full model to reside in microcontroller RAM.

Output token selection

The device completed output-head processing and selected token IDs in recorded experiments.

Performance optimization

A measured partial workload improved by approximately 8.64×.

Remaining Limitations

External weight storage

The current experiment depends on a connected PC to provide model weights.

Long execution times

The complete inference pipeline is far slower than modern CPU or GPU inference.

Multi-token text generation

The recorded token-selection experiments should not be confused with a fully validated interactive generation system.

Limited evaluation scope

The available checks demonstrate correctness for specific workloads, not comprehensive language-model quality or reliability.

No standalone deployment

The project has not demonstrated complete inference using only microcontroller-attached storage.

These limitations are part of the engineering result, not details to hide.

8. What This Experiment Demonstrates

The purpose of this project is not to suggest that an ESP32-C3 is a practical replacement for a GPU.

It is an investigation into how inference systems can be designed when memory constraints are extreme.

The experiment highlights several broader engineering ideas:

  1. Model storage and neural computation do not necessarily have to happen on the same device.
  2. Weight streaming can make workloads executable even when the complete model cannot fit into available RAM.
  3. Aggressive quantization involves trade-offs between storage, decoding overhead, and arithmetic throughput.
  4. Independent numerical verification is essential when implementing low-level inference engines.
  5. Achieving a correct computation path and achieving practical performance are separate engineering milestones.

These principles extend beyond the ESP32-C3 to other constrained embedded systems and specialized inference architectures.

9. Conclusion

Running computations from a roughly 500-million-parameter language model on an ESP32-C3 is an unusual exercise in engineering under constraints.

The model's weights are far too large for the device's memory, yet streaming them in manageable pieces enabled meaningful transformer computation on the microcontroller.

The project progressed from low-bit integer arithmetic benchmarks to transformer-layer verification, multi-position prefill, and device-driven token selection.

It also exposed the limitations of this approach: streaming overhead, long execution times, and the additional work required for validated multi-token generation.

For me, the most interesting result is not that a microcontroller can compete with conventional inference hardware.

It's that carefully separating storage, computation, and working memory can make otherwise impossible workloads technically executable.

That is the engineering question I wanted to explore.


Author: Borjan Ladinski

AI Engineer working with Python, machine learning, AI agents, retrieval systems, and experimental inference architectures.