The project explores running the stories15M language model on an ESP32-S3 microcontroller. The model contains 15.2 million parameters and requires reading weights from flash memory due to limited SRAM and PSRAM capacity. The primary bottleneck is the SPI bus speed, which limits data transfer to approximately 31.5 MB/s.
To optimize performance, the author implemented several techniques including dictionary pruning, reducing the vocabulary size to 6144 tokens, and 4-bit quantization. Using GPTQ and specific grouping strategies allowed the model to maintain quality while significantly reducing the memory footprint. These optimizations resulted in a total compression cost of 5.2% in bits per byte.
The implementation utilizes custom SIMD instructions to process 4-bit weights without explicit unpacking, which was a major performance hurdle. By leveraging the ESP32-S3's PIE instructions and optimizing cache settings, the generation speed reached 5.59 tokens per second. Additional gains were achieved by pinning the engine to IRAM and utilizing both processor cores.
The project highlights the constraints of using flash memory as the primary storage for model weights. By adjusting cache line sizes and employing hardware prefetching, the system maximizes the available bus bandwidth. The final configuration demonstrates that even with limited hardware, efficient memory management and quantization can enable LLM execution on microcontrollers.



