From CUDA and Jax to TorchTPU: Lessons from a Cayley Graph Solver andlukyane.com...

@best

From CUDA and Jax to TorchTPU: Lessons from a Cayley Graph Solver andlukyane.com · 30 points · 0 comments · HN thread

TL;DR The author ports a Cayley-graph puzzle solver (a 3.4M-parameter transformer-guided beam search for Professor Tetraminx) from an A100 with CUDA and JAX to Google's new TorchTPU backend. After optimizing eager execution, attention layout, deduplication and an attention-routing regression, TorchTPU training matches or slightly beats the A100 per epoch, and its beam search runs 25% faster per level than JAX on eight v6e chips at the same solution length.

  • Initial TorchTPU training port was 1.65x slower than the A100 (234.8 s vs 142.7 s per epoch on four v6e chips); fused eager mode and an einsum attention rewrite brought it to 132 s, 1.08x faster.
  • Attention at 51 tokens with head size 32 uses about 2.5% of the TPU matrix unit and accounted for roughly 90% of model time, while being about 3% of FLOPs.
  • Data-dependent ops (masked_select, unique, boolean indexing) and .item() reads were removed to keep graphs static; a checkpoint save from rank 0 deadlocked under fused eager with DDP until tensors were materialized on all ranks.
  • A beam-search dedup bug was exposed when TorchTPU changed topk/sort tie order; keeping the best-scored duplicate via segment-min fixed a loss of 8 moves on one set of puzzles.
  • TorchTPU 0.2.0 routed short attention shapes to a Flash kernel that padded 51 tokens to 128, making a beam level 1.7x slower; disabling Flash fixed it, and the issue was closed by TorchTPU fixes on November 21.
  • On eight v6e chips, TorchTPU with Flash off ran 1.02 s per beam level vs JAX's 1.27 s with the same 185 total moves; on Kaggle's v5e-8 it was about 10% faster per level but found 186 moves vs 185.

Discussion No comments yet, so there is no discussion thread to summarize. The post was submitted with 30 points and has not yet drawn replies.

#TorchTPU #PyTorch #TPU #JAX #CUDA