Tags: #NPU #Ascend #Ascend910 #TimeSeries #Forecasting
Timer 是清华 THUML 团队的大规模时间序列基础模型,预训练数据规模 260B 时序点,本权重为 84M 轻量版,支持上下文最长 2880,本仓验证 672 长度 (7 patches) 预测 96 (1 patch) 的零样本推理。
[batch, seq_len] 浮点时序,张量形状必须为 [B, T] 且 T % 96 == 0 且 T >= 96。单变量 float32。[batch, time],内部通过 unfold(step=96) 切分为 patches 嵌入为 [B, T/96, 1024]。generate 可扩展。revin=True,输出为原始尺度预测。python inference.py 使用 torch.randn(batch=2, lookback=672, seed=42) 合成类真实序列作为演示;业务可替换为真实 CSV/Parquet 单列序列,保证列顺序与 dtype 一致。TimerPatchEmbedding 完成。pip install -r requirements.txt
# 需已安装 CANN 8.5.1 并配置 torch_npupython inference.py
python inference.py --batch-size 2 --lookback 672 --prediction-length 96 --device npu:0 --dtype float32脚本默认完成真实 NPU 推理,固定 torch.manual_seed(42) 输入,前后调用 torch.npu.synchronize() 计时,首轮包含编译,稳定阶段复跑 5 次报告 p50/p90。需保证本地存在 /opt/atomgit/adapt-npu-agent/working/thuml-timer-base-84m 或联网可下载 thuml/timer-base-84m。
关键适配修复 (记录以满足 Hard Gate):
get_usable_length -> get_seq_length (transformers 4.57 Cache API)seen_tokens -> get_seq_length()get_max_length 兼容 get_max_cache_shapeattention_mask raw 长度 (672) 与 patch 长度 (7) 的转换position_ids raw 累计导致的 664 越界修复ts_generation_mixin._extract_past_from_model_output 兼容 (4.57 已移除)GENERATION_MODES_MAPPING[GREEDY_SEARCH] 从 _sample 改回 _greedy_search,否则会走 _sample 导致 logits[:, -1, :] 对 2D forecast 的越界。默认 python inference.py (batch=2, lookback=672, horizon=96, npu:0, float32) 的真实完整输出见 assets/model_result.png,文本摘要:
model_name=thuml/timer-base-84m device=npu:0 dtype=float32
first param device: npu:0
input shape: [2,672] sample last 5: [1.0052, -0.3476, -0.0492, 0.0077, 1.0521]
output shape: [2,96] device: npu:0
forecast sample first 5: [0.2022, 0.1872, 0.1393, 0.0413, -0.0739]
forecast last 5: [-0.1368, -0.1630, -0.1066, -0.0270, -0.0012]
finite: true min -0.2023 max 0.2022 mean -0.0136
first run 251.1 ms, stable avg 10.0 ms
status: NPU inference succeededforecast 张量 ([2,96] float32)。python scripts/compare_outputs.py --cpu cpu.npy --npu npu.npy --task forecasting --atol 1e-4 --rtol 1e-3max_abs_error 5.06e-07 mean 1.39e-07 passed true (阈值 atol 1e-4 rtol 1e-3, FP32)。无 CPU fallback,均为真实设备输出。torch.npu.synchronize() 前后计时,预处理未计入 (纯随机 Tensor 生成)三图由 scripts/render_xterm_evidence.mjs --style raw 根据本次真实日志生成 (深灰背景、白色等宽字体、固定提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$),非手工绘制:
assets/agent_workflow.png - 侦察、环境、CPU基线、NPU推理、一致性、性能与提交校验的完整工作流日志assets/npu_device_call.png - npu-smi、torch_npu 可用性、模型参数 device/dtype、输入输出 Tensor 的 npu:0 调用证明assets/model_result.png - 默认 python inference.py 的真实完整输出、同步耗时与成功状态

图片由 xterm.js 根据本次真实日志生成,不代表原始桌面截图。
T%96==0 且不超过 2880。trust_remote_code=True,已审查 modeling_timer.py/ts_generation_mixin.py 无网络/子进程恶意行为。