跳到正文
AI NEWS JOURNAL
PyTorch BlogAI NEWS / JOURNAL

TorchTLX

TL;DR TorchTLX brings architecture-specific TLX kernels and richer fusion capabilities into TorchInductor across NVIDIA (Hopper/Blackwell) and AMD (Instinct MI300X/MI350X/MI450X) GPUs. Integration: TorchTLX extends TorchInductor’s kernel selection and fusion capabilities, providing... The post TorchTLX appeared first on PyTorch.

翻译服务暂未运行,当前显示原文。

Featured projects TorchTLX brings architecture-specific TLX kernels and richer fusion capabilities into TorchInductor across NVIDIA (Hopper/Blackwell) and AMD (Instinct MI300X/MI350X/MI450X) GPUs. Integration: TorchTLX extends TorchInductor’s kernel selection and fusion capabilities, providing a faster path to leverage new GPU capabilities in torch.compile; Benchmarking: The presented benchmarks show up to 1.2x speedups from architecture-specific GEMM and attention templates and up to 1.5x from richer fusion; Scalability: Reusable templates and fusion mechanisms extend optimizations across workloads and accelerate next-gen GPU bring-up. Why TorchTLX Figure-1: why TorchTLX? Getting the most out of modern GPUs increasingly requires architecture-specific execution strategies. TLX lets us quickly expose new hardware capabilities and optimize specialized kernels, but incorporating those optimizations into PT2 requires deeper integration with TorchInductor. PT2 has traditionally focused on graph-level optimization while relying on Triton to provide competitive kernels underneath. As we push further on performance, the default kernel performance is no longer always enough. TLX, as a low-level extension of Triton, gives us a way to introduce architecture-specific optimizations without giving up the higher-level PT2 compiler stack. TorchTLX explores this middle ground: keeping most of PT2 hardware-agnostic while allowing performance-critical GEMM kernels and surrounding fusion patterns to specialize for each GPU architecture. It not only integrates architecture-specific TLX kernels as Inductor templates, but also extends fusion around them to capture more surrounding computation. Where TorchTLX Fits Topic 1. Hardware-specific vs Hardware-agnostic Where should specialization live? We believe PT2 should remain hardware-agnostic where it can, but high-performance GPU execution cannot be hardware-agnostic everywhere. Our design philosophy for TorchTLX is therefore to keep hardware specialization within a relatively narrow boundary behind ML compiler abstractions. Graph capture, most optimizations, and most scheduling stay in PT2/Inductor. Performance-critical kernels, template hooks, and selected fusion/scheduling decisions can specialize for Nvidia Hopper and Blackwell, AMD MI300x and MI350x, and future architectures. Topic 2. TorchTLX vs Triton Compiler Why do we need a specialization path? TorchTLX and the Triton compiler operate at different points in the optimization cycle. Architecture-specific capabilities are not always immediately available through the generic Triton compiler path. TLX gives kernel authors a fast path to use those capabilities directly. TorchTLX brings the same idea into PT2 so PyTorch users can benefit from them at the model level. TorchTLX both accelerates adoption of new hardware capabilities and provides a lasting home for optimizations that are better expressed through specialized templates. Topic 3. Agentic Kernel Optimization vs ML Compiler Optimization How do we discover and scale optimizations? Agentic kernel authoring is increasingly effective at optimizing a specific model or workload, especially when that workload justifies substantial optimization resources. But optimizing individual instances and building a scalable software stack are different problems. At a high level, this is a matter of exploration and generalization. We see the two as complementary: agents are well suited for exploring specific optimization opportunities, while reusable kernels and compiler mechanisms generalize recurring discoveries across workloads. The right level of generalization is ultimately an ROI-driven decision. It depends on the expected performance value and workload coverage relative to the engineering, validation, and maintenance costs. The goal is not to generalize every optimization, but to maximize its impact at scale. How to Get Started TorchTLX lives in fbtriton. It works through your existing torch.compile calls, so your model code does not change. Set TORCHINDUCTOR_TLX_MODE=allow to let TLX templates compete with ATen and stock Triton in autotuning, or force to use TLX templates wherever they are eligible. To try it, swap PyTorch’s Triton for fbtriton with a swap script, or keep stock Triton and install the triton-utlx plugin. Contributors can check correctness with the L1 tests (test_torchtlx_*.py) and measure performance with the L2 template benchmarks (bench_torchtlx_*.py) and fusion benchmarks (run_torchtlx_fusions.py) in the fbtriton repo. Integration with Inductor Architecture-specific kernels, template selection, fusion, scheduling, and code generation are introduced through Inductor extension points and FBTriton integration hooks, while graph capture and the overall compilation pipeline remain unchanged. Figure-2: Integration with Inductor TorchTLX Templates TorchTLX integrates architecture-specific TLX kernels into TorchInductor through Jinja templates. In “allow” mode, eligible templates compete with ATen (cuBLAS/hipBLASLt) and stock Triton candidates. Eligibility is gated by architecture, dtype, layout, alignment, and shape. TorchTLX covers GEMM (mm/addmm/bmm) and FlexAttention (forward/backward) across NVIDIA Hopper/Blackwell and AMD MI300x/MI350x, with architecture-dependent specialization. Templates bring architecture-specific algorithms and configurations into Inductor through shape heuristics, autotuning, and offline-tuned parameters. For example, the Hopper FlexAttention backward template (#4349) combines dK/dV and dQ computation in one CTA per batch/head for short queries, avoiding redundant K/V reads. TorchTLX also extends to next-generation GPUs such as AMD MI450x. Its architecture-specific TLX FlashAttention kernel (#4771) is integrated into TorchInductor through the existing FlexAttention template hooks (#4772), supporting FP16/BF16 forward attention with sparse masks and score modifications. This demonstrates how new GPU capabilities can be brought into torch.compile through reusable compiler integration mechanisms. Figure-3: template performance TorchTLX Fusions TLX template integration is just the starting point. The larger opportunity comes from extending Inductor fusion to better exploit architecture-specific execution, scheduling, and on-chip data reuse. TorchTLX extends fusion at several levels: from standard pointwise epilogue fusion to architecture-aware store fusion, schedule-aware fusion, cross-phase on-chip retention, and reduction-aware computation. The following subsections walk through these mechanisms and how the compiler selects them safely and profitably. Epilogue Fusion with Arch-specific Store When a TorchTLX template writes through tl.store, downstream pointwise operations can be fused through Inductor’s existing store_output path out of the box. TorchTLX extends Inductor’s code generation with a compute_epilogue hook, allowing Inductor to generate fused epilogue computation while the TLX template retains control of SMEM staging, synchronization, and asynchronous stores. Figure-4: Blackwell GEMM epilogue timeline and generated code The figure illustrates relu(a @ b + bias) on Blackwell. After loading each accumulator subtile from TMEM into registers, the epilogue warps signal that the corresponding TMEM storage can be reused. Inductor-generated code computes bias addition and ReLU, while the TLX template stages the result through a double-buffered SMEM pipeline and issues asynchronous TMA stores. This allows the MMA pipeline to advance without waiting for the complete epilogue and output-store sequence. The key is to separate ownership of the fused computation from ownership of the hardware-specific execution pipeline, enabling richer fusion without sacrificing architecture-specific scheduling and data movement. Schedule-aware Fusion Fusion doesn’t have to happen only after GEMM finishes. For example, #3855 adds an optional pre-drain prefetch hook to the MI350x warp-pipelined GEMM TLX template. It moves an accumulator-independent epilogue operand load ahead of the drain, overlapping the global-memory latency with the remaining NUM_BUFFERS-1 MFMA drain iterations. Figure-5: Pre-drain epilogue prefetch on MI350x This shows that compiler-visible fusion can shape scheduling inside an architecture-specific kernel, not just append computation to its output. Cross-phase On-chip Retention Fusion can also cross reduction phases. In the double-LayerNorm pattern below, the intermediate z is consumed by the second LayerNorm both before and after its row reduction. z = residual + layer_norm(x, ...) return z * sigmoid(layer_norm(z, ...)) TorchTLX can retain z in on-chip storage (AMD LDS #3526 or NVIDIA SMEM #3592) across that reduction instead of writing it to HBM and loading it back. By turning producer => HBM store => reduction => HBM load => consumer to producer => SMEM/LDS store => reduction => CTA-level synchronization => SMEM/LDS load => consumer, TorchTLX can retain data across a compiler-visible phase boundary rather than simply extending the computation attached to a GEMM output. Figure-6: Cross-phase SMEM retention on H100 For the illustrated H100 workload, retaining z in SMEM eliminates its 12 MiB global-memory write and subsequent 12 MiB read, reducing kernel time from 48.6 μs to 36.5 μs (1.33x speedup). The retained kernel competes with the original implementation through Inductor’s MultiKernel selection. This extends compiler-level fusion beyond individual operations to data lifetime management across execution phases, allowing intermediate values to remain on-chip when profitable. From Pattern-specific Prototypes to Generic Reduction TorchTLX also supports a pattern-specific path by replacing a subgraph with a semantic custom op and lowering it to TLX subgraph templates. We limit this path to prototyping new fusion ideas, opportunity sizing, or occasionally filling gaps that are difficult to express through the generic fusion path. Reusable template hooks and fusion mechanisms are how we want TorchTLX to scale. For example, #3752 used this approach to explore addmm+LayerNorm/RMSNorm on MI350x, computing partial normalization statistics in the GEMM epilogue while the accumulators were still live. The prototype achieved up to ~1.17× speedup for addmm+LayerNorm. #4036 then generalized this approach by recognizing GEMM outputs consumed by full-row sum or Welford reductions directly from Inductor Loop IR. Instead of relying on semantic custom ops, regular GEMM TLX templates use opt-in epilogue hooks to write both the GEMM output and per-row FP32 partial statistics. A generated consumer combines these partials and finishes the normalization. The same mechanism was later extended to MI300x SwishWithNorm (#4386). This progression illustrates how pattern-specific exploration can lead to reusable compiler-level fusion mechanisms. Figure-7: Reduction-aware GEMM epilogue: row statistics during GEMM execution Fusion-aware Selection and Safe Fallback Making fusion available is only the first step. The compiler must also determine when fusion is profitable and safe. A specialized GEMM may lose to a vendor library in isolation but win once surrounding operations are fused into its epilogue. On MI300x, TorchTLX enables fusion-aware selection in allow mode without requiring max_autotune, comparing fused execution against the unfused alternative. For a DCN workload, this improves the K=256 case from 1.00x to 1.33x by selecting the fused TLX kernel instead of unfused hipBLASLt (#4245). For unfused GEMMs, isolated autotuning can misrank closely competing candidates due to cache effects. TorchTLX re-benchmarks the leading TLX kernel against the vendor-library GEMM under warm-cache conditions, selecting TLX only with at least a 3% speedup. This check applies only to unfused GEMMs: applying a global margin would also affect fusion-aware selection, reducing the K=512 fusion win from 1.47x to 1.05x (#4627). Fusion must also respect intermediate tensor lifetimes. On Blackwell and Hopper, TorchTLX rejects fusion into warp-specialized GEMMs when their asynchronous store path would leave an intermediate tensor unmaterialized despite remaining live outside the fused group (#4250). Figure-8: Fusion-aware selection and safe fallback Figure-9: Fusion performance of demonstrated examples Conclusion TorchTLX brings architecture-specific TLX kernels and the fusion around them into TorchInductor, and the rest of PT2 stays hardware-agnostic. With it, new GPU capabilities reach torch.compile users quickly, and optimizations that recur across workloads become reusable compiler mechanisms instead of per-model kernels. Appendix: Performance Disclosure Performance results were collected at various stages of TorchTLX development using development builds of PyTorch and Triton/TLX. The following configurations reflect representative hardware settings and TLX.ops reference software versions as of November 30, 2026, rather than the exact historical TorchTLX benchmark environments. NVIDIA B200: CUDA 13.0, cuBLAS/cuBLASLt 13.1.1.3, 750 W power limit, maximum GPU core clock. NVIDIA H100: CUDA 13.0, cuBLAS/cuBLASLt 13.1.1.3, 700 W power limit, maximum GPU core clock. AMD Instinct MI350X: ROCm 7.2, hipBLASLt 1.2.2, 1000 W power limit, 2100 MHz GPU core clock. AMD Instinct MI300X: ROCm 7.2, hipBLASLt 1.2.2, 750 W power limit, 2100 MHz GPU core clock. The benchmark harness targets the above clock and power settings where supported and permitted. Benchmark scripts, workload shapes, reference implementations, and compiler configurations are available in the TLX repository. Unless otherwise specified, aggregate speedups represent the geometric mean of per-shape speedups, and “up to” speedups represent the maximum observed single-shape speedup. Performance may vary with hardware configurations, software versions, compiler configurations, and workload characteristics.

资料来源

阅读原文 ↗

相关主题

← 继续阅读全部动态