数据源与状态仍在导航菜单中
aws.amazon.com·2026/10/22·Josh Longenecker
AWS 博客介绍在单台 Trainium 实例上用 torchtitan 训练 Qwen3:TorchNeuron 将加速器注册为原生 PyTorch 设备,安装 torchtitan-neuron 并下载 Hugging Face 权重后,同一 torchrun 命令可跑多套配置。Transformers 后端通过 AutoModelForCausalLM 直接读写 safetensors,官方称加载公开权重首步损失为 6.54,导出检查点可回读且除共享词嵌入权重外无异常键。原生路径把 config.model_spec 切到原生模型类,用 SDPA 注意力。NKI 路径接入 MoE kernel,将 MoE 层替换为 NKI 实现,并用 wrap_nki、nki_op 和 override 注册 rope_hf 自定义算子,再以 register_autograd 接回反向;为适配单机,示例缩减到 4 层并面向 64 个逻辑 NeuronCore 做数据并行。文末强调可用张量并行、FSDP、序列并行扩展规模,监控 HBM,运行前校验序列长度约束与数值一致性,且自定义算子示例只演示接入而非证明提速。
为什么重要 对需要把 Trainium 纳入训练基座的团队,这篇给出 HF/原生/NKI 三条可复现路径,含权重加载校验与自定义 kernel 接入。适合 使用 AWS Trainium 的模型训练/基础设施工程师,已具备 PyTorch 与 torchtitan 基础。

发布权重首步 loss
随机初始化首步 loss
rope_hf 最大绝对差
注释 · 作者验证跑:随机初始化 loss 12.43;导出后无缺失或意外键,除 tied lm_head.weight。出自 检查点段/自定义内核段
$ python3 -c "import torchtitan, torchtitan_neuron; print(torchtitan.__version__, torchtitan_neuron.__file__)"
$ git clone https://github.com/aws-neuron/torchtitan-neuroncd torchtitan-neuronpip install -r requirements.txt
$ hf download Qwen/Qwen3-4B-Instruct-2507 \--local-dir "$PWD/assets/hf/Qwen3-4B-Instruct-2507"
$ torchrun --nproc_per_node=64 --rdzv_backend c10d --rdzv_endpoint localhost:0 \--local-ranks-filter 0 --role rank --tee 3 \-m torchtitan.train --module neuron_qwen3 --config v5_qwen3_4b
$ torchrun --nproc_per_node=64 --rdzv_backend c10d --rdzv_endpoint localhost:0 \--local-ranks-filter 0 --role rank --tee 3 \-m torchtitan.train --module neuron_qwen3 --config native_qwen3_4b \--override.imports my_neuron_kernels
在 AWS Trainium 上使用 torchtitan,于单台 trn2.48xlarge 上以三种方式训练 Qwen3:Hugging Face Transformers v5 建模后端、torchtitan 原生 Qwen3,以及 NKI mixture-of-experts 内核。
相同的 torchrun 启动器和配置结构在三条路径中均可不变地使用,包括加载和保存已发布的 Hugging Face safetensors。
Train Qwen3 on AWS Trainium with torchtitan three ways on a single trn2.48xlarge: the Hugging Face Transformers v5 modeling backend, torchtitan's native Qwen3, and NKI mixture-of-experts kernels.
The same torchrun launcher and config structure work unchanged across all three paths, including loading and saving published Hugging Face safetensors.
EVIDENCE / METHODS
要点卡片
Transformers v5、原生 Qwen3、术语解释Neuron Kernel Interface,AWS Trainium 的内核编写语言。 MoE 三种后端共用同一 torchrun 启动。
通过 AutoModelForCausalLM 读 Hub 模型,直接读写 safetensors;config.hf_model 选 Hub ID。
config.model_spec 设为 model_registry("4B", attn_backend="sdpa"),用 SDPA。
torchtitan_neuron 的 qwen3_nki_moe_config 接 术语解释Neuron Kernel Interface,AWS Trainium 的内核编写语言。 混合专家内核。
注释 · 三种配置都使用 64 个逻辑 NeuronCore 与 config 结构,切换只改 config 函数。出自 正文开头