#NPU
TTM-R3 (TinyTimeMixer R3) 是 IBM Research 发布的小型时序基础模型,基于 Mixer 架构而非自注意力,采用 trend-residual 分解、三阶段预训练与多尺度补丁。支持零样本/少样本预测、单变量与多变量、CPU 高吞吐推理。本适配将 TTM-R3 的 TinyTimeMixerForDecomposedPrediction 在单卡 npu:0 上真实运行,完成 512 -> 30 的点预测。
context_length=512, prediction_length=30, d_model=128, num_layers=10, patch_length=9, patch_stride=9prediction_outputs tensor shape [B, 30, 1] (forecast)past_values shape [batch, 512, 1] (float32), [B, context_length, channels]scaling="std" 自动标准化;past_observed_mask 默认全 1sin(2*pi*5*t/512 + phase) + 0.02*随机噪声,seed=42,batch=2,用于 CPU/NPU 一致性与 NPU 验证prediction_outputs shape [2, 30, 1],示例 batch0 前5: [-0.0015, 0.0764, 0.1244, 0.1867, 0.2330][B, T, C],不得转置为 [B, C, T]tsfm_public via granite-tsfm (/tmp/granite-tsfm), einops, scikit-learn, pandas, huggingface_hubworking/models/ttm-r3 (snapshotted from HF_ENDPOINT=https://hf-mirror.com)pip install -r requirements.txt
# granite-tsfm 需可用: git clone https://github.com/ibm-granite/granite-tsfm.git /tmp/granite-tsfm
# 或 pip install git+https://github.com/ibm-granite/granite-tsfm.gitpython inference.py默认从本地 working/models/ttm-r3 加载权重,自动下载到 ~/.cache/ttm-r3 若本地不存在。显式将模型与输入搬运至 npu:0,同步计时。
[2,30,1] mean 0.370181 std 0.175235 min -0.039444 max 0.612929,preview [-0.0015, 0.0764, 0.1244, 0.1868, 0.2331][2,30,1] mean 0.369907 std 0.175329 min -0.040227 max 0.612683,preview [-0.0015, 0.0763, 0.1244, 0.1867, 0.2330]working/cpu_output.npy vs working/npu_output.npy 同权重同输入同预处理 dtype=float32 seed=42scripts/compare_outputs.py --task forecastingatol=1e-3 rtol=1e-3 (FP32, 考虑 mixer 数值误差,说明: 严格 1e-4 时 max_abs 7.8e-04 略超,1e-3 内通过)max_abs_error=0.0007829 mean_abs_error=0.0002745 finite=True passed=True (atol=1e-3)torch.npu.synchronize() 前后计时assets/agent_workflow.png — 侦察、下载、加载、NPU 推理、一致性、benchmark 与提交校验assets/npu_device_call.png — npu-smi info、NPU 可用性、设备名、参数 device/dtype、输入输出 deviceassets/model_result.png — python inference.py 完整输出、schema/窗口摘要、真实预测、同步耗时图片由 xterm.js 根据本次真实日志渲染,非截图模拟。
num_input_channels=1、context 512、horizon 30 的烟囱一致性,非全量 benchmark
