groundy
developer tools

Rust Is Quietly Replacing Python in AI Infrastructure

Rust is taking over the performance-critical layers of AI infrastructure, inference engines, tokenizers, data pipelines, while Python retains its role in research and orchestration. Here's what's actually changing and why it matters for practitioners.

8 min···19 sources ↓

Rust is not replacing Python in machine learning research or model development. It is, however, systematically taking over the performance-critical infrastructure that runs beneath those workflows: inference engines, tokenizers, data pipelines, and serving layers. The shift is already in production at companies like Cloudflare, Hugging Face, and across the vLLM ecosystem.

What Is Actually Being Replaced

The framing matters here. Python is not being wholesale ejected from AI infrastructure. It remains dominant for model training, experimentation, and high-level orchestration. What Rust is displacing is the bottleneck layer: the components where Python’s overhead becomes measurable and consequential at scale.

Three areas have seen the most traction:

Inference engines. The systems that execute trained models in production are increasingly written in or migrating toward Rust. Cloudflare’s Infire, a custom LLM inference engine written entirely in Rust, serves as a concrete data point: it completes inference tasks 7% faster than vLLM 0.10.0 on an unloaded NVIDIA H100 NVL GPU while consuming only 25% CPU, compared to vLLM’s 140%+ under the same conditions. (Cloudflare. “How we built the most efficient inference engine for Cloudflare’s network.” Cloudflare Blog, 2025) That CPU delta matters enormously at edge scale, where Cloudflare runs inference across a globally distributed network. Infire also implements techniques like Paged KV Caching (the same class of memory management optimization covered in speculative decoding and PagedAttention), achieving a 99.99% warm request rate and sub-4-second model load times. [Updated June 2026] Cloudflare expanded the architecture in May 2026 to run trillion-parameter models on Workers AI: a disaggregated prefill/decode design that separates compute-bound from memory-bound stages cut p90 inter-token latency from roughly 100ms to 20-30ms (a 3x reduction), a weight-compression layer it calls Unweight kept cold starts under 20 seconds for the largest models, and the Rust engine now reports 20% higher throughput than its vLLM baseline rather than the original 7%. (Cloudflare. “Building the foundation for running extra-large language models.” Cloudflare Blog, May 2026)

Tokenizers and NLP preprocessing. Hugging Face’s tokenizers library (the component that converts raw text to model-ready tokens) has a Rust core. The performance difference is not subtle: benchmarks against the Python-based equivalents show a 43x speed increase on the SQUAD2 dataset subset, and the Rust implementation tokenizes 1 GB of text in under 20 seconds on a server CPU. (Hugging Face. “Tokenizers: Fast State-of-the-Art Tokenizers.” GitHub, 2025) That speedup compounds when tokenization runs millions of times per day.

Data processing pipelines. Polars, the DataFrame library written in Rust, processes 10 million rows with 10 columns in 0.89 seconds. The equivalent pandas operation takes 2.37 seconds, a 2.66x difference on that specific workload; 2025 benchmarks show the advantage ranges from 2.6x (aggregations) to 4.6x (filtering on 1 GB datasets) depending on operation type, and saves hours of compute time on production feature engineering jobs. (Odendaal, Andrew. “Rust for AI and Machine Learning in 2025: Libraries, Performance, and Use Cases.” andrewodendaal.com, 2025) [Updated June 2026] Polars reached 1.40 by April 2026 and its GPU engine, built on NVIDIA RAPIDS cuDF, entered open beta with up to 13x speedups over the CPU path on compute-bound queries. A redesigned streaming engine that pairs morsel-driven parallelism with Rust async state machines is the headline target for the 2.0 release. Reported wins over pandas now stretch from the conservative 2.6x up to 30x on group-by-heavy workloads, with the spread reflecting how much of a query stays in the columnar Rust core versus crossing back into Python.

Why This Convergence Is Happening Now

The technical argument for Rust in AI infrastructure boils down to two intersecting constraints: Python’s Global Interpreter Lock and memory management overhead.

Python’s GIL prevents true parallelism for CPU-bound tasks. When a single agent “thinks” (running inference or processing context), the GIL serializes execution regardless of available CPU cores. Red Hat documented this concretely: a CPU-bound Python task actually ran slower in a multi-threaded configuration (0.1520 seconds) than single-threaded (0.1408 seconds) due to threading overhead. The same task in Rust improved from 0.0107 seconds single-threaded to 0.0025 seconds multi-threaded. Genuine parallelism at work. (Red Hat Developer. “Why some agentic AI developers are moving code from Python to Rust.” September 15, 2025)

Memory safety is the second driver. Python’s garbage collector introduces non-deterministic latency pauses (acceptable in research environments, problematic in latency-sensitive inference serving). Rust’s ownership model eliminates this class of problem at compile time, delivering predictable memory behavior without a runtime GC. The same calculus is pulling infrastructure projects toward Rust from other systems languages too: Bun is rewriting its core from Zig to Rust to end a long tail of memory bugs, which is the closest thing to a controlled experiment on whether the borrow checker pays for itself in a high-throughput runtime.

The timing aligns with a broader ecosystem maturity point. The critical libraries (Candle, Burn, Polars, mistral.rs, PyO3) have crossed thresholds of stability and production readiness in 2024–2025 that weren’t there two years ago.

The Rust AI Tooling Landscape (as of Early 2026)

The ecosystem has fragmented into distinct layers with different maturity levels:

ToolCategoryKey CapabilityProduction Status
CandleInference frameworkcandle-transformers 0.10.2 (Apr 2026), CPU/CUDA/WASM backendsProduction (Hugging Face)
mistral.rsLLM inference engine40+ model families, OpenAI + Anthropic-compatible APIActive (~7,300 stars) [Updated June 2026]
BurnDeep learning frameworkFull training + inference, 1.54x PyTorch speedupMaturing
PolarsData processing2.66x pandas speedup, GPU acceleration availableProduction
tokenizersNLP preprocessing43x speedup vs pure PythonProduction (Hugging Face)
PyO3FFI bridgeRust extensions callable from PythonProduction
Cloudflare InfireEdge inference7% faster than vLLM, 82% CPU overhead reductionProduction (Workers AI)

Hugging Face Candle benchmarks against Llama.cpp and Apple MLX on M1 show Candle trailing Llama.cpp by a narrow margin in raw speed but offering a pure-Rust implementation with async API support, a tradeoff teams running Rust-native infrastructure will accept. (Zain ul Abideen. “Apple MLX vs Llama.cpp vs Hugging Face Candle Rust for Lightning-Fast LLMs Locally.” Medium) On Apple Silicon specifically, the runtime choice shifts again, and the tradeoffs between MLX and llama.cpp for local inference (where MLX leads on smaller models and llama.cpp wins on portability and long context) make the Rust-native option a third axis rather than a clear default.

How the Hybrid Model Actually Works

The dominant production pattern is not full rewrites from Python to Rust. It is surgical integration using PyO3, which allows Rust code to be compiled as Python-native extensions.

use pyo3::prelude::*;
#[pyfunction]
fn process_embeddings(embeddings: Vec<Vec<f32>>) -> PyResult<Vec<f32>> {
// CPU-intensive reduction running without GIL constraints
let result = embeddings.iter()
.map(|e| e.iter().sum::<f32>() / e.len() as f32)
.collect();
Ok(result)
}
#[pymodule]
fn fast_ops(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(process_embeddings, m)?)?;
Ok(())
}
import fast_ops # compiled Rust extension via PyO3
import numpy as np
embeddings = np.random.rand(10000, 512).tolist()
result = fast_ops.process_embeddings(embeddings) # runs in Rust, callable from Python

PyO3 benchmarks report up to 15x speedups for compute-bound Python tasks, with extreme cases reaching 100x in internal benchmarks for 2025 workloads. (Muruganantham, Er. “Why Python Developers Are Turning to Rust with PyO3 for Faster AI and Data Science in 2025.” Medium, 2025) The practical workflow: prototype in Python using the full ML ecosystem, profile to find bottlenecks, rewrite the hot paths in Rust and expose them via PyO3.

vLLM’s Router, released December 2025, follows the same pattern at the infrastructure layer: a Rust-built load balancer sits between Python-orchestrated clients and vLLM workers, delivering 25% higher request throughput than the previous llm-d setup and cutting time-to-first-token by 1,200 milliseconds. (vLLM Team. “vLLM Router: A High-Performance and Prefill/Decode Aware Load Balancer for Large-scale Serving.” vLLM Blog, December 13, 2025)

What Practitioners Need to Know

The transition has practical implications depending on where you sit in the AI stack:

If you run inference infrastructure, the case for evaluating Rust-based alternatives is strong and evidence-backed. Cloudflare’s CPU utilization numbers alone (25% vs 140% for equivalent throughput) represent meaningful cost differences at scale, particularly relevant for serving setups where compute budget is constrained and cold-start latency forces operators back into warm GPU pools. mistral.rs and Candle are production-ready for teams that can accept a smaller model support surface than vLLM.

If you build AI pipelines, Polars has effectively become the default recommendation for new Python data pipelines when performance is a concern. The Python API is idiomatic; the Rust core is invisible unless you need it.

If you’re building agentic systems at scale, the GIL argument remains relevant past roughly 50–100 concurrent CPU-bound agents, even after Python 3.14’s free-threaded improvements, particularly if your dependency stack re-enables the GIL via C extensions. The Red Hat analysis and emerging Rust agentic frameworks (anda, AutoAgents) point toward Rust as the preferred runtime for production multi-agent systems where concurrency is the primary constraint. (Vision on Edge. “The Rise of Rust in Agentic AI Systems.” visiononedge.com, 2025) The coordination overhead in those systems is explored further in why attention steering beats full broadcast in multi-agent LLM coordination.

If you’re a Python ML engineer, learning Rust is not urgent for research workflows. Understanding PyO3 and when to reach for it is increasingly a production engineering skill.

Does Python 3.14 Free-Threading Change the Calculus?

Python 3.14, released in October 2025, moved free-threaded mode (PEP 703) from experimental to officially supported. The practical effect: disabling the GIL now carries roughly 5–10% single-threaded overhead rather than the 40% penalty seen in Python 3.13. For teams already running Python 3.14+ with fully compatible dependencies, this is a genuine concurrency improvement.

The qualifier matters. Free-threaded mode is not the CPython default as of Python 3.14. It requires explicitly building or installing the python3.14t free-threaded variant. More importantly, many packages with C extensions (including some widely used in ML pipelines) automatically re-enable the GIL when loaded, because their extension modules haven’t been updated for PEP 703 compatibility. NumPy, pandas, and scikit-learn are actively working toward free-threading support, but coverage is uneven across the ecosystem as of early 2026.

The practical implication for infrastructure decisions:

ScenarioPython 3.14t free-threadingRust via PyO3
Greenfield stack, compatible depsViable near-term optionHigher ceiling, more migration effort
Existing Python codebase with C extensionsRe-enables GIL; limited benefitSurgical hot-path rewrites only
New multi-agent system, CPU-boundPromising if deps are compatiblePredictable parallelism today
Memory safety / predictable latencyNo GC improvementOwnership model eliminates GC pauses
Team has no Rust experienceLow migration costMeaningful learning curve

The realistic picture is that Python 3.14 free-threading and Rust-via-PyO3 are not competing solutions. They solve different surfaces of the same problem. Free-threading addresses concurrency within a Python runtime. PyO3 addresses compute-bound hot paths regardless of Python version. Teams running at the scale where these distinctions matter are likely to use both.

The Stack Overflow 2025 Developer Survey found Rust as the most admired programming language for the tenth consecutive year at 72% admiration, with usage up 2 percentage points, a modest number that understates infrastructure penetration, since infrastructure code runs at higher leverage than application code. (Stack Overflow. “2025 Stack Overflow Developer Survey.” survey.stackoverflow.co, 2025) JetBrains’ State of Rust Ecosystem report, published February 2026 based on 24,534 developers surveyed, identified expanding adoption across backend services, infrastructure, and AI tooling as the core growth areas. (JetBrains. “The State of Rust Ecosystem 2025.” RustRover Blog, February 11, 2026)

The displacement is happening at the layer that matters most for cost and performance: the critical path between trained model and served response. Python will remain the language of AI research. Rust is becoming the language of AI production.

Frequently Asked Questions

Q: Should I rewrite my Python ML codebase in Rust? A: No, unless specific components are bottlenecks at scale. The practical approach is to keep Python for orchestration, model development, and anything using the PyTorch ecosystem, and migrate only CPU-bound hot paths to Rust via PyO3.

Q: Which Rust inference engines support the most models? A: vLLM (with its Rust router layer) has the broadest model support. mistral.rs and Candle cover major transformer architectures (Llama, Mistral, Gemma, Qwen, Whisper) but have narrower coverage than Python-based alternatives as of early 2026.

Q: How significant is the performance difference between Python and Rust for inference? A: It varies by bottleneck type. Tokenization shows 10–43x improvements. Inference throughput improvements are narrower, Cloudflare’s Infire is 7% faster than vLLM in raw tokens/second but dramatically more CPU-efficient. The CPU savings often matter more than raw speed at production scale.

Q: Is Polars a safe migration target from pandas? A: For new pipelines, yes. For existing pandas code, Polars requires API migration (not a drop-in replacement), but performance gains of 2–13x depending on operation type and data volume are consistently reported in 2025 benchmarks.

Q: What is PyO3 and why does it matter for AI teams? A: PyO3 is a Rust library for creating Python-native extensions. It lets teams write performance-critical components in Rust while maintaining Python as the orchestration language, the pattern that companies like Hugging Face, Polars, and vLLM use in production today.

What Has Surfaced Since Publication [Added May 2026]

Two emerging projects worth tracking in the Rust-AI infrastructure space have surfaced since this article was first published.

Crane is a pure-Rust LLM/VLM/VLA/TTS/OCR inference engine built on Candle, positioning itself as a cleaner alternative to llama.cpp for teams already operating Rust stacks. It supports unified inference across multiple model modalities (text, vision-language, voice-language, text-to-speech, OCR) under a single binary, closing a gap that has historically pushed teams toward multi-language stacks for multimodal serving.

OxiBonsai v0.1.0 ships as the first zero-FFI, zero-C/C++ pure-Rust 1-bit LLM inference engine. The use case is narrow, running 1-bit quantized models like PrismML’s Bonsai-8B on commodity CPU hardware, but the architecture is a meaningful step toward fully native Rust inference paths that don’t depend on the C extension ecosystem at all. For deployments where binary auditability matters (regulated environments, supply-chain-sensitive contexts), zero-FFI is a real differentiator.

The pattern these projects reinforce: the Rust AI inference ecosystem is fragmenting along specialized lines (modality coverage, quantization regime, deployment target) rather than consolidating into a single dominant runtime. For practitioners, this means selection criteria continue to be workload-specific rather than universal.

What Changed by Mid-2026 [Added June 2026]

The clearest signal since this article first ran is that the pure-Rust inference path stopped being aspirational. vllm-rs (v0.11.5, May 2026) ships as a reimplementation of vLLM in Rust with, by its own description, no PyTorch and no Python runtime, keeping core scheduling and attention logic under 5,000 lines and exposing optional Python bindings through PyO3. (vllm-rs on PyPI) It is built on Candle rather than written from scratch, which is the recurring shape of this ecosystem: Candle has become the substrate that other engines are assembled on, the way PyTorch became the substrate for Python serving stacks. candle-transformers itself crossed two million all-time downloads by April 2026 at version 0.10.2, with CPU, CUDA, and WebAssembly backends in the same crate. (candle-transformers on crates.io)

The more telling move came from PyTorch’s own side. PyTorch Monarch pairs a Python frontend with a Rust backend, built on a low-level Rust actor system called hyperactor for distributed message passing and supervision, with the project citing performance and fearless concurrency as the reasons for choosing Rust at the coordination layer. (PyTorch. “Introducing PyTorch Monarch.” PyTorch Blog, 2026) When the reference Python ML framework reaches for Rust to run its distributed control plane, the “Python for research, Rust for production infrastructure” split has stopped being an outside critique and become an internal design decision.

Two smaller markers fill in the picture. Hugging Face’s tokenizers library began shipping dedicated wheels for CPython’s free-threaded build (python3.14t), a quiet acknowledgment that the GIL-removal work and the Rust-core libraries now have to interoperate cleanly. And the broader pattern of replacing Python-ecosystem incumbents with Rust tools is visible well outside inference: uv and Ruff, the Rust-built package manager and linter, have become defaults in large parts of the Python toolchain, with uv reporting over 100 million downloads a month. (uv: Python packaging in Rust. Astral) That is the same displacement thesis as this article’s, applied one layer up the stack, in the developer tooling that wraps the models rather than the runtimes that serve them.

None of this changes the conclusion. PyTorch still owns training, the research workflow still lives in Python, and no Rust framework is close to displacing either. What 2026 added is evidence that the infrastructure-layer migration is now self-reinforcing: every Rust engine built on Candle makes the next one cheaper to build, and a Python-native runtime that re-enables the GIL on a single incompatible C extension is a harder thing to reason about than a Rust binary that never had one.


sources · 19 cited

  1. Candlegithub.comcommunityaccessed 2026-04-24
  2. mistral.rsgithub.comcommunityaccessed 2026-04-24
  3. Burngithub.comcommunityaccessed 2026-04-24
  4. Polarsgithub.comcommunityaccessed 2026-04-24
  5. PyO3github.comcommunityaccessed 2026-04-24
  6. candle-transformers on crates.iocrates.iocommunityaccessed 2026-06-20
  7. uv: Python packaging in Rust. Astralgithub.comvendoraccessed 2026-06-20