cognisoc / zigllm
Answers in the margin

Frequently asked questions

The short answers. For the long ones, the curriculum and the code are the real documentation.

What is zigllm?

zigllm is an educational, inference-only implementation of large language models written from scratch in Zig. It is structured like a textbook — six progressive layers from tensors up to a generation loop — and is meant for reading and learning rather than production deployment.

Is zigllm production-ready?

No. zigllm is a pedagogical project and is inference-only. Educational clarity takes priority over raw speed; it is not intended to replace a production runtime like llama.cpp. Use it to understand how transformers work, then apply that understanding wherever you like.

Do I need to know Zig already?

It helps, but the project is written to be read. If you can follow C-family code and are comfortable learning as you go, the chapters and the 285+ tests will teach you the Zig you need — comptime generics, SIMD, and manual memory management included.

Do I need a GPU?

No. zigllm runs on CPU using SIMD (@Vector) kernels. A modern CPU with AVX/AVX2 is recommended for the fast paths but is not required.

Which architectures does it implement?

Eighteen transformer families, including LLaMA, Mistral, Qwen, Phi, GPT-2, GPT-J, GPT-NeoX, Falcon, BLOOM, StarCoder, Gemma, BERT, Mamba, MoE, and multimodal variants. See the architectures page for what distinguishes each.

Can it load real pre-trained models?

Yes. zigllm supports memory-mapped GGUF loading compatible with the llama.cpp ecosystem, so you can read a real quantized model from disk, decode its tensors, and run a forward pass.

Is it free and open source?

Yes. zigllm is released under the MIT license. Contributions that improve educational value — clearer explanations, more tests, new architectures — are especially welcome.

How is it different from nanoGPT or llm.c?

They are complementary readings. nanoGPT is a compact PyTorch training/inference example; llm.c is a lean C implementation focused on GPT-2 training. zigllm is inference-only, spans 18 architecture families across six explicitly layered chapters, and leans on Zig’s comptime and SIMD to keep the math legible. Read them side by side — see the Compare page.