在之前的文章中,我们介绍了 TorchNeuron,这是 AWS Trainium 的原生 PyTorch 后端(torch-neuronx 包)。借助它,Transformers 可以在 Trainium 上运行其自身的建模代码,就像在其他任何设备上一样,因此 Hub 上的任何 Transformers 模型都可以运行。究竟哪些模型能够实际运行呢?
torch-neuronx 模型支持 Space 针对 Hub 上最受欢迎的模型回答了这个问题。它会告诉你某个模型是否可以在未修改的情况下在 Trainium 上运行,并提供让你自行运行的脚本。
查找模型
该 Space 默认打开“已选”视图:这是我们从 Hub 上下载量最高和趋势评分最高的模型中精选出的模型列表。每一行都显示了结果、模型分片所覆盖的 Trainium 核心数量、运行耗时(包括编译时间)以及峰值设备内存。
要查找特定模型,请切换到“趋势”或“下载量”视图并输入其名称的一部分。这些视图遵循 Hub 自身的排名,一次针对一个任务,无论该模型是否经过测试。如果某个模型被有意排除,Space 会说明原因(大多数情况下是因为优先级较低,有时则是确实不兼容)。你还可以选择查看 Neuron 编译器(neuronx-cc)和 Transformers 的版本。
截至撰写本文时,仅对 Transformers 模型进行了测试,我们的选择仅限于文本生成和图文到文本模型。我们计划扩展到 diffusers、sentence transformers 以及其他 Transformer 任务。
自行运行
选择一个模型以查看如何运行它。该 Space 列出了该模型所测试的 Neuron 堆栈、需要在其之上安装的包以及实际运行的 run.py 脚本。该脚本遵循 TorchNeuron 公告中的配方:使用 from_pretrained 加载模型(如果需要则进行分片),然后使用静态缓存和 torch.compile(backend="neuron") 生成文本。
在具有该堆栈的 Trainium2 (trn2) 实例上,例如在 AWS Neuron Deep Learning Container 中,安装这些包,然后运行:
python3 run.py
无需使用 torchrun:当模型进行分片时,脚本会启动自己的 torch.distributed 进程。
首次运行会从编译模型的计算图开始。若要跳过此步骤,可以从公共 NEFF 缓存存储桶中复制测试期间同一编译器构建的图。Space 提供了带有正确编译器版本的命令:
hf buckets sync hf://buckets/aws-neuron/torch-neuronx-neff-cache/neuronxcc-
“运行”的含义
每次测试都将模型加载到 trn2 实例上,分片到能够容纳其权重的最少 Trainium 核心数量。大多数模型使用张量并行进行分片。没有张量并行计划的混合专家(MoE)模型仅使用专家并行。测试随后生成 32 个 token 并检查它们。在单个核心上,生成的 token 会与同一检查点的 CPU 运行结果进行比较。当模型进行分片时,一个小型评判模型会检查文本是否为流畅的英语。
截至撰写本文时,仅对能够容纳在 4 个 Trainium2 设备上的模型进行测试,这意味着最多 16 个核心。通过(PASS)并不代表吞吐量或更长生成序列的表现。
结果是一个数据集
Space 显示的所有内容均来自公共 aws-neuron/torch-neuronx-model-support 数据集,其中每个 neuronx-cc 和库版本对对应一个 Parquet 文件。
每一行包含模型的结果、失败时的错误信息、整个堆栈的版本以及实际运行的 run.py。你可以直接查询它:
import pandas as pd
df = pd.read_parquet( "hf://datasets/aws-neuron/torch-neuronx-model-support/data" )
df[df.model_id == "Qwen/Qwen3-0.6B" ][[ "neuronx_cc" , "library" , "library_version" , "neuron_cores" , "result" ]]
数据集卡片给出了每个结果的确切含义。
下次你想知道某个模型是否能在 Trainium 上运行时,请去查找一下。
In a previous post , we introduced TorchNeuron, the native PyTorch backend for AWS Trainium (the torch-neuronx package). With it, Transformers runs its own modeling code on Trainium, as it does on any other device, so any Transformers model on the Hub may run. Which ones actually do?
The torch-neuronx model support Space answers that question for the most popular models on the Hub. It tells you whether a model runs unmodified on Trainium, and gives you the script to run it yourself.
Look up a model
The Space opens on the Selected view: our own selection of models picked among the top models on the Hub by downloads and by trending score. Each row gives the result, the number of Trainium cores the model is sharded over, the wall time of the run (compilation included) and the peak device memory.
To look up a given model, switch to the Trending or Downloads view and type part of its name. These views follow the Hub's own rankings, one task at a time, whether a model was tested or not. When a model was left out on purpose, the Space tells you why (most of the time it was not prioritized, sometimes it is truly incompatible). You can also pick the versions of the Neuron compiler ( neuronx-cc ) and of Transformers to look at.
At the time of writing, only Transformers models are tested, and our selection is limited to text-generation and image-text-to-text models. We plan to expand to diffusers, sentence transformers, and other transformers tasks.
Run it yourself
Select a model to see how to run it. The Space lists the Neuron stack the model was tested on, the packages to install on top of it, and the run.py script that ran. The script follows the recipe of the TorchNeuron announcement : it loads the model with from_pretrained , sharded when it needs to be, then generates with a static cache and torch.compile(backend="neuron") .
On a Trainium2 ( trn2 ) instance with that stack, for example in the AWS Neuron Deep Learning Container , install the packages, then run:
python3 run.py
No need for torchrun : the script launches its own torch.distributed ranks when the model is sharded.
A first run starts by compiling the model's graphs. To skip that step, copy the graphs the same compiler built during the test, from the public NEFF cache bucket. The Space gives you the command, with the right compiler version:
hf buckets sync hf://buckets/aws-neuron/torch-neuronx-neff-cache/neuronxcc-
What "runs" means
Each test loads the model on a trn2 instance, sharded over the smallest number of Trainium cores that can hold its weights. Most models are sharded with tensor parallelism. Mixture-of-experts models without a tensor-parallel plan use expert parallelism only. The test then generates 32 tokens and checks them. On a single core, the tokens are compared with those of a CPU run of the same checkpoint. When the model is sharded, a small judge model checks that the text is fluent English.
At the time of writing, only models that fit on 4 Trainium2 devices are tested, which means 16 cores at most. A PASS says nothing about throughput, or about longer generations.
The results are a dataset
Everything the Space shows comes from the public aws-neuron/torch-neuronx-model-support dataset, with one Parquet file per pair of neuronx-cc and library versions.
Each row holds a model's result, the error when it failed, the versions of the whole stack and the run.py that ran. You can query it directly:
import pandas as pd
df = pd.read_parquet( "hf://datasets/aws-neuron/torch-neuronx-model-support/data" )
df[df.model_id == "Qwen/Qwen3-0.6B" ][[ "neuronx_cc" , "library" , "library_version" , "neuron_cores" , "result" ]]
The dataset card gives the exact meaning of each result.
Next time you wonder whether a model runs on Trainium, look it up .
首次收录 · 2026-10-24 · 9.95 分