SemiAnalysis实测Trainium3:原生PyTorch训练体验改善
Amazon’s Trainium Takes a Strike at the Training King
针对非NVIDIA芯片的训练痛点,这篇深度实测给出了原生PyTorch迁移的具体路径与框架兼容性验证,对考虑算力替代方案的工程师极具参考价值。
Trainium has already proven itself in the realm of inference. Anthropic is running production inference and RL rollouts on Trainium2 and Trainium3. Historically, Trainium has been great for inference but not the best fit for research training. In inference, the model architecture changes at a much slower pace compared to training, where researchers iterate on many different experiments and ablations of model architecture and need a stack that covers a broad API surface. In the past, that is where Trainium fell short.
Trainium 在推理领域已经证明了自己的实力。Anthropic 正在 Trainium2 和 Trainium3 上运行生产环境中的推理任务和强化学习(RL) rollout。从历史上看,Trainium 非常适合推理,但并非研究训练的最佳选择。在推理场景中,模型架构的变更速度远慢于训练场景;研究人员需要对多种不同的实验和模型架构消融方案进行迭代,因此需要一个能够覆盖广泛 API 表面的技术栈。过去,这正是 Trainium 的短板所在。
The AWS Neuron team is aggressively working to change this pitfall with the biggest shift being moving towards a first-class, native PyTorch training experience. Gone are the days of sprinkling xm.step() through your training loop and wrestling with a bespoke XLA-style execution model. Trainium now runs PyTorch the way PyTorch users expect, in eager mode, with torch.compile and the standard APIs.
AWS Neuron 团队正积极努力消除这一缺陷,其中最大的转变是转向提供一流的、原生的 PyTorch 训练体验。往需要在训练循环中散布 xm.step() 调用并与定制化的 XLA 风格执行模型搏斗的日子一去不复返了。现在,Trainium 以 PyTorch 用户期望的方式运行——采用 eager 模式,支持 torch.compile 以及标准 API。
The SemiAnalysis engineering team has been trying out the Trainium3 racks for the past couple of weeks and has found the experience to be great – we love the overall direction of where it is heading. To be clear, it isn’t perfect yet, and we have personally run into a couple of bugs ourselves. It’s nowhere close to the maturity of the CUDA ecosystem, but the direction is right. Their team is making rapid progress with the help of agentic coding.
SemiAnalysis 工程团队在过去几周里试用了 Trainium3 机架,发现体验非常出色——我们非常看好其整体发展方向。必须说明的是,它目前尚不完美,我们自己确实遇到了几个 bug。它与 CUDA 生态系统的成熟度还相差甚远,但方向是正确的。在智能体编程(agentic coding)的助力下,他们的团队正取得快速进展。
Furthermore, unlike other accelerator companies, where we had to fight tooth and nail to get their engineers a reasonably stable CI fleet, Trainium uses up to 80,000 physical cores allocated towards automated quality control.
此外,与其他加速器公司不同——在其他公司,我们必须竭尽全力才能让他们的工程师获得一个相对稳定的 CI 集群——Trainium 最多分配了 80,000 个物理核心用于自动化质量控制。
In this article, we walk through our experience on the Trainium3 TorchTitan and TorchNeuron stack, along with our experience of Trainium’s Neuron Explorer profiler, which is way better than both Nvidia’s and AMD’s profilers. We created a bunch of demos to show how Trainium’s profiler is “GPU Impossible.”
在本文中,我们将介绍我们在 Trainium3 TorchTitan 和 TorchNeuron 堆栈上的使用经验,以及我们对 Trainium Neuron Explorer 分析器的体验,该分析器比 Nvidia 和 AMD 的分析器都要好得多。我们创建了一系列演示,以展示 Trainium 的分析器如何做到“GPU 不可能实现”的功能。
Visualizing Nafea Bshara, VP at AWS In Trainium Profiler Showcasing Trainium’s Finegrain Profiler. Source: SemiAnalysis
可视化 Nafea Bshara,AWS Trainium 分析器副总裁,展示 Trainium 的细粒度分析器。来源:SemiAnalysis
In an upcoming article, we will go deep on writing speed-of-light NKI kernels and microbenchmarking on Trainium3. For our deep dive into the Trainium hardware, check out our previous article where we do a complete hardware breakdown.
在即将发布的一篇文章中,我们将深入探讨如何在 Trainium3 上编写光速 NKI 内核并进行微基准测试。若要深入了解 Trainium 硬件,请参阅我们之前的文章,其中对硬件进行了全面拆解。
Source: SemiAnalysis
来源:SemiAnalysis
We Are Hiring
我们正在招聘
SemiAnalysis is hiring for various Member of Technical Staff roles. If you find this type of analysis interesting, apply below:
SemiAnalysis 正在招聘各种技术团队成员(Member of Technical Staff)职位。如果您觉得此类分析有趣,请在下方申请:
Apply Here
在此申请
What we’re looking for:
我们要寻找的人才特质:
- Highly motivated & skilled Member of Technical Staff to join our growing engineering team.
- Member of Technical Staff will play a crucial role in developing inference benchmarks & system modeling
- You will also play a role in writing and preparing our newsletter articles for publishing, with the opportunity for direct authorship recognition.
- We are hiring individual contributors at all experience levels. Compensation will be competitive
- As part of the interview process, you’ll complete a paid coding challenge designed to reflect typical daily tasks at SemiAnalysis
- Competitive Compensation depending on experience, skillset, location & business needs
- 高度积极且技能娴熟的技术团队成员,加入我们不断壮大的工程团队。
- 技术团队成员将在开发推理基准测试和系统建模方面发挥关键作用。
- 您还将参与撰写和准备我们的通讯文章以供发布,并有机会获得直接署名认可。
- 我们正在招聘各个经验级别的独立贡献者。薪酬具有竞争力。
- 作为面试流程的一部分,您需要完成一项付费编程挑战,该挑战旨在反映 SemiAnalysis 典型的日常任务。
- 具有竞争力的薪酬,具体取决于经验、技能组合、地点和业务需求。
Qualifications
资格要求
- Proactive, self-motivated, and capable of working independently in a global team.
- Demonstrated experience in ML frameworks such as PyTorch or JAX through professional experience, personal projects, or personal Substack blogs
- Solid understanding of at least 1 of the following: transformer architecture, LLM parallelism strategies, and/or CUDA parallel programming
- Strong research skills and the ability to synthesize information from various sources to draw insights.
- English language proficiency required, Chinese language proficiency preferred
- 积极主动、自我驱动,并能在全球团队中独立工作。
- 通过专业经验、个人项目或个人 Substack 博客展示在 PyTorch 或 JAX 等 ML 框架方面的经验。
- 对以下至少一项有扎实的理解:Transformer 架构、LLM 并行策略以及/或 CUDA 并行编程。
- 强大的研究能力,能够从各种来源综合信息以得出见解。
- 要求具备英语语言能力,中文语言能力者优先。
Moving Towards a First-Class PyTorch Experience
迈向一流的 PyTorch 体验
Amazon has made a major course correction to its software strategy, and we believe it will meaningfully broaden Trainium3 adoption. TorchNeuron represents a native PyTorch experience instead of duct-taping Trainium onto PyTorch through the PyTorch/XLA project. The new backend is aimed at everyone who isn’t a frontier-lab kernel engineer. AWS has even hired the lead of Google’s native Torch on TPU effort to work on native Torch for Trainium. He was the TPU SW lead from the start of the program at Google, including XLA, xprof, Cloud TPU, etc.
亚马逊对其软件战略进行了重大调整,我们相信这将显著扩大 Trainium3 的采用率。TorchNeuron 代表了一种原生的 PyTorch 体验,而不是通过 PyTorch/XLA 项目将 Trainium 强行适配到 PyTorch 上。新的后端旨在服务于所有非前沿实验室内核工程师的人群。AWS 甚至聘请了 Google 原生 TPU Torch 项目的负责人来从事 Trainium 的原生 Torch 工作。他从该项目在 Google 的初期开始就担任 TPU 软件负责人,包括 XLA、xprof、Cloud TPU 等。
The old approach made Trainium feel foreign to anyone coming from CUDA. PyTorch/XLA relied on lazy tensor graph capture and had no first-class eager mode. It also didn’t support PyTorch’s native distributed APIs (torch.distributed.*) or its native parallelism APIs (DTensor, SimpleFSDP, DDP). Users had to rely on out-of-tree XLA SPMD APIs such as torch_xla.experimental.spmd_fsdp and torch_xla.distributed.spmd. For researchers who are used to native PyTorch on CUDA, switching to Trainium meant relearning how to write a training loop.
旧方法让任何来自 CUDA 背景的人觉得 Trainium 很陌生。PyTorch/XLA 依赖于惰性张量图捕获,没有一流的一阶急切模式(eager mode)。它也不支持 PyTorch 的原生分布式 API(torch.distributed.*)或其原生并行化 API(DTensor、SimpleFSDP、DDP)。用户不得不依赖树外 XLA SPMD API,如 torch_xla.experimental.spmd_fsdp 和 torch_xla.distributed.spmd。对于习惯于在 CUDA 上使用原生 PyTorch 的研究人员来说,切换到 Trainium 意味着需要重新学习如何编写训练循环。
Source: AWS
来源:AWS
The pain of converting GPU research codebases by adding XLA markers everywhere was a massive turnoff to anyone who used PyTorch/XLA before.
通过在各处添加 XLA 标记来转换 GPU 研究代码库的痛苦,让任何之前使用过 PyTorch/XLA 的人都望而却步。
Source: AWS
来源:AWS
At a high level, the only change needed is replacing .to(”cuda”) with .to(”neuron”), and in theory the vast majority of the PyTorch ATen operators will work decently well out of the box.
从宏观层面来看,唯一需要的更改是将 .to("cuda") 替换为 .to("neuron"),理论上绝大多数 PyTorch ATen 运算符开箱即用即可良好运行。
Source: AWS
来源:AWS
In theory, with PyTorch’s torch.accelerator hardware-agnostic API, lines of code like bf16 autocast won’t even need to be changed, though some APIs in PyTorch and some research codebases still haven’t migrated to the torch.accelerator namespace and still directly call the torch.cuda.* namespace.
理论上,借助 PyTorch 的 torch.accelerator 硬件无关 API,像 bf16 autocast 这样的代码行甚至无需更改,尽管 PyTorch 中的一些 API 和一些研究代码库尚未迁移到 torch.accelerator 命名空间,仍然直接调用 torch.cuda.* 命名空间。
As most academics and researchers across robotics, biotech, world models, and self-driving mainly use BF16, Trainium Torch will not support TorchAO MXFP8 on day 0 until they have made the BF16 training experience great. We don’t disagree with this sequence, as most people doing MXFP8 training are big Tier 1 labs that have enough kernel engineers to write custom kernels for the big training run.
由于机器人、生物技术、世界模型和自动驾驶领域的绝大多数学者和研究人员主要使用 BF16,Trainium Torch 在第一天不会支持 TorchAO MXFP8,直到他们把 BF16 的训练体验做好。我们并不反对这一顺序,因为大多数进行 MXFP8 训练的是大型一级实验室,它们拥有足够的内核工程师来为大训练任务编写自定义内核。
Trainium Torch Ecosystem
Trainium Torch 生态系统
PyTorch is popular not only because of core PyTorch but also because of the entire ecosystem of libraries, including Hugging Face Transformers, PEFT, diffusers, TRL, Accelerate, TorchTitan, etc. We are amazed to see that Trainium Torch already supports a ton of these libraries in the ecosystem, including Hugging Face Accelerate, which an insane number of layers of indirection. Trainium supports one of the most popular clean open-source training codebases called TorchTitan with many Tier 2 labs forking it to serve as the foundation of their internal training codebase. Trainium’s new PyTorch experience fully supports that too.
PyTorch 之所以流行,不仅因为其核心功能,还因为其整个库生态系统,包括 Hugging Face Transformers、PEFT、diffusers、TRL、Accelerate、TorchTitan 等。令人惊叹的是,Trainium Torch 已经支持了生态系统中大量的这些库,包括 Hugging Face Accelerate,后者具有极其复杂的间接层结构。Trainium 支持其中一个最受欢迎的干净开源训练代码库 TorchTitan,许多二级实验室将其 fork 作为其内部训练代码库的基础。Trainium 的新 PyTorch 体验也完全支持这一点。
We saw how Google was able to successfully partner with Inferact/RadixArk to bring TPUs into the vLLM/SGLang ecosystem, and also land Meta as a production TPU customer. Furthermore, by bringing TPUs into the vLLM/SGLang ecosystem, TPUs were already able to automatically get day 0 support for Muse Spark Open and commitments for day 0 TPU support for popular upcoming models.
我们看到 Google 如何成功与 Inferact/RadixArk 合作,将 TPU 引入 vLLM/SGLang 生态系统,并使 Meta 成为生产环境中的 TPU 客户。此外,通过将 TPU 引入 vLLM/SGLang 生态系统,TPU 已经能够自动获得 Muse Spark Open 的第一天支持,并承诺对即将推出的热门模型提供第一天 TPU 支持。
While it is true that the increase in agentic coding has made the engine code itself less important, what vLLM/SGLang brings to the table is the ecosystem. No matter the open source model, on day 0, the global ML community trusts vLLM/SGLang as the go-to engine for inference. No vibe-coded engine has that reach.
虽然确实代理式编码的增加使得引擎代码本身变得不那么重要,但 vLLM/SGLang 带来的是生态系统。无论是什么开源模型,在第一天,全球机器学习社区都信任 vLLM/SGLang 作为推理的首选引擎。没有任何通过随意编码(vibe-coded)构建的引擎能达到这种影响力。
We are starting to see Trainium rapidly invest in the vLLM/SGLang community with hardware access and early access to Trainium on SGLang built on native PyTorch (TorchNeuron), similar to the TorchTPU approach.
我们开始看到 Trainium 正在迅速投资 vLLM/SGLang 社区,提供硬件访问权限以及基于原生 PyTorch(TorchNeuron)构建的 SGLang 上 Trainium 的早期访问权限,这与 TorchTPU 的方法类似。
Source: SemiAnalysis
来源:SemiAnalysis
TorchTitan Experience
TorchTitan 体验
TorchTitan is one of the most popular open-source pre-training frameworks, and we tested Neuron’s support to gauge the user experience of a researcher training a non-trivial model with Trainium. Specifically, we trained a Qwen3-32B on 16 Trainium2 chips, 64 LNC=2 logical cores in total, and we also tried doing it on a rack-scale Trainium3 UltraServer with 64 physical chips.
TorchTitan 是最受欢迎的开源预训练框架之一,我们测试了 Neuron 的支持情况,以评估研究人员使用 Trainium 训练非平凡模型的用户体验。具体而言,我们在 16 个 Trainium2 芯片(共 64 个 LNC=2 逻辑核心)上训练了一个 Qwen3-32B 模型,并尝试在拥有 64 个物理芯片的机架级 Trainium3 UltraServer 上进行训练。
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力