cd /news/artificial-intelligence/tiny-inference-engine-in-pure-rust-c… · home topics artificial-intelligence article
[ARTICLE · art-70015] src=github.com ↗ pub= topic=artificial-intelligence verified=true sentiment=· neutral

Tiny inference engine in pure Rust, CPU-only, with TUI visualization

A developer released Tiny-Llama, a minimal LLaMA-style inference engine for MiniCPM5-1B written in pure Rust, featuring CPU-only inference and a TUI visualization that shows how the model processes prompts in real time. The single-file implementation at src/main.rs (~1800 lines) includes core components such as RoPE, multi-head attention with GQA, SwiGLU MLP, and RMSNorm, and is designed to help others study large language model fundamentals.

read1 min views1 publishedJul 23, 2026
Tiny inference engine in pure Rust, CPU-only, with TUI visualization
Image: source

A minimal LLaMA-style inference engine for MiniCPM5-1B, built purely in Rust.

I built this project to study the fundamentals of large language models. Every understanding is rephrased directly in the code — dense, but organized. My hope is that it helps you learn too.

Inspired by tiny-vllm.

CPU-only inference— no GPU required** No KV-cache**— focuses on the core model mechanics** Single-file implementation**—src/main.rs

(~1800 lines)TUI visualization— real-time view of how the model "thinks"

Component Details
Embedding Token ID lookup via embedding table
RoPE Rotary position embeddings
Attention Multi-head attention with GQA (Grouped Query Attention)
MLP SwiGLU activation function
Normalization RMSNorm
Residual connections Standard skip connections after attention and MLP
cargo run --release -- "<model_dir>" "<your prompt>"

Example:

cargo run --release -- ./models/minicpm5-1b "What is artificial intelligence?"

Press q

to quit early.

The best way to read this code is top-to-bottom in src/main.rs

:

Tensor ops— A minimalTinyTensor

wrapper over candle tensors with matrix multiply, reshape, transpose, softmax, etc. I will try to write the Maths operations by hand.**Model **—ModelConfigurations

,LlamaModel

, andTransformerBlock

structs that map directly to the safetensors keys.— The inference loop through every transformer layer. Each operation is annotated with shape comments and timing.predict_next_token

TUI— Ratatui widgets render attention maps, tensor shapes, and logits in real time.

MIT — see LICENSE

── more in #artificial-intelligence 4 stories · sorted by recency
── more on @minicpm5-1b 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/tiny-inference-engin…] indexed:0 read:1min 2026-07-23 ·