#NPU
ibm-research/test-patchtst (PatchTSTForPrediction, 测试版 PatchTST 时序预测)a8c54ceeaf3c9c4d864a33d650b156cc18b3ab53 — 本地快照 /tmp/work/test-patchtst (config.json 1287B, model.safetensors 2.4M)| 项 | 值 |
|---|---|
| 输入 | past_values [B, T, C] float32, 轴顺序 batch-time-channel, T=context_length 512, C=num_input_channels 7 |
| 上下文 context_length | 512 (论文及 ibm-granite/patchtst 标准, patch 12 → 42 patches) |
| 预测长度 prediction_length | 96 |
| 通道 C | 7 (ETTh1 兼容, 本验证 7 通道同时预测) |
| 输出 | prediction_outputs [B, H, C] float32, H=96, C=7, 点预测 (forecast tensor) |
| 缩放 | PatchTSTStdScaler (std scaling, 内部 loc/scale, mse loss) |
| 预处理 | 合成确定性序列 seed=0, randn + trend(线性) + seasonal(sin) 按通道, dtype float32, 无外部 CSV |
| 后处理 | 线性投影 head, 无逆变换外部依赖, 已 inverse-scale 内部完成 |
| 轴顺序 | [B,T,C] -> patchify -> transformer -> [B,H,C] |
| 来源 | 合成可追溯数据 seed 0, 完全复现, 满足表格/时序混合场景最小可验证集 |
表格数据提示词下,本模型按时序预测路线验证;若需 CSV 表格回归/分类,可将
past_values替换为[rows, features]映射后同样复用 NPU 路径。
torch.manual_seed(0) np.random.seed(0) model.eval() torch_npu.synchronize() 计时/tmp/work/test-patchtst, 无需远程代码, trust_remote_code=Falsepip install -r requirements.txt
# 权重已本地缓存 /tmp/work/test-patchtst, 若需手动:
# hf download ibm-research/test-patchtst --local-dir /tmp/work/test-patchtstpython inference.py默认 python inference.py 从本地 /tmp/work/test-patchtst 加载真实权重, 完成 NPU 推理并打印设备、输入输出摘要、同步耗时。首次运行含编译 ~3.2ms, 稳定 ~3.0ms。
输入: 合成 torch.randn(2,512,7) seed=0 + trend/season, 真实权重, 同一预处理
输出: prediction_outputs [2,96,7] 有限, 均值 ~0.209, 同步耗时已报告, npu:0
past_values [2,512,7] mean -0.0092 std 1.1035, past_values[0,0,:3]=[-1.2758,-1.4523,-0.7005]cpu_pred[0,0,:3]=[0.0998,-0.1055,-0.0522] cpu_pred[0,10,:3]=[0.2346,0.0138,0.0712]npu_pred[0,0,:3]=[0.0999,-0.1054,-0.0522] npu_pred[0,10,:3]=[0.2346,0.0138,0.0711]npu_pred[1,0,:3]=[-0.3778,-0.0390,-0.0323]NPU inference completed successfully device=npu:0完整输出见 assets/model_result.png (xterm 真实日志渲染, prompt atomgit@pod-a94f8701860f4700b161b00e290de466:~$ 仅为展示标签, 图片由 xterm.js 生成)。
torch.randn(2,512,7) seed=0 + trend/season, 同一权重 /tmp/work/test-patchtst/model.safetensors, 同一预处理, FP32, eval modeprediction_outputs [2,96,7] forecast tensor 点预测max_abs 0.000187 mean_abs 6.15e-05, atol=5e-4 rtol=1e-3 (FP32 NPU 算子容差, BatchNorm + GELU + attention 累积误差, 符合理论)python scripts/compare_outputs.py --task regression单窗口 smoke consistency (2 windows, 7 variates, 96 horizon), 非全量 benchmark;表格回归同样比较 forecast 数值, 分类则比较 logits/probabilities。
| 阶段 | 时间 |
|---|---|
| 首轮 (含编译) | 3.16 ms |
| 稳定 avg (10 runs, 3 warmup, sync) | 2.99 ms |
| min / max / p50 / p90 / p95 | 2.74 / 3.44 / 2.96 / 3.20 / 3.20 ms |
| 吞吐 | 668.9 windows/s, 1337.8 series*? (batch 2) |
| dtype | float32 |
| 峰值显存 | ~3.2GB HBM (npu-smi), 权重 2.4M + 激活 |
| 预处理计时 | 不含 CSV/DataFrame, 仅模型 forward, 已同步 torch.npu.synchronize() |
计时前后 torch.npu.synchronize(), 首轮与稳定分开报告。
assets/agent_workflow.png — 侦察、下载、CPU/NPU、一致性、推理全流程 (xterm.js 渲染, 真实日志)assets/npu_device_call.png — npu-smi、NPU 可用性、dummy tensor npu:0、模型参数 device npu:0assets/model_result.png — 默认 python inference.py 真实完整输出, 含 schema/窗口摘要、真实预测、同步耗时图片由 scripts/render_xterm_evidence.mjs --style raw 根据本次真实日志生成, 深灰背景白色等宽字体, 提示符固定为展示标签。
test-patchtst 测试权重, 非官方生产 ibm-granite/granite-timeseries-patchtst, 精度仅演示时序预测可行性。[B,512,7] 且 float32; 其他 shape 需 patch 对齐, 超长上下文需重训或滑动窗口。[7 通道] 与 dtype 一致。hardware: NPU (YAML frontmatter)