bytedance-research/Timer-S1 在华为昇腾 Ascend 910 (910B) 单卡 npu:0 上的真实适配与推理验证。基于 torch_npu 将原始 PyTorch MoE 时间序列基础模型迁移至 NPU,保持 BF16 精度与概率分位输出一致性。
bytedance-research/Timer-S1 (revision: 8911430cc7f32add5c8913afe12e3b05742f5bb2, 8.3B total / 0.75B active, MoE 32 experts, 24 layers, hidden 1024)python inference.py (默认 npu:0, bfloat16, revin=True)NPU Ascend Ascend910 time-series forecasting MoE Timer-S1[batch, context_length] (B T), float/bfloat16, 例 [1,512]input_token_len=16max_new_tokens), 输出 [B,9,H] 例 [1,9,32][0.1..0.9] 排序, 单调递增需满足 q0<q1<...<q8revin=True (模型内可逆实例归一化, 含逆变换)torch.randn(42) 生成, 哈希校验 745e4d5ed328cd10, 统计 mean=0.0388 std=1.0624 min=-2.89 max=2.89float32不得擅自改变轴顺序或用随机输入冒充业务数据, 本示例窗口与数据来源已固定并记录哈希。
npu:0 (HBM 64GB), 2 devicesnpu-smi 25.5.5, CANN 8.5.1 /usr/local/Ascend/cann-8.5.1HF_ENDPOINT=https://hf-mirror.comtorch.npu.is_available()==True, device_count=2, torch.npu.get_device_name(0)=Ascend910_9362+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.5 Ascend910 HBM 3105/65536 MB Power 168.9W Temp 45C |pip install -r requirements.txt
# requirements: torch==2.9.0 torch-npu==2.9.0.post1 transformers==4.57.6 numpy==1.26.4 safetensors accelerate huggingface_hub模型下载 (必须设镜像, 权重 16.6GB, 4 分片):
HF_ENDPOINT=https://hf-mirror.com python3 -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='bytedance-research/Timer-S1', local_dir='/tmp/Timer-S1', max_workers=1)"
# 或 huggingface-cli: HF_ENDPOINT=https://hf-mirror.com huggingface-cli download bytedance-research/Timer-S1 --local-dir /tmp/Timer-S1本地加载无需联网: AutoModelForCausalLM.from_pretrained("/tmp/Timer-S1", trust_remote_code=True, dtype=torch.bfloat16)
python inference.py
# 预期: 加载 4 分片 -> CPU 基线 -> NPU npu:0 推理 -> 一致性 PASS -> 性能 3.5 windows/s核心逻辑 (inference.py:resolve_model_dir, get_model, model.to("npu:0"), torch.npu.synchronize()):
model = AutoModelForCausalLM.from_pretrained(model_dir, trust_remote_code=True, dtype=torch.bfloat16, device_map="cpu")
model.to("npu:0")
seqs = torch.randn(1, 512, dtype=torch.bfloat16).to("npu:0")
torch.npu.synchronize(); t0=time.time()
out = model.generate(seqs, max_new_tokens=32, revin=True)
torch.npu.synchronize(); print((time.time()-t0)*1000)
# out shape [1,9,32]设备显式检查: first_param device: npu:0, input device: npu:0, output device: npu:0 (无 CPU fallback)
shape [1,9,32] dtype float32 device cpu time 1857ms median [0,4,:5]=[0.1109,0.1571,0.1565,0.0953,0.1026] quantiles first step [-1.256, -0.807, -0.469, -0.169, 0.110, 0.387, 0.661, 0.976, 1.366] mean 0.0656 std 0.8253torch.npu.synchronize() 计时)shape [1,9,32] device npu:0 median [0,4,:5]=[0.1088,0.1560,0.1545,0.0958,0.1034] quantiles first step [-1.264, -0.812, -0.469, -0.172, 0.108, 0.385, 0.661, 0.976, 1.383] mean 0.0652 std 0.8265 finite True/tmp/timer_cpu.npy /tmp/timer_npu.npyforecast quantiles (非逆变换后标签), float32 视图max_abs 0.0166, mean_abs 0.00209, allclose(atol=1e-2, rtol=1e-2)=Trueq0<...<q8 CPU/NPU 均为 True), finite True, shape [1,9,32] 一致python scripts/compare_outputs.py --cpu /tmp/timer_cpu.npy --npu /tmp/timer_npu.npy --task regression --atol 1e-2 --rtol 1e-2 -> passed truetorch.npu.synchronize() 前后, 首轮编译与稳定阶段分离npu:0 bfloat16 batch=1 context=512 horizon=32 quantiles=9compile/first_run 594.00 ms | avg 279.71 ms min 270.29 max 287.80 p50 278.87 p90 286.18 p95 286.993.58 windows/s (3.58 series/s) (batch 1)allocated 16000 MB reserved 19362 MB peak 16032 MB (8.3B BF16 权重 ~16GB)revin 含在模型内三图由 xterm.js 根据本次真实日志渲染 (--style raw), 深灰背景白字, 提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$, 仅展示非敏感日志, 详细生成见 scripts/render_xterm_evidence.mjs。

B T 输入, 多变量需通道独立外循环use_cache=Falsefit 无)context 或 batch 至 1Apache-2.0 (同上游). 使用 trust_remote_code=True 需审查 configuration_TimerS1.py modeling_TimerS1.py ts_generation_mixin.py 无网络/子进程/文件写入风险.