A solver for the CayleyPy Professor Tetraminx competition—finding shortest solutions to 1000 scrambled puzzles—was ported from CUDA and JAX to the new TorchTPU backend. The port was a real-world test: could a PyTorch-native TPU stack match or beat an A100 pipeline and a highly-optimised JAX beam search, using a transformer-based neural heuristic?
The short answer: yes, but only after some serious work. The initial TorchTPU training run was 1.65x slower than the A100, and the first TPU beam search was 5.7x slower than JAX. After a series of optimisations—rewriting attention, eliminating dynamic tensor shapes, and switching execution modes—TorchTPU training matched the A100, and the beam search ran 25% faster per level than JAX on an eight-chip v6e machine, with identical solution quality.
What TorchTPU changes about PyTorch on TPUs
TorchTPU is not just PyTorch/XLA. It lowers ATen ops directly to StableHLO, running through PJRT and libtpu. You get a native "tpu" device string, and no more xm.mark_step() or xla_device() calls. There are three execution modes:
- Eager (default): one op at a time, asynchronously.
- Fused eager: set
TORCH_TPU_DEFER_AND_FUSE=1to fuse ops without code changes. - Compiled: use
torch.compile(fn, dynamic=False)for graph compilation.
Static shapes are critical. With the tested TorchTPU builds, each new tensor shape triggers a full recompile, and ops with data-dependent output sizes (like , , , , or ) run eagerly and force expensive host round-trips. If you hit an unimplemented op, TorchTPU raises immediately—no silent CPU fallback.




