Menu

FlashAttention on TPUs (splash_sdpa), Custom Verified Pallas Kernels & XProf in TorchTPU (Part 4)
📰

FlashAttention on TPUs (splash_sdpa), Custom Verified Pallas Kernels & XProf in TorchTPU (Part 4)

DEV Community: pytorch·Ahmed Elnaggar·1 day ago
#C6u6W9VY
#devtopytorch#devto#dev#torch#pallas
Long article (1299 words) — no AI summary yet.
Reading 0:00
15s threshold

Companion GitHub Repository: agemagician/torchtpu-zero-to-hero

12,115.8 MiB -> 610.5 MiB at 4K Context, and 1,221.0 MiB at 8K Where Standard Attention OOMs

At long context lengths ( S >= 4,096 ), materializing the quadratic [B, H, S, S] attention score matrix in off-chip High Bandwidth Memory (HBM) hits a memory-bandwidth wall and crashes single-chip 16 GiB TPUs with RESOURCE_EXHAUSTED .

On NVIDIA GPUs, you reach for FlashAttention and Triton . On Google Cloud TPUs with TorchTPU , you reach for:

torch.tpu.ops.splash_sdpa (Splash Attention): Google's hardware-tuned Pallas Sparse Flash Attention kernel exposed as a native differentiable PyTorch operator ( 6.39x faster and 19.8x less HBM at S = 4,096 on our live TPU v5e-1 benchmark!).

torch.tpu.pallas.jax_op + pallas.verifier.verify : Write custom VMEM-tiled Pallas kernels that trace Mosaic MLIR once on CPU ( JAX_PLATFORMS="cpu" ) and execute at zero runtime JAX cost directly on torch.Tensor buffers — backed by static contract, lowering, and autograd…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.