my little winter · Willix
← All posts

Why AI Is Moving to Rust

Every few months someone on the internet announces that Python is dying. It isn't. But something real is happening underneath the Python. The parts that actually run in production are being rewritten in Rust, quietly, one library at a time.

I noticed this the first time I looked at how Hugging Face tokenizers work. I was reading through the source and saw that almost none of it was Python. It was a thin wrapper around a Rust binary. That surprised me. I thought the whole AI ecosystem was Python all the way down. It's not.

The Python problem

Python is slow. Everyone knows this, so I won't spend too long on it. But the interesting part is where the slowness actually matters.

Training a model is not the bottleneck. The GPU does the work, and Python just sends instructions. You could write your training loop in almost any language and get similar results, because the GPU is the one doing the math.

The bottleneck is everything else. Tokenization. Data loading. Serving requests. Preprocessing. The glue code. That's where Python starts to cost real money.

If a company serves a model to millions of users, a tokenizer that processes a few thousand tokens per second is not good enough. A tokenizer written in Rust can handle millions. That difference is the difference between a profitable product and a bleeding one.

Why Rust and not C++

Speed alone wouldn't justify a rewrite. C++ is fast too. If speed was the only concern, the industry would still be writing C++ like it did in the 2000s.

Rust's real advantage is memory safety. The borrow checker catches entire categories of bugs at compile time. Null pointer dereferences, data races, use after free. Things that have caused real outages and real security vulnerabilities in production systems for decades.

If you're running an inference server, a crash is not a minor inconvenience. It's lost revenue and lost trust. Rust makes that kind of failure much harder to write.

There's also the tooling. Cargo is genuinely pleasant to use. The compiler errors are helpful instead of cryptic. The ecosystem is smaller than Python's, but the packages that exist tend to be well maintained.

What's actually being rewritten

Hugging Face rewrote their tokenizers in Rust years ago. The library is one of the fastest tokenizers in the world, and most production pipelines use it. When you call tokenizer.encode() in Python, you're calling into Rust.

They also released Candle, a small ML framework written in Rust. It's not trying to replace PyTorch. It's trying to be a fast runtime for inference and deployment. That's a different job, and it matters.

OpenAI has posted job listings for Rust engineers. Anthropic has talked about using Rust in parts of their infrastructure. These aren't small experiments. These are companies whose product depends on this code.

The pattern is consistent across the industry. Python for research. Rust for production.

It's not just AI

Look at the Python data ecosystem and you'll see the same thing.

Polars, the DataFrame library, is written in Rust and is dramatically faster than pandas. Ruff, the Python linter, is written in Rust and replaces flake8 with something that finishes before you lose focus. uv, the package installer, is written in Rust and makes pip feel like waiting for a dial-up connection.

All three of these were built by people who got tired of waiting. Someone writes a useful Python tool. It becomes popular. Someone else rewrites it in Rust. Everyone switches. The cycle repeats.

AI is just the newest field following the same path.

Python is not going anywhere

I want to be careful here because I see people overreact to this trend. Python is not dying.

The research ecosystem runs on Python. PyTorch, JAX, scikit-learn, every paper's code, every tutorial on YouTube. You can't replace that overnight, and honestly you shouldn't try.

What's actually happening is subtler. Python is becoming the interface. Rust is becoming the engine. You write Python, it calls into Rust, Rust does the heavy work. That pattern is already everywhere, and it's probably going to stay.

For someone like me, learning Python first is still the right move. But it helps to know what's running underneath. When I call a function and it returns in a millisecond, that's not magic. That's someone else's Rust code doing the work.

Why this matters to me

I'm 16. I don't work in AI infrastructure. I'm not building anything at that scale. But I care about this trend because it tells me something about where the field is heading.

The people who understand both layers, the Python that everyone uses and the Rust that makes it fast, are going to be more valuable than the people who only know one. Not because Rust is fashionable. Because the boundary between the two is where the real problems are being solved.

I started learning Rust recently. Slowly. The borrow checker has rejected more of my code than I want to admit, and I've rewritten a simple program four times for reasons that felt arbitrary until they didn't. But I get it now. It's not punishing me. It's showing me bugs I would have found at 3am in production, if I was lucky.

The honest part

Not every AI project should be Rust. If you're fine tuning a model for a paper, use Python. If you're prototyping an idea, use Python. If you're writing something that runs once and never again, use Python. Rust costs you time and complexity, and that trade isn't always worth it.

Rust makes sense when the cost of failure is high, when performance actually matters, or when other people will depend on the code. That's most production systems. That's why the trend exists.

The move to Rust is not hype. It's a response to real problems that Python was never designed to solve. Python is not bad. It's just not the right tool for every job. And the AI industry is finally admitting that out loud.

See you

That's it for this one. If you're learning AI and wondering whether to learn Rust, my honest answer is this. Learn Python first. Learn it well. Then learn Rust when you feel Python's limits yourself. You'll know when. Nobody has to tell you.

— Doğukan