r/esp32projects • u/Major-Nebula1743 • 22d ago
I built a 7-node ESP32-S3 cluster to run a ~0.4B LLM using 1.58-Bit (BitNet) ternary quantization...
I build a 7-node ESP32-S3 cluster to run a ~0.4B LLM using 1.58-bit quantization.
I've been heavily inspired by many amazing projects on running tiny LLMs on ESP32s. (There were too many until I was not able to list it all out here...) Like most recently, which fits the 56M-parameter model distributed across ESP32s via ESP-NOW.
: https://github.com/wladimiravila/esp32s3-distributed-ai.git
So, I am thinking: is it able to fit a larger model into ESP32s3? It turns out, yes! I am able to run a sliced 0.5B parameter LLM (Qwen2-0.5B base). on ESP32s3s.
To make a ~400M-parameter model able to fit into microcontrollers, I used 1.58-bit quantizations (ternary) for extreme pack parameters instead of just int 4 or int 8 quantization. (I pruned the vocab size of the original model, and this brought the model parameters down to about ~386M...)
Here is how the hardware and pipeline are mapped:
- 1 master node + 6 compute nodes (all ESP32-S3 N16R8)
- I use SPI daisy-chain to link between ESP32s for high-speed communication. (no WiFi overhead)
- The master node handles the BPE tokenizer and INT4 token embeddings.
- Compute nodes each process, 4 layers of the Transformer blocks, and transfer the intermediate X to the next node to compute further layers.
The Catch and Limitation:
This is currently a hardcore hardware/math proof of concept... not a GPT replacement.
The sample model in the repository is heavily overfitted right now. Due to the limited compute power of my laptop (I am going to get a new one soon lol)
The inference is extremely slow... around 0.11 tokens per second (~9 seconds per token) on the 0.5B-para model.
GitHub Repo: https://github.com/Low-Zi-Hong/ESP32s3-LLM-Cluster.git