The fastest isolated GEMM can lose inside a model graph when an intervening write and read cost more than it saves. TorchTLX makes architecture-specific TLX templates available to TorchInductor and lets the compiler compare the cost of executing adjacent operations together.

Meta Contributors: Daohang Shi, Hongtao Yu, Doris Xiang, Lei Wang, Peng Chen, Marvin Fan, Jason Lu, Alexey Loginov · AMD Contributors: Nithin Meganathan, Bangtian Liu, Ivan Butygin, Stanley Winata, Lei Zhang · 2026-12-01 · TorchTLX

When a template is eligible

In allow mode, architecture, dtype, layout, alignment and shape gate eligibility. Matching GEMM or FlexAttention templates compete with ATen vendor-library and stock Triton candidates inside the existing graph-capture pipeline. A Hopper backward-attention template, for example, computes multiple gradient components in one CTA per batch/head for short queries, avoiding repeated K/V reads. Eligibility depends on the query shape as well as the operation.

The columns align compiler stages and existing Inductor hooks with TorchTLX template and fusion additions.View original ↗

The columns align compiler stages and existing Inductor hooks with TorchTLX template and fusion additions.

Fusion changes when data moves

The compiler knows which operations consume each value. The template knows the hardware pipeline. On MI350x, an epilogue operand independent of the accumulator can be prefetched before the pipeline drains, overlapping its global-memory latency with remaining compute. If an intermediate remains live outside a fusion group and a specialized asynchronous store would leave it unmaterialized, the compiler rejects that fusion. Scheduling and tensor lifetime both constrain the choice.

Why fused and standalone choices need different gates

Standalone GEMMs rerun the leading TLX and vendor choices with warm caches and require a 3% advantage to select TLX. Fused candidates compete against the entire unfused sequence. In a DCN example on MI300x at K=256, selecting the fused template raised the ratio from 1.00 to 1.33. Applying the standalone margin globally would cut the K=512 fusion gain from 1.47 to 1.05 times. TLX.ops explains how to implement a kernel for a given shape. TorchTLX addresses the distinct question of when a specific graph should use it.

Two 12 MiB transfers for one intermediate

In a double-LayerNorm example, the sum of a residual and the first normalization output is used on both sides of a second row reduction. Fusing only neighboring elementwise operations would still send this intermediate to HBM. TorchTLX retains it in shared memory across the reduction and CTA synchronization. The H100 example avoided a 12 MiB write and a 12 MiB read, reducing kernel time from 48.6 to 36.5 microseconds. The original implementation remains available during selection. The concrete evidence is the avoided off-chip transfer, beyond the number of eliminated launches.