Skip to content
HardwareLab

ESP32 LLM

Proof that a language model can run on an ESP32: a 260K-parameter TinyLlamas model trained on TinyStories generating text at about 19 tokens per second.

Hardware:
ESP32-S3 with PSRAM
Difficulty:
Advanced
Creator:
DaveBben

A real LLM running on an ESP32.

ESP32 LLM
No photo in the source; GitHub repository card, served from HardwareLab.

By DaveBben

Posted

What it does

Proof that a language model can run on an ESP32: a 260K-parameter TinyLlamas model trained on TinyStories generating text at about 19 tokens per second.

What you need

Difficulty
Advanced
License
No license stated

Parts

  • ESP32-S3FH4R2 (2MB of embedded PSRAM) [not stated]
AI model or service
llama2.c tiny model

Prices, notes and sources: Parts and requirements

Parts and requirements

PartSpec / notesNeededPrice
ESP32-S3FH4R2 2MB of embedded PSRAMNot stated

Full build guide

Steps

Difficulty
Advanced
  1. Install the ESP-IDF toolchain.
  2. Build with idf.py build.
  3. Flash with idf.py -p /dev/{DEVICE_PORT} flash.

Full instructions: View original

How it works

It uses llama2.c on an ESP32-S3FH4R2, whose 2 MB of PSRAM fits the roughly 1 MB model. Speed-ups include using both cores, ESP-DSP SIMD dot-product functions, a 240 MHz CPU and 80 MHz PSRAM, and a larger instruction cache. It builds with the ESP-IDF toolchain.

Limits and caveats

  • The 260K parameter tinyllamas checkpoint still requires 1MB of RAM.

Like this build? Get the weekly builds

Every Thursday: the 5 best gadget hacks you can copy. Free.

Built something? Submit a build

Why it's interesting

This is the earlier, smaller proof that an LLM can run on an ESP32 at all, and the author is candid that it is probably not very useful. The model is a 260K-parameter tinyllamas checkpoint trained on TinyStories, run with llama2.c. Even that needs about 1 MB of RAM, so the build uses an ESP32-S3FH4R2 for its 2 MB of embedded PSRAM. The README lists the optimizations that reach 19.13 tokens per second: using both cores for the heavy math, using ESP-DSP dot-product functions that take advantage of the S3's few SIMD instructions, and pushing the CPU to 240 MHz and PSRAM to 80 MHz with a larger instruction cache. Building requires the ESP-IDF toolchain. The 28.9M-parameter ESP32-S3 LLM on HardwareLab goes much further.

Source: github.com/DaveBben/esp32-llm#readme

Hardware

  • ESP32-S3 with PSRAM

More ESP32 builds

This page is a short summary written by HardwareLab. Build steps, code and photos belong to the creator; follow “View original” for the full project.

Featured? Add this badge

Built this? Paste the badge into your README. It links back to this page.

Featured on HardwareLab

Markdown

[![Featured on HardwareLab](https://hardwarelab.dev/badge.svg)](https://hardwarelab.dev/projects/esp32-llm/?utm_source=badge&utm_medium=referral&utm_campaign=launch_2w)

HTML

<a href="https://hardwarelab.dev/projects/esp32-llm/?utm_source=badge&utm_medium=referral&utm_campaign=launch_2w"><img src="https://hardwarelab.dev/badge.svg" alt="Featured on HardwareLab" width="188" height="20"></a>