This tutorial walks you through loading a BitNet GGUF model and generating your first tokens. It assumes you have completed the Getting Started guide and have a model downloaded.
Time: ~5 minutes
Prerequisites: Rust toolchain, model downloaded to models/
cargo run -p bitnet-cli --no-default-features --features cpu,full-cli -- \
compat-check models/microsoft-bitnet-b1.58-2B-4T-gguf/ggml-model-i2_s.ggufExpected output includes ✓ format, ✓ quantization, ✓ vocab_size.
RUST_LOG=warn \
cargo run -p bitnet-cli --no-default-features --features cpu,full-cli -- run \
--model models/microsoft-bitnet-b1.58-2B-4T-gguf/ggml-model-i2_s.gguf \
--tokenizer models/microsoft-bitnet-b1.58-2B-4T-gguf/tokenizer.json \
--prompt "What is 2+2?" \
--max-tokens 8 \
--temperature 0.0 --greedyRUST_LOG=warn suppresses verbose debug output so you only see the generated text.
The CLI:
- Loaded the GGUF — memory-mapped the model file; parsed metadata and tensor data.
- Auto-detected the tokenizer — found
tokenizer.jsonalongside the model. - Selected the backend — chose CPU with SIMD acceleration based on available features.
- Applied the prompt template — wrapped your prompt with the instruct template (
Q: ... A:). - Generated tokens — ran the autoregressive decode loop with greedy sampling.
The startup log (visible with RUST_LOG=info) shows:
INFO backend selected backend_selection=requested=auto detected=[cpu-rust] selected=cpu-rust
INFO loaded model tensors=xxx vocab=32000 layers=18
# Creative with temperature (stochastic):
RUST_LOG=warn cargo run -p bitnet-cli ... run \
--prompt "Write a haiku about Rust" \
--max-tokens 32 \
--temperature 0.8 --top-p 0.95
# Deterministic with seed (reproducible):
RUST_LOG=warn cargo run -p bitnet-cli ... run \
--prompt "What is 2+2?" \
--max-tokens 4 \
--temperature 0.0 --greedy --seed 42RUST_LOG=warn \
cargo run -p bitnet-cli --no-default-features --features cpu,full-cli -- chat \
--model models/microsoft-bitnet-b1.58-2B-4T-gguf/ggml-model-i2_s.gguf \
--tokenizer models/microsoft-bitnet-b1.58-2B-4T-gguf/tokenizer.jsonType your question, press Enter. Commands: /help, /clear, /metrics, /exit.
The QK256 scalar kernels run at ~0.1 tok/s on 2B models. For quick validation, use --max-tokens 4-16. For faster inference, use the BitNet32-F16 format:
# Check if BitNet32 format is available:
ls models/microsoft-bitnet-b1.58-2B-4T-gguf/
# Look for a non-i2_s.gguf fileSee How-to: use-qk256-models for details on format differences.
- How-to: validate-models — inspect and validate model quality
- How-to: cross-validate — compare Rust vs C++ numeric parity
- Explanation: quantization formats — understand I2_S/QK256
- Reference: CLI — full flag reference