How We Built TLX: A Hardware-Native GPU Compiler for Production ML at Scale
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
Title: How We Built TLX: A Hardware-Native GPU Compiler for Production ML at Scale 标题:我们如何构建 TLX:用于大规模生产机器学习的硬件原生 GPU 编译器
By Hongtao Yu, Peng Chen, Daohang Shi, Nick Riasanovsky, Lei Wang, Partha Kanuparthy Triton Low-Level Extensions (TLX), is an extension to Triton that helps engineers optimize GPU performance while preserving Triton’s productive programming model. TLX introduces explicit warp-group and cluster-level orchestration, letting developers adopt new hardware capabilities without sacrificing velocity. TLX has demonstrated performance improvements in RecSys training, RecSys inference, and large-scale LLM pretraining. 作者:Hongtao Yu, Peng Chen, Daohang Shi, Nick Riasanovsky, Lei Wang, Partha Kanuparthy。Triton 低级扩展 (TLX) 是 Triton 的一个扩展,旨在帮助工程师在保持 Triton 高效编程模型的同时优化 GPU 性能。TLX 引入了显式的线程束组(warp-group)和集群级编排,让开发人员能够在不牺牲开发速度的情况下采用新的硬件功能。TLX 已在推荐系统训练、推荐系统推理以及大规模大语言模型预训练中展现出性能提升。
Modern GPU architectures increasingly rely on execution-oriented features such as warp specialization, asynchronous memory movement, tensor memory, and cluster-level execution to optimize their performance. But these same features also expose a growing gap between low-level programming models for control and high-level programming models for productivity. To bridge this gap, we built Triton Low-Level Extensions (TLX), an extension that gives engineers explicit control over GPU execution while preserving Triton’s productive programming model. 现代 GPU 架构越来越依赖于以执行为导向的功能(如线程束特化、异步内存移动、张量内存和集群级执行)来优化性能。但这些功能也暴露了用于控制的低级编程模型与用于生产力的高级编程模型之间日益扩大的差距。为了弥合这一差距,我们构建了 Triton 低级扩展 (TLX),这是一个让工程师能够显式控制 GPU 执行,同时保留 Triton 高效编程模型的扩展。
Today, TLX powers production workloads across Meta, from AI training to large-scale LLM pretraining, enabling engineers to adopt new hardware capabilities quickly without sacrificing developer velocity. Across NVIDIA and AMD GPUs, TLX is pushing the frontier of GPU performance — combining state-of-the-art kernels with explicit execution orchestration and model-aware fusion to deliver end-to-end improvements beyond what standalone libraries can achieve. 如今,TLX 为 Meta 的生产工作负载提供支持,涵盖从 AI 训练到大规模大语言模型预训练的各个领域,使工程师能够快速采用新的硬件功能,而不会牺牲开发速度。在 NVIDIA 和 AMD GPU 上,TLX 正在推动 GPU 性能的极限——将最先进的内核与显式执行编排和模型感知融合相结合,从而实现超越独立库所能达到的端到端性能提升。
From AI Models to GPU Kernels To understand where TLX fits, it helps to trace the path from an AI model to the GPU instructions that ultimately execute it. At Meta, machine learning (ML) workloads are built on a common software stack centered around PyTorch. Model code is transformed through graph capture, optimization, compilation, and lowering before eventually becoming GPU kernels running across large accelerator fleets. 从 AI 模型到 GPU 内核:要了解 TLX 的定位,追踪从 AI 模型到最终执行它的 GPU 指令的路径会有所帮助。在 Meta,机器学习 (ML) 工作负载构建在以 PyTorch 为中心的通用软件栈之上。模型代码通过图捕获、优化、编译和降级进行转换,最终成为在大型加速器集群上运行的 GPU 内核。
Over the past several years, Triton has evolved from an experimental kernel language into a foundational component of this stack. A significant share of production GPU kernels — both compiler-generated and hand-optimized — are now implemented in Triton. Improvements at this layer can therefore propagate broadly across training and inference workloads, making kernel performance an increasingly important lever for improving end-to-end system efficiency. 在过去几年中,Triton 已从一种实验性内核语言演变为该软件栈的基础组件。目前,很大一部分生产 GPU 内核(包括编译器生成的和手动优化的)都是用 Triton 实现的。因此,这一层的改进可以广泛传播到训练和推理工作负载中,使得内核性能成为提高端到端系统效率日益重要的杠杆。
Figure 1: Normalized kernel count growth at Meta over a 10-month period (start = 1.0 in month 1). Over this period, Triton kernel count grew ~3.8x compared with ~2.0x for CUDA, reflecting Triton’s rapidly expanding role in Meta’s GPU software stack. This shift has also changed who writes kernels. Kernel optimization is no longer the exclusive domain of GPU specialists. 图 1:Meta 在 10 个月期间的归一化内核数量增长(第 1 个月起点 = 1.0)。在此期间,Triton 内核数量增长了约 3.8 倍,而 CUDA 增长了约 2.0 倍,这反映了 Triton 在 Meta GPU 软件栈中日益扩大的作用。这种转变也改变了编写内核的人员构成。内核优化不再是 GPU 专家的专属领域。
ML engineers routinely profile workloads, identify bottlenecks, and optimize the hottest kernels through autotuning, fusion, memory-layout improvements, or algorithmic restructuring. Triton’s productivity allows many of these iterations to happen in hours rather than days, enabling engineers to stay close to the model-development workflow. As a result, GPU kernel development has increasingly become part of the standard optimization toolkit for ML engineers. 机器学习工程师经常对工作负载进行性能分析,识别瓶颈,并通过自动调优、融合、内存布局改进或算法重构来优化最关键的内核。Triton 的生产力使得许多此类迭代可以在数小时而非数天内完成,使工程师能够紧跟模型开发工作流。因此,GPU 内核开发已日益成为机器学习工程师标准优化工具包的一部分。
Triton already provides a productive foundation for many memory-bound workloads through fusion and compiler-managed memory-access optimizations. Building on these strengths, TLX addresses a complementary challenge: coordinating execution groups, asynchronous data movement, and shared resources on modern GPUs. Triton 已经通过融合和编译器管理的内存访问优化,为许多内存受限的工作负载提供了高效的基础。在这些优势的基础上,TLX 解决了一个互补的挑战:在现代 GPU 上协调执行组、异步数据移动和共享资源。
The Problem: When Hardware Evolves Faster Than Programming Models While Triton dramatically improved developer productivity, modern GPU architectures have evolved in ways that place increasing emphasis on execution orchestration rather than computation alone. NVIDIA’s Hopper introduced warp specialization and the Tensor Memory Accelerator (TMA). NVIDIA’s Blackwell GPU expanded this trend further with Tensor Memory (TMEM), cluster-level execution, paired-CTA execution, and increasingly asynchronous execution mechanisms. 问题:当硬件进化速度超过编程模型时。虽然 Triton 极大地提高了开发人员的生产力,但现代 GPU 架构的演进方式越来越强调执行编排,而不仅仅是计算。NVIDIA 的 Hopper 架构引入了线程束特化和张量内存加速器 (TMA)。NVIDIA 的 Blackwell GPU 通过张量内存 (TMEM)、集群级执行、配对 CTA 执行以及日益增加的异步执行机制进一步扩展了这一趋势。
These capabilities are not simply new instructions that can be hidden behind compiler optimizations, they fundamentally change how high-performance kernels are organized. For example, a modern FlashAttention kernel may dedicate one warp group to issuing TMA transfers while another executes tensor-core computation. A Blackwell GEMM kernel may coordinate multiple warp groups, TMEM allocations, and cluster resources simultaneously. 这些功能不仅仅是可以隐藏在编译器优化背后的新指令,它们从根本上改变了高性能内核的组织方式。例如,现代 FlashAttention 内核可能会分配一个线程束组来发出 TMA 传输,而另一个线程束组则执行张量核心计算。Blackwell GEMM 内核可能会同时协调多个线程束组、TMEM 分配和集群资源。
In both cases, performance depends not only on the computation being performed, but also on how multiple execution agents cooperate. As we adopted Hopper and Blackwell across Meta’s ML infrastructure, we repeatedly encountered the same challenge: CUDA could express these execution structures, but doing so often required large amounts of architecture-specific orchestration code. 在这两种情况下,性能不仅取决于所执行的计算,还取决于多个执行代理如何协作。随着我们在 Meta 的机器学习基础设施中采用 Hopper 和 Blackwell,我们反复遇到同样的挑战:CUDA 可以表达这些执行结构,但这样做通常需要大量的架构特定编排代码。
Triton provided a dramatically more productive programming model, but many of the execution relationships required by modern hardware remained hidden behind compiler abstractions. The result was a growing compiler catch-up problem. Each new hardware generation introduced new execution capabilities, while programmers either waited for compiler support to arrive or dropped into increasingly specialized implementations. We realized that the challenge was not simply missing compiler features, it was the absence of an appropriate programming abstraction. Triton 提供了一种效率高得多的编程模型,但现代硬件所需的许多执行关系仍然隐藏在编译器抽象之后。结果导致编译器追赶硬件的问题日益严重。每一代新硬件都引入了新的执行功能,而程序员要么等待编译器支持,要么转向日益专业化的实现。我们意识到,挑战不仅仅是缺少编译器功能,而是缺乏一种合适的编程抽象。
The Missing Middle: Why SIMT and SIMB Weren’t Enough The capabilities that matter most on recent GPUs operate neither at thread granularity nor at block granularity. Warp specialization partitions work across cooperating warp groups. TMA introduces dedicated agents for memory movement. TMEM enables new communication patterns between execution groups. Cluster execution lets multiple CTAs cooperate within a shared execution context. Organizing a kernel around these features means reasoning about how several execution agents cooperate, communicate, and s 缺失的中间层:为什么 SIMT 和 SIMB 不够用。近期 GPU 上最重要的功能既不是在线程粒度上运行,也不是在块粒度上运行。线程束特化将工作划分给协作的线程束组。TMA 引入了专用的内存移动代理。TMEM 实现了执行组之间新的通信模式。集群执行允许多个 CTA 在共享的执行上下文中协作。围绕这些功能组织内核意味着需要推理多个执行代理如何协作、通信以及 s