How dimitricl/micro-llm-2bit works
This repository builds and evaluates a compact ternary-weight language model for low-memory CPU inference. The main workflow prepares a reduced vocabulary and batches, distills a Hugging Face teacher into a student, exports a packed model, then generates text through a memory-mapped inference engine and C kernels. Additional branches prepare reasoning-trace data and evaluate exported models with fixed prompts or held-out perplexity. The graph includes documented capabilities whose implementation was not sampled; their links use README evidence, and uncertain internal wiring is omitted.
Main entry points: main.py Command dispatcher · engine.py CPU inference engine · distill.py Distillation trainer · ternary.h Kernel interface
Components 28
Data preparation
- Fetch Wikipedia
data_fetch/fetch_wiki.py - Generate traces
data_fetch/gen_think.py - Clean traces
data_fetch/clean_think.py - Build slices
data_fetch/make_slices.py - Prepare country data
data_clean/make_monde_fr.py - Vocabulary and batches
data.py
Training and export
- Command dispatcher
main.py - Teacher logit cache
distill.py - Distillation trainer
distill.py - Ternary Transformer
model.py - Quantization and packing
quant.py - Training checkpoint
Inference runtime
- Packed model file
- CPU inference engine
engine.py - Kernel interface
kernels/ternary.h - NEON kernel
kernels/neon.c - AVX2 kernel
kernels/avx2.c - Portable kernel
kernels/portable.c - Generated text
Evaluation and tracking
- Fixed-prompt evaluation
tools/eval_fixed.py - Held-out PPL evaluation
tools/eval_ppl.py - Run plots
tools/plot_run.py - Run summary
tools/runs_table.py - Training benchmark
tools/bench_train.py
Other components
- CLI user
- Text corpora
- Ollama model
- Wikipedia source
Connections 32
- CLI user → Command dispatcher: runs commands
README.md - Wikipedia source → Fetch Wikipedia: provides source
- Fetch Wikipedia → Build slices: prepares slices
- Ollama model → Generate traces: generates responses
data_fetch/gen_think.py - Generate traces → Clean traces: cleans traces
data_fetch/clean_think.py - Text corpora → Vocabulary and batches: loads corpus
data.py - Prepare country data → Text corpora: produces text
- Build slices → Text corpora: produces slices
- Clean traces → Text corpora: produces traces
- Command dispatcher → Vocabulary and batches: prepares batches
main.py - Command dispatcher → Distillation trainer: starts training
README.md - Command dispatcher → Teacher logit cache: builds cache
README.md - Command dispatcher → Packed model file: exports model
README.md - Command dispatcher → CPU inference engine: runs inference
README.md - Distillation trainer → Ternary Transformer: trains student
distill.py - Ternary Transformer → Quantization and packing: quantizes weights
model.py - Distillation trainer → Teacher logit cache: reads logits
README.md - Distillation trainer → Training checkpoint: saves weights
- Packed model file → CPU inference engine: loads model
engine.py - CPU inference engine → Kernel interface: calls matvec
README.md - Kernel interface → NEON kernel: defines interface
kernels/ternary.h - Kernel interface → AVX2 kernel: defines interface
kernels/ternary.h - Kernel interface → Portable kernel: defines interface
kernels/ternary.h - CPU inference engine → Generated text: generates tokens
README.md - Fixed-prompt evaluation → CPU inference engine: runs prompts
tools/eval_fixed.py - Held-out PPL evaluation → CPU inference engine: scores perplexity
tools/eval_ppl.py - Fixed-prompt evaluation → Vocabulary and batches: encodes prompts
tools/eval_fixed.py - Held-out PPL evaluation → Vocabulary and batches: loads evaluation data
tools/eval_ppl.py - Run summary → Run plots: references plots
tools/runs_table.py - CLI user → Fixed-prompt evaluation: requests evaluation
README.md - CLI user → Held-out PPL evaluation: requests evaluation
README.md - CLI user → Training benchmark: benchmarks training
README.md