ML compiler engineers face an NP-hard layout-selection problem: deciding how tensors should be represented and where to convert between layouts. An Amazon paper formalizes the problem for Trainium and builds an exact solver, but its cost model produces a striking result on ResNet-50: the supposedly optimal layout takes 63.9 million cycles, while simple heuristic rules take 20.9 million. Ian tests a related decision in Triton’s RemoveLayoutConversions pass, which assigns conversions either zero cost for register-local permutations or a fixed, much larger cost for operations involving shuffles or shared memory. That rule substantially overestimates conversion costs - by about four times for fp32 and 19 times for fp16 relative to an elementwise add, and sometimes more for fp8.
Yet replacing the rough estimate with a more accurate model barely improves outcomes: across tested kernels, eight get slower, four faster, and nine do not change, with no tutorial kernels shifting. Rematerialization often avoids conversion altogether by recomputing or reloading data in the needed layout, and most kernels either require no layout choice or perform well with the default. The larger practical difficulty is that conversion choices interact with downstream compilation and hardware behavior that the model cannot reliably predict. In one matmul, changing instruction order made the kernel 15-26 times faster because ptxas altered register allocation and avoided memory spills. Thus, layout selection is formally hard, but the real challenge is estimating costs through a complex, partly closed compiler stack.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.