GoogleIvan Nardini, Spencer PetersonTutorial
Run Ray on TPU, Part 2: Ray AI libraries
Summary
Running Ray on TPUs requires multi-host workloads to remain on one intact TPU slice whose hosts share a high-speed ICI link. This guide presents Ray's AI libraries on top of GKE and Ray Core: Ray Serve for serving, Ray Data's iter_jax_batches() for input pipelines and batch inference, and Ray Train's JaxTrainer for distributed JAX training. Serve uses accelerator_config.topology to defer slice placement to the replica, while iter_jax_batches() returns device-sharded JAX arrays and handles ragged final batches through drop, pad, or raise choices. JaxTrainer takes a training function and slice topology, launches one worker per host, and provides checkpointing, fault-tolerant restarts, and multi-slice scale-out; official TPU images and dashboard metrics round out the workflow.
Context
Multi-host TPU models must land on one whole slice because workers on different slices cannot communicate over the ICI; otherwise jobs can hang. TPU input pipelines can also become bottlenecks when data loading does not keep the accelerators fed, while training previously required accounting for slice topology in application code.
Approach / What changed
Use GKE with the Ray Operator and Ray Core's slice_placement_group() to reserve a declared TPU topology, then configure Ray Serve with accelerator_config.topology, Ray Data with iter_jax_batches(), or Ray Train with JaxTrainer, use_tpu=True, and a topology. The guide also recommends RayService for production serving and describes official -tpu images and dashboard and profiler support.
Takeaways
Without accelerator_config.topology, Serve can place per-chip bundles across separate slices, leaving a multi-host deployment stuck in DEPLOYING because the workers cannot complete their first collective.
JAX should be imported inside train_loop_per_worker because each worker initializes JAX in its own TPU context; JaxTrainer's topology value describes the slice shape, not a chip count.
Official Ray TPU images include the JAX/TPU stack and profiling tools, while the Ray Dashboard shows TPU utilization and memory and can attach to per-worker JAX profiling.
Source and freshness
- Source
- developers.googleblog.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.