Running Modern SLMs (Gemma 4, Qwen 3 & Phi-4) on CPU: Pure Rust, Zero Python A developer built a pure-Rust, Python-free CLI engine using Hugging Face's Candle framework that runs quantized GGUF versions of Google's Gemma 4 (E4B), Alibaba's Qwen 3 (4B), and Microsoft's Phi-4-mini (3.8B) on standard CPUs. The tool switches between model families from the terminal, auto-selecting the right Hugging Face repo, GGUF file, and chat template (ChatML, Gemma, or Phi), and reports benchmarks on RAM usage, cold-start latency, and token generation speed. The developer argues CPU inference in Rust is now a viable production architecture for edge devices, IoT gateways, and low-cost cloud instances. When I first shared my experiment on running Microsoft’s Phi-3 on a standard consumer CPU using pure Rust and Hugging Face’s Candle framework, the mission was straightforward: prove that we don’t need bloated Python runtimes, complex CUDA setups, or 5GB+ Docker images just to run local AI inference. Fast forward to today, and the Small Language Model SLM landscape has exploded. With the release of edge-optimized powerhouses like Google’s Gemma 4 E4B , Alibaba’s Qwen 3 / 3.6 4B , and Microsoft’s Phi-4-mini 3.8B , running high-reasoning AI directly on standard CPU hardware is no longer just a weekend hack—it is a viable production architecture. In this guide, we will upgrade our pure-Rust inference pipeline to build a multi-model CLI engine capable of running the latest quantized GGUF models on a standard CPU, complete with real-world benchmarks on RAM usage, cold-start latency, and token generation speeds. Why go through the trouble of writing inference code in Rust when Python has transformers and vLLM ? When deploying to edge devices, IoT gateways, or cost-effective CPU cloud instances, runtime overhead matters. Instead of locking our code to a single model, we are testing three of the strongest compact models currently dominating local AI: Let’s write a unified Rust CLI tool that lets you switch between Phi-4 , Qwen , and Gemma models straight from the terminal, leveraging candle-transformers and hf-hub . Cargo.toml Create a new project cargo new rust-slm-bench and configure your Cargo.toml : package name = "rust-slm-bench" version = "0.2.0" edition = "2021" dependencies anyhow = "1.0" candle-core = "0.8" candle-nn = "0.8" candle-transformers = "0.8" hf-hub = { version = "0.3", features = "tokio" } tokenizers = "0.20" clap = { version = "4.5", features = "derive", "ValueEnum" } src/main.rs Below is the clean, streaming implementation. We define an enum for our model families so our engine automatically selects the right Hugging Face repository, GGUF file, and Chat Template ChatML vs. Gemma vs. Phi : use anyhow::{Error as E, Result}; use candle core::quantized::gguf file; use candle core::{Device, Tensor}; use candle transformers::generation::LogitsProcessor; use candle transformers::models::quantized llama::ModelWeights as LlamaStyleModel; use candle transformers::models::quantized phi3::ModelWeights as PhiStyleModel; use candle transformers::models::quantized qwen2::ModelWeights as QwenStyleModel; use clap::{Parser, ValueEnum}; use hf hub::api::sync::Api; use std::io::Write; use tokenizers::Tokenizer; derive Debug, Clone, ValueEnum enum ModelFamily { Phi4, Qwen3, Gemma4, } enum LoadedModel { Phi PhiStyleModel , Qwen QwenStyleModel , Gemma LlamaStyleModel , } impl LoadedModel { fn forward &mut self, x: &Tensor, index pos: usize - candle core::Result