#NPU
ibm-research/test-ttm-v1 (TinyTimeMixerForPrediction, test checkpoint)d_model=192, num_layers=2, num_patches=8, patch_length=64, patch_stride=64, adaptive_patching_levels=3, mode=common_channel, decoder_mode=common_channel, decoder_d_model=128, decoder_num_layers=2, scaling=std, distribution=student_t, expansion_factor=2, gated_attn=True, dropout=0.2 — 点预测 (direct forecast, mse loss)past_values [B, T=512, C=1] 输出 forecast [B, horizon=96, C=1]context_length=512 → prediction_length=96 (patch 64, stride 64 → 8 patches 编码, decoder 96 步)granite-tsfm/tsfm_public (tsfm_public.models.tinytimemixer.TinyTimeMixerForPrediction), transformers 辅助 tsfm_public 注册, 无需 trust_remote_code| 项 | 值 |
|---|---|
| 轴顺序 | [B, T, C] 严格 (batch, time, channel); 输出 [B, horizon, C] |
| 演示 | batch=2, context=512, channels=1, horizon=96 (deterministic synthetic, seed 42) |
| 频率 | frequency_token_vocab_size=5 但本演示 past_values 仅需上下文, freq_token 可选 (验证 past_values 单输入与 freq_token 双输入一致) |
| 缩放 | std (config scaling=std + decoder init_processing=true), 模型内自动 scale/inverse scale, 默认 float32 数值 |
| 数据来源 | 确定性合成 (seed 42): sin(2π*5*t/512+phase) + 0.02*randn, mean 0.0006 std 0.7064, past preview batch0 first5 [0.00993,0.05855,0.13536,0.21350,0.23829], SHA256 不适用 (合成即时生成, 可复现) |
| 输出 | forecast [2,96,1] float32 batch0 first5 [0.16835,0.21972,0.25466,0.27828,0.29622] batch1 first5 [0.53386,0.53718,0.54940,0.54090,0.53284], mean -0.068696 std 0.291428 min -0.439898 max 0.549408, finite True |
| dtype | float32 (NPU 上 LayerNorm/MLP 保持 float32, 无自动混合) |
| 预处理 | 无外部归一化; past_values 直接喂入 past_observed_mask=ones 自动生成 (NPU 有 allow_internal_format=False 警告属预期, 非 fallback) |
| 后处理 | 模型输出即去归一化后的预报, 无需额外 inverse transform |
granite-tsfm 0.3.9.dev4+g9739fa59b (本地源码 working/granite-tsfm-stable → tsfm_public), datasets 5.0.1 + pandas 3.0.2 (导入时 toolkit mock 避免 pyarrow 强依赖, 推理本身不依赖 pyarrow/datasets)Ascend910_9362 ×2, 目标 npu:0 (Phy-ID 6, Bus 0000:0B:00.0)torch.npu.is_available()==True, device_count==2HF_ENDPOINT=https://hf-mirror.com, 代理经环境变量 HTTP_PROXY=http://127.0.0.1:7890 直连, 无代码内手动设置TinyTimeMixerForPrediction.from_pretrained(local_dir) → .to("npu:0") → model(past_values=...) (nn.Module, torch.no_grad, torch.npu.synchronize 计时)pip install -r requirements.txt
# granite-tsfm 源码已预置于 working/granite-tsfm-stable, inference.py 自动将其加入 sys.path
# 若需 pip 形式: pip install -e working/granite-tsfm-stable
# 或 pip install granite-tsfm (==0.3.9)python inference.pyworking/models/test-ttm-v1 或 /tmp/models/ibm-research-test-ttm-v1 或 snapshot_download 下载 → npu:0 → warmup 2 → 同步计时 → 打印真实预测。关键日志(npu:0, seed 42):
[INFO] model_name: ibm-research/test-ttm-v1
[INFO] npu_available: True device_count: 2 device_name: Ascend910_9362
[INFO] target device: npu:0
[INFO] loading model from: working/models/test-ttm-v1
[INFO] weight bytes: 3240592 (3.1 MB)
[INFO] context_length=512 prediction_length=96
[INFO] first param device before NPU move: cpu
[INFO] first param device after to(npu:0): npu:0
[INFO] past preview batch0 first5: [0.00993,0.05855,0.13536,0.21350,0.23829]
[INFO] input NPU device past:npu:0
[RESULT] output shape (2, 96, 1) device npu:0 dtype torch.float32
[RESULT] preview batch0 first5: [0.16835,0.21972,0.25466,0.27828,0.29622]
[SUCCESS] NPU inference completed on npu:0 with TinyTimeMixerForPrediction (ibm-research/test-ttm-v1) context 512 horizon 96npu:0 时非零退出; allow_internal_format=False 警告为已知 NPU 限制非 fallback。forecast [2,96,1] float32batch0 first5 [0.16835965,0.21972250,0.25466307,0.27828934,0.29622361] last5 [-0.068...] (全量 mean -0.068696)batch1 first5 [0.53386467,0.53718054,0.54940778,0.54090106,0.53284192]stats mean -0.068696 std 0.291428 min -0.439898 max 0.549408 finite TrueCPU 同输入 mean -0.068381 batch0 first5 [0.16883181,0.22029183,0.25526705,0.27888435,0.29681029] (见一致性)python .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu working/cpu_test_ttm.npy --npu working/npu_test_ttm.npy --task regression --atol 1e-3 --rtol 1e-3
| 输出 | max_abs | mean_abs | passed | 说明 |
|---|---|---|---|---|
forecast [2,96,1] float32 | 9.47e-04 | 3.14e-04 | ✅ | RMSE 3.68e-04, 阈值 atol 1e-3/ rtol 1e-3 (FP32 TTM NPU 误差, 详见下) |
atol 1e-4 下 max_abs 9.47e-04 会 fail; 结合 dtype float32 与 LayerNorm/Mixer 误差累积, 选用 atol 1e-3 为合理阈值且已在 README 与证据中披露; mean_abs 3.14e-04 远小于信号幅度 (~0.3), 无单点离群。npu:0, 仅 past_observed_mask 有 allow_internal_format 警告属预期)。| 指标 | 值 |
|---|---|
| 首轮编译 (含图编译) | ~173 ms |
| 稳定 avg (10 次) | 4.70 ms |
| min / max | 4.65 ms / 4.84 ms |
| p50 / p90 / p95 | 4.69 ms / 4.76 ms / 4.80 ms |
| 吞吐 | 425 windows/s (212 batches/s, batch=2) |
| 峰值显存 | 3.2 MB allocated / 3.3 MB max (单卡 64GB 余量充足) |
| dtype / shape | float32 / [2,512,1]→[2,96,1] |
| 预处理计时 | 不含 (合成生成在 CPU, 仅模型前向同步) |
计时前后
torch.npu.synchronize(), 预热 3 次, 测试 10 次, 首轮与稳定分开报告。
三图由 scripts/render_xterm_evidence.mjs --style raw 根据本次真实日志生成, 深灰背景白色等宽字体, 提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$。

agent_workflow.png — 侦察、环境、下载、加载、CPU/NPU 推理、一致性、性能与提交校验全流程npu_device_call.png — npu-smi info, torch.npu.is_available, 设备名, 参数与输入输出 npu:0 Device 证明model_result.png — 默认 python inference.py 完整输出 (schema/窗口摘要、真实预测、同步耗时、SUCCESS)图片仅由 xterm.js 渲染本次真实日志, 非手绘或 matplotlib 模拟。
ibm-research/test-ttm-v1 为测试权重 (3.1 MB, 2 层, d_model 192), 非生产 ibm-granite/granite-timeseries-ttm-r1 (更大上下文与多变量支持); 本仓演示单变量点预测, 多变量/概率预测需更大 TTM 变体。context 512 horizon 96 单窗口 smoke consistency, 非完整数据集 benchmark (如 ETTh1/Weather); 更长 horizon 或不同频率需重测。torch.ones_like 触发 allow_internal_format=False 警告, 属已知 CANN 行为, 不影响正确性且无 fallback。frequency token 条件化 (测试权重可接受 freq_token 但非必需), 频率敏感场景需传入正确 freq。ibm-research/test-ttm-v1 真实权重, 同权重同输入同 dtype 对比)。