Accelerated Linear Algebra
XLA, short for Accelerated Linear Algebra, is a domain-specific compiler that lowers machine-learning models into optimized executables for central processors, graphics processors and specialised accelerators.XLA 是 Accelerated Linear Algebra 的缩写,是一款领域特定编译器,把机器学习模型降级为面向中央处理器、图形处理器与专用加速器的优化可执行体。
It sits beneath the major machine-learning frameworks rather than in front of the user, taking their computation graphs through a shared intermediate representation and retargeting them across many kinds of hardware without framework-specific hand work.它位于主流机器学习框架之下而非呈现给用户,把框架的计算图送入共享的中间表示,并在多种硬件之间重新定向,无需针对框架逐一手工调优。
Features
- The compiler takes a model graph expressed in StableHLO and produces machine instructions, using a versioned high-level operation set as the portability layer between frameworks and the compiler.该编译器接收以 StableHLO 表达的模型图并生成机器指令,用一个带版本的高层操作集充当框架与编译器之间的可移植层。
- An early target-independent stage applies common subexpression elimination, operation fusion and buffer analysis to the graph, and rewrites the StableHLO dialect into XLA's own internal HLO dialect.靠前的与目标无关的阶段对图施加公共子表达式消除、操作融合与缓冲区分析,并把 StableHLO 方言重写成 XLA 自有的内部 HLO 方言。
- A backend then runs HLO-level optimizations that use target-specific knowledge, for instance fusing operations that suit the graphics-processor programming model or partitioning the computation into streams.随后由后端执行利用目标特定知识的 HLO 级优化,例如融合契合图形处理器编程模型的操作,或把计算切分成多个流。
- At that stage backends may also pattern-match operations or their combinations onto calls into optimized vendor libraries instead of emitting them afresh.在该阶段,后端还可以把操作或其组合模式匹配到经优化的厂商库调用上,而不必重新生成这些操作。
- The CPU and GPU backends that ship with XLA lower to LLVM for low-level intermediate representation, optimization and native code emission.XLA 自带的 CPU 与 GPU 后端降级到 LLVM,用于低层中间表示、优化与本地代码生成。
- The compiler is modular by design so that an alternative backend can be slotted in to target a novel hardware architecture, and the graphics-processor backend reaches NVIDIA GPUs through the LLVM NVPTX path while the CPU backend covers several instruction-set architectures.该编译器在设计上模块化,便于接入替代后端以面向新型硬件架构,其图形处理器后端经 LLVM 的 NVPTX 路径支持 NVIDIA 的 GPU,而 CPU 后端覆盖多种指令集架构。
- StableHLO is the versioned operation set that serves as the portable input format, and it can be serialized into MLIR bytecode to carry compatibility guarantees across compilers and frameworks.StableHLO 是充当可移植输入格式的带版本操作集,可序列化为 MLIR 字节码,从而在编译器与框架之间携带兼容性保证。
- Those compatibility guarantees run to five years of backward compatibility and two years forward, a span aimed at long-lived server and edge deployments with annual update cycles.这些兼容性保证达到五年向后兼容、两年向前兼容,这一跨度面向需要长期运行并每年更新的服务器端与边缘部署。
- A reference interpreter for StableHLO offers both C++ and Python interfaces, supports static and dynamic operations, and underpins the testing and vendor-integration workflow.面向 StableHLO 的参考解释器同时提供 C++ 与 Python 接口,支持静态与动态操作,并支撑起测试与厂商集成流程。
- Extensibility comes through composite operations and custom calls, letting a developer express vendor-specific primitives in kernel languages such as CUDA, HIP, SYCL or Triton.可扩展性来自复合操作与自定义调用,让开发者能用 CUDA、HIP、SYCL 或 Triton 等内核语言表达厂商特定的原语。
- PJRT supplies a uniform device application programming interface so that different backends connect to the compiler through a consistent C interface, and ready plugin examples exist for Apple Metal, CUDA, Intel GPUs and Tensor Processing Units.PJRT 提供统一的设备应用程序接口,使不同后端经一致的 C 接口接入编译器,并为 Apple Metal、CUDA、Intel 的 GPU 与张量处理单元提供了现成的插件范例。
- Shardy is an MLIR-based system for describing and transforming models that run across distributed or multi-device environments, rounding out the multi-device side of the stack.Shardy 是一个基于 MLIR 的系统,用于描述与变换运行在分布式或多设备环境中的模型,补齐了整套技术栈的多设备一侧。
- XProf, a profiling and analysis tool maintained alongside the compiler, helps developers find where time and memory go inside compiled programs.XProf 是与编译器一同维护的性能剖析与分析工具,帮助开发者查明已编译程序中时间与内存的去向。
- Whole-model optimizations include simplification of algebraic expressions, optimization of in-memory data layout and improved scheduling that lowers peak memory use and communication overhead.整模型优化包括化简代数表达式、优化内存中的数据布局,以及降低峰值内存占用与通信开销的改进调度。
- Advanced operator fusion and kernel generation lift device utilization and cut memory bandwidth demand, so the same model runs faster without hand-written device code.高级操作融合与内核生成提升设备利用率并削减内存带宽需求,使同一模型无需手写设备代码即可跑得更快。
- Automatic parallelization through the GSPMD machinery lets a developer annotate only a subset of critical tensors, after which the compiler generates a partitioned computation across many hosts and accelerators.通过 GSPMD 机制实现的自动并行让开发者只需标注一部分关键张量,之后编译器便生成跨众多主机与加速器切分的计算。
- A StableHLO quantizer provides framework-agnostic and device-agnostic rewriting toward lower numerical precision, easing the move to quantized execution.StableHLO 量化器提供与框架、设备都无关的重写以走向更低的数值精度,简化了转向量化执行的过程。
- The project is a compiler core rather than a model-authoring library, so users normally reach it through a host framework and must look to that framework for the end-user interface.该项目是编译器核心而非模型编写库,因此用户通常经由宿主框架使用它,终端界面须依赖相应框架提供。
History
- XLA began inside Google's TensorFlow as the compilation path that could turn TensorFlow graphs into faster code for a widening set of devices.XLA 起初位于谷歌的 TensorFlow 之内,作为能把 TensorFlow 图转换为更快代码、并面向越来越多设备的编译路径。
- Once made public it was adopted beyond TensorFlow, and the accelerator vendor Graphcore has said its IPU compiler pipeline has used XLA since it was released.公开之后它被 TensorFlow 之外的场景采纳,加速器厂商 Graphcore 曾表示其 IPU 编译器流水线自 XLA 发布起就一直使用它。
- The code was later consolidated into a standalone repository, openxla/xla, whose GitHub creation record is dated 2022-08-09.相关代码后来被整合进独立仓库 openxla/xla,其 GitHub 创建记录日期为 2022-08-09。
- The OpenXLA Project was made available on 2023-03-08, gathering the XLA, StableHLO and IREE repositories under a single open machine-learning compiler ecosystem.OpenXLA 项目于 2023-03-08 上线可用,把 XLA、StableHLO 与 IREE 三个仓库收拢到同一个开放的机器学习编译器生态之下。
- That launch was co-developed by a roster of industry organisations including Alibaba, Amazon Web Services, AMD, Anyscale, Apple, Arm, Cerebras, Google, Graphcore, Hugging Face, Intel, Meta, NVIDIA and SiFive.该次发布由一批产业机构共同开发,包括阿里巴巴、亚马逊云科技、AMD、Anyscale、Apple、Arm、Cerebras、谷歌、Graphcore、Hugging Face、Intel、Meta、NVIDIA 与 SiFive。
- A named founding team, drawn from Google's machine-learning organisation, included Eugene Burmako, James Rubin, Magnus Hyttsten, Mehdi Amini, Navid Khajouei and Thea Lamkin.一支具名的创始团队出自谷歌的机器学习部门,成员包括 Eugene Burmako、James Rubin、Magnus Hyttsten、Mehdi Amini、Navid Khajouei 与 Thea Lamkin。
- At the 2023 launch the project stated that through that year it intended to work with the PyTorch team to align the compiler with the then-new PyTorch 2.0 release.在 2023 年的发布会上,项目表示当年打算与 PyTorch 团队协作,使编译器与当时新出的 PyTorch 2.0 版本对齐。
- A second public milestone followed on 2024-05-09 with the OpenXLA Dev Lab, a hands-on event that drew practitioners from hardware vendors and infrastructure teams.第二个公开里程碑出现在 2024-05-09,即 OpenXLA Dev Lab,一场吸引硬件厂商与基础设施团队从业者参与的手把手活动。
- The ecosystem widened over time beyond the original three repositories, with profiling, partitioning and benchmarking components such as XProf, Shardy and Tokamax added under the same umbrella.这一生态随时间在最初三个仓库之外扩大,XProf、Shardy 与 Tokamax 等剖析、切分与基准组件被加入到同一伞下。
- The official site has described the effort as an open ecosystem of performant, portable and extensible machine-learning infrastructure components that defragment the tools between front-end frameworks and hardware backends.官方站点把这项工程描述为开放生态,由高性能、可移植且可扩展的机器学习基础设施组件构成,用以消除前端框架与硬件后端之间的工具割裂。
- Development stays rolling in public repositories rather than moving through a numbered release stream, so the main branch rather than a tagged version is the reference point.开发在公开仓库中以滚动方式推进,而非经由编号的发布序列,因此基准点落在主分支而非某个打标签的版本上。
- The compiler has been used at the largest scales of the field, including training runs for models such as DeepMind's AlphaFold and serving infrastructure behind Google's Gemini.该编译器被用于该领域最大的规模,包括 DeepMind 的 AlphaFold 等模型的训练,以及谷歌 Gemini 背后的服务基础设施。
Reception
- The 2023 launch drew public endorsements from the fourteen co-developing organisations, each quoted in turn on the compiler's performance, portability and open governance.2023 年的发布引来十四家共同开发组织的公开背书,各方依次就编译器的性能、可移植性与开放治理发表评论。
- Graphcore reported that its compiler pipeline has used XLA since it was made public and that millions of queries a day are served by systems running code that XLA compiled.Graphcore 报告称其编译器流水线自 XLA 公开起就使用它,每天有数百万次查询由运行 XLA 编译代码的系统提供服务。
- Hugging Face said it enabled XLA for TensorFlow text-generation models and saw speed-ups of roughly a hundredfold, with the results folded into its Optimum library.Hugging Face 表示它为 TensorFlow 文本生成模型启用了 XLA,获得约百倍的加速,成果被并入其 Optimum 库。
- Alibaba reported that OpenXLA customers saw speed-ups of 72 per cent for GPT2 and 88 per cent for the Swin Transformer on NVIDIA GPUs.阿里巴巴报告称,其客户在 NVIDIA 的 GPU 上使用 OpenXLA 获得了 GPT2 加速 72%、Swin Transformer 加速 88% 的效果。
- Meta said it has used XLA, a core part of the project, to enable PyTorch models on Cloud TPUs with significant performance improvements on important projects.Meta 表示它使用 XLA 这一项目核心,让 PyTorch 模型跑在 Cloud TPU 上,并在一些重要项目上取得显著性能提升。
- Named deployment examples include full-scale training of DeepMind's AlphaFold, GPT2 and the Swin Transformer on Alibaba Cloud, multi-modal models serving Amazon.com, and real-time on-vehicle inference at Waymo.具名的部署实例包括在阿里云上对 DeepMind 的 AlphaFold、GPT2 与 Swin Transformer 做全规模训练,为 Amazon.com 服务多模态模型,以及在 Waymo 做实时车载推理。
- AMD highlighted use of the compiler to optimize serving of Stable Diffusion on locally equipped RDNA 3 machines, an example of the portability claim in practice.AMD 强调用它来优化在本地配备 RDNA 3 的机器上服务 Stable Diffusion,是「可移植」这一主张落地的一个例子。
- The launch also drew trade-press attention, with the data-infrastructure outlet Datanami running a March 2023 piece on the flexibility the stack gives machine-learning applications.此次发布也引来行业媒体的关注,数据基础设施媒体 Datanami 在 2023 年 3 月刊文介绍该技术栈给机器学习应用带来的灵活性。
- Its adoption as the acceleration infrastructure behind global-scale products, from Amazon.com search to Google Gemini and x.AI's Grok, is offered by the project as its strongest external validation.它被用作全球规模产品背后的加速基础设施,从 Amazon.com 搜索到谷歌 Gemini 与 x.AI 的 Grok,项目把这当作最有力的外部验证。
- The source is released under the Apache License 2.0 and developed in public repositories under the OpenXLA organisation on GitHub.源码以 Apache License 2.0 发布,并在 GitHub 上 OpenXLA 组织的公开仓库中开发。
- Coordination runs through a mailing list, an OpenXLA Discuss forum, a Discord server and a recurring community meeting, alongside issue trackers on the repositories.协作通过邮件列表、OpenXLA Discuss 论坛、Discord 服务器与定期的社区会议进行,仓库上的议题跟踪也一并使用。
- Documentation is hosted on the project site and covers XLA itself as well as the StableHLO, Shardy, PJRT, XProf and Tokamax components, each with its own set of guides.文档托管在项目站点,覆盖 XLA 本身以及 StableHLO、Shardy、PJRT、XProf 与 Tokamax 各组件,各自配有成套指南。
- Contributors span a broad set of hardware and software organisations, and the community page lists Alibaba, Amazon Web Services, AMD, Anyscale, Apple, Arm, Cerebras, Google, Graphcore, Hugging Face, Intel, Meta, NVIDIA and SiFive among participants.贡献者涵盖众多硬件与软件组织,社区页把阿里巴巴、亚马逊云科技、AMD、Anyscale、Apple、Arm、Cerebras、谷歌、Graphcore、Hugging Face、Intel、Meta、NVIDIA 与 SiFive 列为参与方。
- Framework teams integrate by emitting StableHLO, which keeps the ecosystem open to any front-end that can produce that operation set.框架团队通过产出 StableHLO 来完成集成,这使整个生态对任何能生成该操作集的前端保持开放。
- Tutorial material includes Colab notebooks that show how to extract StableHLO graphs from JAX, PyTorch and TensorFlow, and nightly development wheels ease onboarding.教程材料包括 Colab 笔记本,演示如何从 JAX、PyTorch 与 TensorFlow 提取 StableHLO 图,逐夜构建的开发期安装包也降低了上手门槛。
- The contribution path is documented plainly, asking for a signed Contributor License Agreement, a fork, a Bazel and Docker based build, and pull requests against the main repositories.贡献路径有清晰文档,要求签署贡献者许可协议、创建派生仓库、基于 Bazel 与 Docker 构建,并向主仓库提交拉取请求。
- Project governance rests on stated principles of equal footing between members, a culture of respect, scalable and efficient consensus-based decision-making, and transparency toward the public.项目治理立足于若干明示原则,成员间地位平等、尊重的文化、可扩展且高效的共识决策,以及面向公众的透明。
- Recurring gatherings such as the OpenXLA Dev Lab and the community meetings keep vendor engineers and researchers in the same room, with the 2024 Dev Lab drawing over a hundred practitioners from ten countries.OpenXLA Dev Lab 与社区会议等定期聚会让厂商工程师与研究者同处一室,2024 年的 Dev Lab 吸引了来自十个国家的逾百名从业者。
- JAX uses XLA as its default compilation backend, so much of the accelerator ecosystem reaches the compiler through that framework rather than directly.JAX 以 XLA 作为默认编译后端,因此加速器生态中的许多成员是经由该框架而非直接接触这个编译器。
- TensorFlow, where the compiler originated, still bundles it, and PyTorch reaches it through the PyTorch/XLA route for accelerator execution.编译器发源所在的 TensorFlow 仍随附它,PyTorch 则经 PyTorch/XLA 这条路径接入,以获得加速器执行能力。
- MLIR, the compiler infrastructure beneath it, supplies the intermediate-representation machinery that XLA, StableHLO and the partitioner all build on.位于其下的编译器基础设施 MLIR 提供了中间表示机制,XLA、StableHLO 与切分器都建立在它之上。
- IREE, brought under the same umbrella at launch, is a sibling project aimed at compiling machine-learning models through a comparable intermediate-representation route.IREE 在发布时被归入同一伞下,是一个姊妹项目,目标是以相近的中间表示路径编译机器学习模型。
- Alternative compiler stacks such as Apache TVM, NVIDIA TensorRT, ONNX Runtime and OpenAI Triton address overlapping problems, and each occupies a different point between framework and silicon.Apache TVM、NVIDIA TensorRT、ONNX Runtime 与 OpenAI Triton 等替代编译器栈处理彼此重叠的问题,各自落在框架与芯片之间的不同位置。
- Where a deployment is tied to one vendor's accelerators, a vendor-specific runtime such as TensorRT or the AWS Neuron stack may be the more direct choice, leaving XLA for cross-platform work.若部署绑定在某一厂商的加速器上,诸如 TensorRT 或 AWS Neuron 技术栈这类厂商特定运行时可能更为直接,而把 XLA 留给跨平台场景。
- Alongside the compiler, associated tools sit in the same ecosystem, with a quantizer, a partitioning system and a profiler covering parts of the workflow that the compiler core does not.与编译器并行,相关工具同处一个生态,量化器、切分系统与剖析器覆盖了编译器核心未涉足的工作流环节。
- The project positions itself against the manual approach of writing device-specific kernels per hardware target, arguing that a shared compiler removes that bespoke work and the vendor lock-in it brings.项目把自己定位为对抗「针对每种硬件目标手写设备内核」的做法的方案,主张共享编译器能免去这种定制工作及其带来的厂商锁定。