ML compiler eng, your job is NP-hard A paper from Amazon, "Tensor Seeks Layout," proves that layout selection for ML compilers is NP-hard even when each operator has only a constant number of inputs and each tensor admits only a small number of layouts. Independent experiments by Ian Barber on Triton's RemoveLayoutConversions pass found the compiler's heuristic overestimates conversion cost by about 4x for fp32 and 19x for fp16 relative to an elementwise add, yet swapping in a proper cost model changed little: of 21 kernels tested, 8 were slower, 4 faster and 9 unchanged. Barber attributes the remaining performance gaps to ptxas register allocation, citing one matmul that ran 15–26x faster purely from instruction ordering. I mean, sorta. From the Tensor Seeks Layout paper https://arxiv.org/abs/2608.21555v1 from Amazon: Layout Selection is NP-hard even when each operator has only a constant number of inputs and each tensor admits only a small number of layouts, and hardness persists in restricted settings that resemble common matmul-heavy graphs. The paper is very focused on formal analysis of the layout problem, for Trainium workloads. They build a layout selection exact solver, and on ResNet-50 they find the proven optimum using their cost model takes 63.9M cycles. In contrast, the awkward heuristic rules take… 20.9M cycles. The authors attribute this to a wonky cost model, which we will come back to. There has been a lot https://arxiv.org/abs/2603.02298 of work https://arxiv.org/pdf/2601.05972 in recent months on what layouts actually are , but this paper is about where and when you do conversions between them. To jump down a level of granularity, in the Triton compiler this decision is mainly handled by the RemoveLayoutConversions pass: during compilation, Triton throws in layout conversions every time one might be needed, and this pass prunes them. It has the very sophisticated rule that conversions either cost 0 or 32xbytes . “0” means the conversion is a register permute, where everything happens locally. The higher value is for shuffles and shared memory round trips. This made me wonder how wrong the rule actually was, versus the more structured approach in Amazon’s paper. I ran some experiments https://github.com/ianbarber/experiments/tree/main/2026-11-21-triton-layout-cost-weights and found, yeah, the heuristic is pretty wrong. Relative to an elementwise add, the heuristic overestimates by about 4x for fp32, 19x for fp16, and sometimes even more for fp8. If you update to use the proper cost model though, not a lot changes. No tutorial kernels shift, and in general the performance changes are a bit of a wash: in testing 8 were slower, 4 were faster, 9 didn’t change at all. The main reason is rematerialization: instead of converting the layout, walk back up the chain and recompute or load in the format you actually need. Conversions are mostly about cases where you can only emit one way, and then consume a different way. In those cases, the layout picks are arbitrary