NPU-optimized inference for thuml/timer-base-84m (Timer 84M, generative time-series foundation model) on Huawei Ascend 910B npu:0.
#NPU
| 项 | 内容 |
|---|---|
| 类型 | 单变量时间序列点预测 (univariate), 基金模型零样本 |
| 输入轴 | [batch, time] float32, 例 [2,672] -> [2,768] |
| 上下文长度 (context) | 672 (7 tokens, input_token_len 96) 默认; 已验证 2880 (30 tokens) |
| 预测长度 (horizon) | 96 (1 token, output_token_len 96) |
| 通道 | 1 |
| 频率/时区 | none (synthetic), 无显式频率 token |
| 缩放/归一化 | 无 (revin=False), 原始 randn 合成, Timer 内部 PatchEmbedding unfold 96 |
| 缺失值 | 无 |
| 目标列 | forecast tensor [batch, horizon] 点预测 |
| 预处理固定 | TimerPatchEmbedding.unfold(96) + Linear 96->1024, 随后 Transformer; 推理时 prepare_inputs_for_generation 自动切片过去 token |
| 数据来源 | 合成确定性 torch.manual_seed(0) torch.randn (seed 0 batch2x672; seed 1 batch1x2880), 可追溯, 无外部依赖, 可替换为真实时序 (ETTh1, Electricity 等) |
| 预期输出范围 | forecast 均在 ±0.3 内, 有限值, 单调性不要求 (点预测) |
表格数据提示词对应本模型的时间序列预测能力:时序即表格的时序列,输入为 [B,T] 数值矩阵,输出为未来窗口,符合表格数据范畴的时序预测任务。
npu:0, 64 GB HBM, CANN 8.5.1torch.npu.is_available()==True, device_count 2working/models/thuml-timer-base-84m/model.safetensors (HF cache) -> inference.py 自动探测本地候选路径, 缺失时从 HF hub 拉取 thuml/timer-base-84mpython inference.py 默认 npu:0 同步计时, 无 CPU fallbackpip install -r requirements.txt
# 权重已通过 snapshot_download 缓存到 working/models/thuml-timer-base-84m (HF_ENDPOINT=https://hf-mirror.com)
# 若本地不存在, inference.py 会自动从 HF hub 下载 thuml/timer-base-84mrequirements:
torch==2.9.0
torch-npu==2.9.0.post1
transformers==4.57.6
huggingface-hub==0.36.2
numpy==1.26.4
safetensors默认命令 (单卡 npu:0, 同步计时, 手动 greedy 循环避免 HF generate 4.57 兼容问题):
python inference.pytimer_generate_manual 循环 prepare_inputs_for_generation + model(**model_inputs) + KV cache, torch.npu.synchronize() 前后计时, next_token = logits (点预测) 拼接到输入, attention_mask token 级维护[B, context+horizon] (例 [2,768]), forecast [B,96], device npu:0, dtype float32长上下文示例 (672 默认, 2880 已验):
import torch
seqs = torch.randn(1, 2880).to("npu:0")
# for horizon 96 -> out shape [1,2976][0.16091025, 0.00500162, -0.05125746, -0.02440653, 0.00457354, -0.03515654, -0.00169658, 0.00727242, 0.00133836, -0.07170998][0.07593706, 0.02563520, -0.09106676, -0.09411422, -0.14003009, -0.09981096, -0.01900825, 0.06876215, 0.08435688, 0.12020388][-0.09359372, -0.10494035, -0.09225260, -0.08856311, -0.07026178] (seed 1)npu:0, 输入 npu:0, 输出 npu:0, torch.npu.synchronize() 包围, 无 CPU fallback (见 npu_device_call.png)同权重、同输入 (seed 0, 2×672, raw)、同 dtype float32、同预处理 (unfold 96)、同 greedy 循环 (use_cache True, revin False) 下 CPU vs NPU:
[2,768] max_abs 4.69e-07, mean 1.68e-08[2,96] max_abs 4.69e-07, mean 1.35e-07, 全部 finite truepython .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu working/cpu_pred.npy --npu working/npu_pred.npy --task forecasting --atol 1e-4 --rtol 1e-3
python .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu working/cpu_forecast.npy --npu working/npu_forecast.npy --task regression --atol 1e-4 --rtol 1e-3npu:0 (log 中打印 input device npu:0 / output device npu:0)torch.npu.synchronize() 前后计时, 首轮编译单独报告, 稳定阶段 warmup 3 + 正式 10 次, 输入包含预处理 (unfold) 但不含数据生成:
三张 PNG 由 xterm.js 根据本次真实日志生成 (非绘图库模拟), 深灰背景, 白色等宽字体, 提示符固定为 atomgit@pod-a94f8701860f4700b161b00e290de466:~$ 展示标签:



图片由 scripts/render_xterm_evidence.mjs --style raw 根据 working/logs/workflow.log, working/logs/device.log, working/logs/inference.log 真实输出渲染, 仅 ANSI 清理与 token 脱敏, 未篡改 PASS/FAIL。
npu:0, 未验证多卡或 npu:1revin (可逆实例归一化), 如数据需缩放请自行在外层标准化并记录model.generate, 已验证等价