A from-scratch Llama 3.2 inference engine, written in pure MLX for Apple Silicon.
Named after the lancer โ the mounted knight who charged the lists at the joust โ because this engine drives the model forward, token by token.
The full forward pass is implemented by hand, no transformers model class:
tokenizer.pyโ encoding/decoding and input embedding lookupattention.pyโ Grouped-Query Attention with Llama 3 RoPE frequency scalingMultiLayerPerceptron.pyโ the SwiGLU MLP blockmain.pyโ the inference loop: RMSNorm โ attention โ MLP across all 16 layers, then greedy decoding
- Apple Silicon Mac
- Python 3.14+
mlx,transformers
The Llama 3.2 weights are not included in this repo (~4.6 GB). Download them from
Hugging Face into a llama3.2/ directory at the repo root:
llama3.2/snapshots/<snapshot-hash>/model.safetensors
python main.py