Gemma 4 in Rust on TorchTPU: A Native TPU Rig With PyO3 and MCP A developer published a step-by-step guide to serving the Gemma 4 E2B model from a Cloud TPU v5e-1 VM, with the model's forward pass written in Rust and every operation dispatched through TorchTPU via a 154-line C++ shim over ATen. The Rust engine matches Hugging Face Transformers on 64 of 64 greedy tokens on CPU, boots on a fresh TPU VM in 4 minutes 29 seconds, and decodes at a median 12.20 tokens per second on the TPU. A Claude Code MCP server provisions the TPU, and the VM serves an OpenAI-compatible streaming endpoint on port 8000. This article provides a step by step guide to serving Gemma 4 E2B from a Cloud TPU v5e-1 VM with the model written in Rust and every operation run by TorchTPU. A Claude Code MCP server provisions the TPU, the VM builds the Rust crate on boot and serves an OpenAI-compatible endpoint, and a local shim gives it a chat page and a second MCP server for demos. Python hosts the process and the HTTP server; the 35 layers, the ring cache and the decode loop are Rust. https://github.com/xbill9/torchtpu-dev/tree/main/tpu-pytorchrust-v5e1-2b-q4w4a16emb4 https://github.com/xbill9/torchtpu-dev/tree/main/tpu-pytorchrust-v5e1-2b-q4w4a16emb4 The Rust model reaches TorchTPU through a 154-line C++ shim over ATen, so it builds against whichever PyTorch is installed: here Python 3.14, PyTorch 2.14.1 and a nightly Rust. It matches Hugging Face Transformers on 64 of 64 greedy tokens on CPU, boots on a fresh TPU VM in 4 minutes 29 seconds from installing Python to starting the service, and decodes at a median 12.20 tokens per second on the TPU. Gemma 4 in Rust on TorchTPU: Hands On With Colab https://dev.to/gde/gemma-4-in-rust-on-torchtpu-hands-on-with-colab-44hi ran the same Rust engine in a Colab notebook. This rig takes it to a TPU VM of its own and keeps it there: | Layer | Where | What | |---|---|---| | Capacity | Claude Code | An MCP server that creates a v5e-1 queued resource and reads its boot stages | | Model | TPU VM | torchtpu rs , a Rust crate built on the VM as a PyO3 extension | | Kernels | TPU VM | ATen calls through PyTorch's dispatcher to TorchTPU | | API | TPU VM, port 8000 | rust openai server.py , OpenAI-compatible, streaming | | Demo | This laptop | A shim on 127.0.0.1:8015 with a chat page, and a demo MCP server | The checkpoint is the W4A16 repack xbill9/gemma-4-E2B-it-qat-q4 0-w4a16-ct-text with the int4 vocabulary tables from its -text-emb4 twin. The directory name follows the rig naming scheme: tpu Cloud TPU API , pytorchrust the forward pass is Rust over PyTorch's ATen , v5e1 , 2b , and q4w4a16emb4 for the encoding. Versions on the VM, read from its /v1/engine : Python 3.14.10, PyTorch 2.14.1, torch tpu 0.2.0, libtpu 0.0.51, Transformers 5.20.2, rustc 1.101.0-nightly. The rig is a Claude Code plugin with its own MCP server and skill: git clone https://github.com/xbill9/torchtpu-dev cd torchtpu-dev/tpu-pytorchrust-v5e1-2b-q4w4a16emb4 ./project-setup.sh . --project