#NPU Ascend910 TinyTimeMixer
npu:0,通过 torch_npu 显式迁移model.safetensors,本地加载 /opt/atomgit/adapt-npu-agent/.cache_hf/ttm-research-r2Tiny Time Mixer (TTM) 是 IBM Research 开源的轻量时序基础模型,NeurIPS 2024。支持 zero-shot/few-shot 预测,本适配使用 512-96 模型,StandardScaler 预处理 + freq_token (hourly=7) 前缀调优。
| 项 | 值 |
|---|---|
| 数据来源 | ETTh1 hourly (https://raw.githubusercontent.com/zhouhaoyi/ETDataset/main/ETT-small/ETTh1.csv) 公开可追溯 |
| 行数/列 | 17420 行, 8 列 (date + 7 通道 HUFL/HULL/MUFL/MULL/LUFL/LULL/OT) |
| 使用通道 | OT (Oil Temperature) 单变量,num_input_channels=1 |
| 时间列 | date (hourly), 已排序,测试集 20% (3484 行) |
| 输入窗口 | 最后 512 小时 (context) |
| 预测长度 | 96 小时 (horizon) |
| 缩放 | StandardScaler per-channel (mean=9.3458, std=1.9074) 独立拟合窗口,推理后逆变换 |
| 频率 | hourly -> freq_token=7 (DEFAULT_FREQUENCY_MAPPING h=7) |
| 轴顺序 | [batch, time, channel] = [1,512,1] |
| 是否训练 | 否,仅 zero-shot 推理,权重冻结 |
inference.py 校验缺列、非法值,复用同一 fitted mean/std,不得重新 fit。
python scripts/collect_env.py --output working/env.jsonpip install -r requirements.txt
# 或已在昇腾容器中,通过 torch_npu 直接可用模型需先下载到本地(依赖环境变量 HF_ENDPOINT=https://hf-mirror.com 自动镜像):
python -c "from huggingface_hub import snapshot_download; snapshot_download('ibm-research/ttm-research-r2', local_dir='./ttm-research-r2')"
# 或使用 HF CLI# 默认 npu:0,ETTh1 自动下载到 data/ETTh1.csv 或 /opt/atomgit/adapt-npu-agent/ETTh1.csv
python inference.py
# 自定义
python inference.py --model-dir /path/to/ttm-research-r2 --data /path/to/ETTh1.csv --context 512 --prediction-length 96 --device npu:0 --iterations 10关键日志 (节选):
[INFO] model_id : ibm-research/ttm-research-r2
[INFO] device : npu:0
[INFO] npu name : Ascend910_9362
[INFO] params : 0.855M
[INFO] first param : device=npu:0 dtype=torch.float32
[INFO] input tensor : past_values shape=(1, 512, 1) device=npu:0 dtype=torch.float32
[INFO] freq_token : value=7 (hourly) shape=(1,) device=npu:0
[INFO] first run (compile+infer): 187.2 ms
[INFO] forecast tensor: shape=(1, 96, 1) device=npu:0 dtype=torch.float32
[STATUS] NPU inference PASS所有模型参数与输入 Tensor 显式 .to(npu:0),计时前后 torch.npu.synchronize(),首轮编译与稳定推理分离。
基于 ETTh1 OT 最后 512 小时的逆变换预测 (前12步):
step 1: 9.3668
step 2: 9.1558
step 3: 9.0187
step 4: 8.9667
step 5: 8.9550
step 6: 8.9499
step 7: 8.9500
step 8: 8.9498
step 9: 8.8968
step 10: 8.9191
step 11: 9.0361
step 12: 9.2043同一权重、输入、预处理、dtype float32、seed 下:
python compare -> pred shape [1,96,1], mean -0.0525.npy: compare_outputs.py --cpu cpu.npy --npu npu.npy --task forecasting --atol 1e-4 --rtol 1e-3max_abs 0.000154, mean_abs 5.59e-05, passed true (FP32, TinyTimeMixer 含 LayerNorm/MLP,误差来自 NPU 浮点融合,阈值 1e-4/1e-3 在合理范围)预热 3 次,测试 10 次,同步后计时:
| 指标 | ms |
|---|---|
| compile+first | 187.2 |
| avg | 4.9 |
| min | 4.8 |
| max | 4.9 |
| p50 | 4.9 |
| p90 | 4.9 |
| p95 | 4.9 |
| windows/s | 204.99 |
| peak NPU mem | 3.6 MiB |
Batch=1, context 512, horizon 96, dtype float32, 含 inverse scaling,不含 CSV 读取首轮下载。
三张 PNG 由 scripts/render_xterm_evidence.mjs --style raw 根据真实日志生成,深灰背景、白色等宽字体,提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$ 仅展示标签:

图片由 xterm.js 根据本次真实日志生成,非手绘或 Matplotlib 模拟。
原模型 CC-BY-NC-SA-4.0 (research-use),详见上游。