This project implements a cutting-edge distributed AI system that efficiently runs a 56M-parameter language model across three ESP32-S3 boards. By utilizing ESP-NOW for seamless communication, it provides a fully offline solution for advanced inference capabilities, making distributed processing accessible and efficient.
ESP32-S3 Distributed AI is a cutting-edge project designed to facilitate distributed micro-LLM inference using three ESP32-S3 N16R8 boards via ESP-NOW communication.
This project implements a distributed AI system that effectively runs a 56M-parameter language model across three ESP32-S3 microcontrollers. Building on the work of slvDev/esp32-ai, which showcased the execution of TinyStories on a single board, this initiative extends the architecture to a multi-board distributed system featuring web-based interaction.
The language model, trained on the WikiText-103 corpus (Wikipedia), utilizes Per-Layer Embeddings (PLE) from Google's Gemma architecture, quantized to 4-bit. The architecture is optimized to split the 50.3M-parameter PLE table across three boards that communicate wirelessly via the ESP-NOW protocol. Board B utilizes a KV cache in PSRAM, allowing the transformer to maintain awareness of the complete generated sequence instead of processing token-by-token.
The system architecture consists of three primary components:
┌───────────────────┐ ESP-NOW ┌───────────────────┐ ESP-NOW ┌───────────────────┐
│ Board A │ ◄──────────────► │ Board B │ ◄──────────────► │ Board C │
│ Embeddings + │ │ Core + KV Cache │ │ PLE_A + Decoder │
│ PLE_Proj + Head │ │ │ │ + WiFi │
│ │ │ │ │ │
│ • BPE Tokenizer │ │ • 6 Attn layers │ │ • PLE table A │
│ • tok_emb 8-bit │ │ • 6 FFN layers │ │ (12.5 MB) │
│ • ple_model_proj │ │ • KV Cache (128) │ │ • Sampling │
│ • out_norm + head │ │ • PLE_B (half) │ │ • Web Server │
│ │ │ • PLE Gating │ │ • Space heuristic │
│ Flash: 4.31 MB │ │ Flash: 13.71 MB │ │ Flash: 13.37 MB │
└───────────────────┘ └───────────────────┘ └───────────────────┘
The end-to-end inference flow is as follows:
Browser ──WiFi──► Board C ──ESP-NOW──► Board A ──ESP-NOW──► Board B
◄─────────────── ◄──────────────
The PLE table is divided between the boards to optimize memory usage:
This innovative approach features a KV cache in PSRAM (1.5 MB for 256 positions) on Board B, significantly enhancing the model's ability to maintain coherence across generated sequences. This solution addresses historical constraints of autoregressive models by allowing proper position-aware attention during inference.
The repository includes comprehensive code and data for both the training pipeline and ESP32-S3 firmware, including:
This system utilizes a Tiny decoder-only transformer architecture with the following specifications:
The model achieved impressive metrics during training, including:
Future improvements include optimization of the BPE tokenizer implementation, enhancements to the web UI, and power optimizations among others.
The ESP32-S3 Distributed AI project exemplifies a significant advancement in distributed machine learning on microcontrollers, effectively showcasing the potential of low-power devices in sophisticated AI applications.
No comments yet.
Sign in to be the first to comment.