Skip to content

20.2 Inference Frameworks: The Cross-Language Landscape

Once you know how a model is served in principle, the practical question is where you run it. The answer depends on far more than raw speed. A datacenter serving millions of requests, a laptop running a model offline, a browser tab, and an embedded device each want something different, and the inference ecosystem has split along language lines to serve them: a C/C++ foundation (llama.cpp and ggml), a Python serving tier (vLLM, TGI, SGLang, TensorRT-LLM), a set of Rust equivalents (candle, mistral.rs, burn, ratchet, luminal), and an emerging Zig stack (ZML, llama.cpp.zig).

Concepts from other sections (12)

This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.

  • static binary: an executable that needs no C library at run time, produced by Go with CGO_ENABLED=0. Read more: 10.2 Dockerfiles for the gateway and the engine in Systems Engineering
  • KV cache: the stored keys and values of all processed tokens, per layer, that let each new token attend without recomputation. Read more: Chapter 20: Inference Engines and GPU Deployment
  • continuous batching: token-level scheduling that admits and evicts sequences every step to keep the GPU full. Read more: Chapter 20: Inference Engines and GPU Deployment
  • inference engine: software that loads weights, schedules requests, manages the KV cache, and generates tokens (vLLM, SGLang, TensorRT-LLM, llama.cpp). Read more: 20.5 LLM Serving Platforms: How They Work and When to Use Them
  • Computation graph: a graph with one node per value and an edge from each value to the values it was computed from. Read more: 12.1 Graphs, DAGs, and an iterative topological sort in Mathematics
  • PagedAttention: KV-cache management in fixed-size blocks mapped through a block table, like virtual memory. Read more: Chapter 20: Inference Engines and GPU Deployment
  • safetensors: a weight format consisting of an 8-byte little-endian header length, a JSON header of tensor names, dtypes, shapes, and offsets, and a flat byte buffer. Read more: 20.3.4 Portability and load triage
  • Explicit allocator: the Zig convention that every function that allocates takes an allocator as a parameter, so memory cost is visible at the call site and the strategy (arena, pool, leak-detecting test allocator) can change without changing the code. Read more: Chapter 24: Zig in Programming and Algorithms
  • symmetric quantization: affine quantization with z=0z = 0, used for roughly zero-mean weights to avoid GEMM cross-terms. Read more: 20.1.4 Choosing and validating quantization
  • Dot product: u⋅v=∑iuivi=∥u∥∥v∥cos⁡θu \cdot v = \sum_i u_i v_i = \lVert u \rVert \lVert v \rVert \cos\theta; it measures how much two vectors point the same way, and it is zero exactly when they are perpendicular. Read more: Chapter 10: Calculus 3 in Mathematics
  • K-quants / i-quants: llama.cpp’s weight quantization schemes for GGUF files; k-quants mix precision per block, and i-quants choose precision guided by an importance matrix measured on sample data. Read more: Chapter 26: Edge and Realtime Inference
  • Service Level Objective (SLO): a target for a defined measure of service behavior over a specified window. Read more: Chapter 13: Engineering Acronyms in Software Engineering

This section maps that landscape. The throughline is that every framework is the same three layers, a kernel and tensor core, a runtime, and a server, assembled in a different language for a different deployment target. Once you can see those layers, choosing a framework becomes a matter of choosing a deployment story, and the choice of language largely makes it for you.

This section builds on the chapter opening, LLM Systems & Inference, particularly its tour of serving frameworks and of deployment on GPU clusters, and it assumes basic reading knowledge of C, Rust, and Zig. The quantization formats these frameworks consume are derived in Quantization: Math to Code, and deployment choices and operating costs for hosted platforms (Anyscale, Ray, vLLM, SGLang, RouteLLM, and OpenRouter) are in LLM Serving Platforms. Runnable examples are in code/.

Learning objectives

  • Decompose any inference framework into its kernel, runtime, and server layers, and say which layers it owns and which it borrows.
  • Explain why GGUF and the OpenAI-compatible HTTP API act as the universal exchange formats between frameworks.
  • Compare the C, Python, Rust, and Zig tiers by deployment target, and pick a framework for a given target with a reason.
  • Describe the two Zig idioms, wrapping C with @cImport and writing pure-Zig SIMD kernels, and when each fits.

There is no single “inference framework”. There is a stack, and each project stakes out a slice of it. Python frameworks such as vLLM maximize datacenter GPU throughput. C (llama.cpp) maximizes portability and minimizes dependencies, so a model runs on a laptop. Rust (candle, mistral.rs) trades a little ecosystem maturity for memory safety and a single static binary. Zig (ZML) bets on compiling the whole model graph to a standalone native artifact via MLIR. Pick the language and you have largely picked the deployment story.

The stack itself has three layers, and the table below shows what each one does and who implements it.

LayerJobExamples
Kernels / tensor corematmul, attention, dequant on CPU/GPUggml, CUTLASS/cuBLAS, candle-core, Metal/Vulkan shaders, MLIR+XLA
Runtimeload weights, run the graph, manage KV cache, sample tokensllama.cpp, candle-transformers, mistral.rs engine, ZML
Scheduler / servercontinuous batching, request queue, OpenAI HTTP APIllama-server, vLLM, TGI, SGLang, mistralrs-server, LLMD

Most “frameworks” are a vertical slice through these layers, and they differ in which layers they own and which they borrow. Ollama is the llama.cpp runtime plus a friendly model manager. mistral.rs is candle’s kernels plus its own runtime plus an OpenAI-compatible server.

Two artifacts tie the layers together across projects. GGUF is the lingua franca of portable inference: a single quantized model file from llama.cpp’s ecosystem runs under llama.cpp, candle, mistral.rs, and the Zig bindings alike. And the OpenAI-compatible HTTP API is the universal contract at the top: swap llama.cpp’s llama-server for vLLM, for mistral.rs, or for ZML’s LLMD, and clients do not change. With the layers and the two contracts in view, we can walk the tiers one language at a time, starting at the bottom.

llama.cpp is the most-deployed inference engine on earth, and most of the non-Python ecosystem rests on it. Its core is ggml, a dependency-free C tensor library with a static computation graph and a quantization-first design, with backends for CPU (AVX and NEON), Metal, CUDA, Vulkan, SYCL, and ROCm. On top of ggml, llama.cpp provides the transformer runtime and llama-server, an OpenAI-compatible server. llama.cpp also defines GGUF, the quantized model container, and the k-quant and i-quant formats, which are explained in Quantization: Math to Code.

The C API in llama.h is the integration point for every other language. Python (llama-cpp-python), Rust (llama-cpp-2), Zig (@cImport), Go, and others all bind to it. The same ggml core underlies a family of projects, including whisper.cpp and stable-diffusion.cpp, and downstream, Ollama, LM Studio, Jan, GPT4All, and KoboldCpp all wrap llama.cpp.

llama.cpp wins for edge and local use because it needs no Python and no CUDA: it is a single small binary that runs a 7B model on a laptop CPU. The tradeoff is lower datacenter GPU throughput than vLLM. Historically it had no PagedAttention-class scheduler, and its continuous batching is newer.

The Python tier is the datacenter-throughput layer, covered in the chapter opening’s tour of serving frameworks. In one line each: vLLM combines PagedAttention with continuous batching and is the general-purpose throughput leader; TensorRT-LLM uses compiled NVIDIA kernels and FP8 for maximum performance on H100; TGI is Hugging Face’s production server; SGLang offers RadixAttention prefix sharing and fast structured output; and Ray Serve and KServe provide orchestration on top of any of these. These dominate GPU clusters. The C, Rust, and Zig tiers dominate edge, embedded, and dependency-constrained deployments.

Rust trades ecosystem breadth for memory safety, a single static binary, and no GIL. The current stack has several projects, each owning a different combination of layers:

FrameworkLayer(s)NicheNotes
candlekernels + runtimeminimalist ML, the Rust “PyTorch-lite”CPU/CUDA/Metal/WASM; loads GGUF + safetensors; HuggingFace-backed
mistral.rsruntime + serverturnkey fast inferencebuilds on candle; ISQ (in-situ quant), OpenAI server, vision/tools
burnkernels + runtimebackend-agnostic train and inferWGPU/CUDA/NdArray/LibTorch; own quantization API (see Quantization: Math to Code)
ratchetkernels + runtimeweb/cross-platform GPUwgpu-based, browser-first inference
luminalcompiler + runtimesearch-compiled kernelstiny graph IR, compiles to fast kernels
llama-cpp-2Rust interfacereuse llama.cpp from Rustllama_cpp is the higher-level wrapper

Warning: rustformers/llm (and the older llama-rs) are unmaintained. The ecosystem consolidated onto candle and mistral.rs; use those.

Pick Rust for edge and embedded targets, for WASM in the browser, for a CLI you ship as one binary, or for a service where you want Rust’s safety end to end. Two examples show the shape of the code: code/candle_generate.rs runs GGUF generation with candle, and code/mistralrs_serve.rs stands up an OpenAI-compatible server with in-situ quantization.

Zig makes a different pitch. Its interop with C is trivial, since @cImport reads C headers directly with no binding generator, and it compiles the whole program to a small native artifact. The Zig projects take two quite distinct approaches:

ProjectApproachNotes
ZMLcompile model graphs via MLIR + OpenXLAZig + XLA → standalone native binaries; NVIDIA/AMD/TPU/Trainium from one codebase; LLMD OpenAI server in a ~2.4 GB image
llama.cpp.zigbindings + build.zig over llama.cppreuse the C engine from Zig via @cImport
llm.zigfrom scratch, no depspedagogical full-stack inference in pure Zig
llama2.zigport of Karpathy’s llama2.cthe cleanest “read the whole inference loop” reference

Beneath the projects are two idioms. The first is to wrap C: write @cImport({ @cInclude("llama.h"); }) and call llama.cpp directly. Zig’s interop makes this less code than the equivalent Rust bindgen setup; code/llama_cpp.zig shows it. The second is to write pure Zig kernels, implementing the hot loops yourself with @Vector SIMD and explicit allocators. code/quant_dot.zig does this for INT8 symmetric quantization followed by a SIMD dot product; it is the CPU twin of quantization/code/symmetric_quant.cu.

Pick Zig when you want C-level control and a tiny dependency-free binary, when you are already calling C libraries (Zig is arguably the best C-interop language), or when you want compile-time graph specialization, as ZML provides.

Having walked the four tiers, you can now turn the question around and start from the deployment target. This table gives the framework that fits each target and the reason:

Deployment targetLanguageFrameworkWhy
GPU cluster, max throughputPythonvLLM / TensorRT-LLMPagedAttention, FP8, mature scheduler
Laptop / CPU / “just runs”Cllama.cpp (llama-server)no deps, GGUF, every backend
Single safe static binary, edgeRustmistral.rs / candlememory-safe, OpenAI server, ISQ
Browser / WASMRustcandle / ratchetnear-native in-browser inference
Multi-vendor native compileZigZMLMLIR/XLA → standalone binary, AMD/TPU/Trainium
Reuse C engine, minimal binaryZigllama.cpp.zig@cImport, no binding generator
Train + infer in one stackRustburnbackend-agnostic, own quant API

The same information, organized by language rather than by target, gives a compact matrix of each tier’s flagship, kernel core, quantization formats, server, and strength:

C/C++PythonRustZig
Flagshipllama.cppvLLMcandle / mistral.rsZML
Kernel coreggml, CUTLASSTriton, CUTLASScandle-coreMLIR/XLA, @Vector
Quant formatsGGUF k/i-quantsGPTQ/AWQ/FP8GGUF, ISQGGUF (via C), native
Serverllama-servervLLM/TGI/SGLangmistralrs-serverLLMD
Best atportabilitythroughputsafe single binarynative compile + C interop
File exchangecheckpoint filessafetensors, tokenizer.jsonsafetensors, tokenizer.jsonserialized model formats

The best way to make the comparison concrete is to run it. Serve the same GGUF model under llama.cpp (llama-server), candle, and mistral.rs, and compare tokens per second, memory, and binary footprint. For each framework, identify its three layers and which it borrows (mistral.rs borrows candle’s kernels; Ollama borrows llama.cpp’s runtime). Then build one example from code/ per language to compare how each language handles runtimes and file interfaces.

The formats these frameworks load, GGUF k-quants, in-situ quantization, and FP8, are derived in Quantization: Math to Code, and the continuous batching, KV cache management, and SLOs that the runtime and server layers implement are the subject of the chapter opening, LLM Systems & Inference, and of Serving & Load. Seeing the same algorithm in C, Rust, and Zig is the theme of Practice: Predict and Build, and deploying any of these servers on Kubernetes with autoscaling behind an OpenAI-compatible API is covered in Cloud Native in Systems Engineering.

These tiers map onto real organizations. Meta and ggml-org maintain llama.cpp, ggml, and GGUF, the C foundation; Hugging Face builds candle, ratchet, and TGI across the Rust and Python tiers; ZML in Paris pursues Zig plus MLIR/XLA multi-vendor inference; Ollama and LM Studio productize llama.cpp for local use; and NVIDIA supplies TensorRT-LLM and the CUTLASS kernels underneath many runtimes.

  • kernel / tensor core layer: the code that performs matmul, attention, and dequantization on a specific CPU or GPU backend.
  • runtime: the layer that loads weights, executes the model graph, manages the KV cache, and samples tokens.
  • server layer: the scheduler and request queue that batch requests and expose an HTTP API.
  • GGUF: llama.cpp’s single-file quantized model container, readable across llama.cpp, candle, mistral.rs, and Zig bindings.
  • OpenAI-compatible API: the de facto HTTP contract that lets clients switch between serving frameworks unchanged.
  • ISQ (in-situ quantization): mistral.rs’s quantization of weights at load time rather than ahead of time.
  • @cImport: Zig’s built-in that reads C headers directly, removing the need for a binding generator.
  • Every inference framework is three layers, a kernel/tensor core, a runtime, and a server, and frameworks differ in which layers they own and which they borrow.
  • GGUF is the lingua franca of portable inference, and the OpenAI-compatible HTTP API is the universal contract at the top of the stack.
  • Language picks the deployment target: Python for maximum-throughput GPU serving, C for “runs anywhere with no runtime”, Rust for a single safe static binary at the edge, and Zig for minimal-dependency native compilation and effortless C interop.
  • llama.cpp’s C API is the integration point for nearly every non-Python binding, and Ollama, LM Studio, and others wrap its runtime.
  1. Describe Ollama and mistral.rs in terms of the three-layer stack.
    AnswerOllama is the llama.cpp runtime (and ggml kernels underneath it) plus a friendly model manager; it borrows both lower layers. mistral.rs borrows candle's kernels, owns its own runtime, and adds an OpenAI-compatible server.
  2. Why can a client switch from vLLM to llama-server to mistral.rs without code changes, and what makes the same model file usable across llama.cpp, candle, and mistral.rs?
    AnswerAll of them expose the OpenAI-compatible HTTP API, which is the shared contract at the server layer. At the file level, GGUF is the shared container: one quantized GGUF file runs under llama.cpp, candle, mistral.rs, and the Zig bindings.
  3. What does llama.cpp give up relative to vLLM, and what does it gain?
    AnswerIt gives up datacenter GPU throughput: historically it lacked a PagedAttention-class scheduler, and its continuous batching is newer. It gains portability: no Python, no CUDA requirement, a single small binary, and backends from AVX and NEON to Metal, CUDA, Vulkan, SYCL, and ROCm, enough to run a 7B model on a laptop CPU.
  4. You need to ship a model inside a browser application. Which tier and frameworks fit, and why?
    AnswerThe Rust tier: candle supports a WASM backend, and ratchet is a wgpu-based, browser-first inference library. Both give near-native in-browser inference from a memory-safe codebase.
  5. What are the two Zig idioms for inference, and when would you choose each?
    AnswerWrapping C, using `@cImport` to call llama.cpp directly, fits when you want to reuse the mature C engine in a minimal Zig binary with less glue than Rust's `bindgen`. Writing pure Zig kernels with `@Vector` SIMD and explicit allocators fits when you want full control of the hot loops, as in `quant_dot.zig`. ZML adds a third path, compiling the model graph through MLIR and OpenXLA for multi-vendor native binaries.