How marcelpetrick/esp32-tiny-llm works
ESP32-Tiny-LLM trains a greenhouse-focused decoder model, exports it for a portable C inference runtime, then serves conversations through a desktop CLI, web simulator, or ESP32 firmware. The runtime builds prompts, generates replies, retrieves device facts, and parses and validates proposed actions before simulated device state changes. Training also includes rule-based dialogue generation, optional local-LLM paraphrases, tokenizer and model training, export, and evaluation. Some runtime and training internals are unsampled; their links below rely on the README’s documented workflow and capabilities.
Main entry points: console.c Prompt and action console · dialogue.py Dialogue generation · transformer.c Transformer inference · train.py Training loop
Components 27
Model training
- Dialogue generation
training/data/dialogue.py - LLM paraphrase teacher
training/data/teacher.py - Dataset builder
training/data/dataset.py - Tokenizer training
training/tokenizer/bpe.py - Transformer training
training/model.py - Training loop
training/train.py - Model export
training/export.py - Model evaluation
training/eval.py
Greenhouse domain
- Device rules
training/world/actions.py - Fault diagnosis
training/world/diagnose.py - Device facts
training/world/facts.py - Greenhouse state
training/world/state.py
C inference runtime
- Model loader
runtime/src/model_loader.c - Tokenizer runtime
runtime/src/tokenizer.c - Transformer inference
runtime/src/transformer.c - Inference kernels
runtime/src/kernels.c - Token sampler
runtime/src/sampler.c - Prompt and action console
runtime/src/console.c - Action validation
runtime/src/device.c - Fact retrieval
runtime/src/facts.c - Host API
runtime/src/host.c
Product interfaces
- Desktop CLI
runtime/cli/main.c - Python runtime binding
tools/runtime.py - Web simulator
web/server.py - Browser UI
web/static/app.js - ESP32 firmware
firmware/main/app_main.c
Other components
- User
Connections 29
- LLM paraphrase teacher → Dialogue generation: provides paraphrases
training/data/dialogue.py - Device rules → Dialogue generation: supplies semantics
training/data/dialogue.py - Fault diagnosis → Dialogue generation: supplies diagnoses
training/data/dialogue.py - Device facts → Dialogue generation: supplies facts
training/data/dialogue.py - Dialogue generation → Dataset builder: generates samples
training/data/dataset.py - Dataset builder → Tokenizer training: builds vocabulary
training/data/dataset.py - Dataset builder → Training loop: provides training data
- Tokenizer training → Transformer training: encodes text
- Transformer training → Training loop: trained by
training/train.py - Training loop → Model export: exports weights
- Model export → Model loader: loads exported model
- Training loop → Model evaluation: evaluates model
training/eval.py - Model loader → Transformer inference: provides model
- Transformer inference → Inference kernels: runs operations
runtime/src/transformer.c - Transformer inference → Tokenizer runtime: uses tokenizer
runtime/src/transformer.c - Transformer inference → Token sampler: produces logits
- Token sampler → Prompt and action console: returns sampled tokens
- Prompt and action console → Action validation: validates actions
- Prompt and action console → Fact retrieval: retrieves prompt facts
runtime/src/console.c - Prompt and action console → Action validation: applies approved actions
runtime/src/console.c - Desktop CLI → Host API: opens and submits
runtime/cli/main.c - Host API → Prompt and action console: serves console API
- Python runtime binding → Host API: calls host API
tools/runtime.py - Web simulator → Python runtime binding: creates runtimes
web/server.py - Browser UI → Web simulator: uses web API
- ESP32 firmware → Prompt and action console: serves serial console
firmware/main/app_main.c - User → Desktop CLI: enters commands
- User → Browser UI: sends chat
- User → ESP32 firmware: sends serial input