ibm-research/test-patchtsmixer NPU
#NPU Ascend 910B time-series forecasting PatchTSMixerForPrediction on npu:0 via torch_npu.
模型简介
- 模型名称:
ibm-research/test-patchtsmixer
- 模型权重URL: https://huggingface.co/ibm-research/test-patchtsmixer
- revision: 929deb5554d0dc787505243f5372463b241f0c68 (cache)
- 架构:
PatchTSMixerForPrediction (transformers 4.57.6, model_type patchtsmixer, _name_or_path ibm/patchtsmixer-etth1-pretrain)
- 任务: time-series forecasting 点预测 (ETTh1 7 channels, context 512 -> horizon 96)
- 加载 backend:
transformers.PatchTSMixerForPrediction.from_pretrained safetensors, float32, 无需 trust_remote_code
- 权重: 771KB (model.safetensors, 196144 params, ~0.75 MB)
数据契约
- 输入:
past_values float32 [batch, context_length, num_input_channels] = [B,512,7], 轴顺序 B T C, 无转置
- 合成输入: torch.randn seed 42, 均值约0.008 std1.0, 7 通道模拟 ETTh1 HUFL/HULL/MUFL/MULL/LUFL/LULL/OT
- 频率: 未指定 (null), 观测掩码: 全部 1 (无缺失), dtype float32, scale 默认清理
- 输出:
prediction_outputs [B,96,7] + loc/scale [B,1,7] (Student-t loc/scale),已做 inverse scaling
- 预处理: 无需外部缩放, 模型内部
scaling=True 依据 past_values 自动标准化
- batch: 固定 2, context 512, horizon 96, patch_length 16, num_patches 32, d_model 48, num_layers 2, mode common_channel
环境
- 平台: Ascend 910_9362 x2, NPU_VISIBLE_DEVICES=6,7, 目标设备
npu:0
- CANN: 8.5.1, torch 2.9.0+cpu, torch_npu 2.9.0.post1, transformers 4.57.6, python 3.11.14
- 显存: 权重 0.75MB, 推理峰值 < 350MB, 单卡充裕
安装
pip install -r requirements.txt
# requirements: torch, torch-npu, transformers>=4.36, numpy, huggingface_hub, safetensors
NPU 推理
- 默认从本地
working/model_test_patchtsmixer 加载, 回退到 HF cache 或在线下载 (首次需联网)
- 显式
model.to("npu:0") 与 past.to("npu:0"), 日志打印 device、dtype、shape、耗时, 前后 torch.npu.synchronize()
- 失败返回非零退出码
真实结果 (本次运行)
- CPU baseline: shape (2,96,7) mean -0.036452 std 0.234344 min -0.893760 max 0.825257
- batch0 前5 channel0: [0.7754599, 0.7455660, 0.8252569, 0.7308591, 0.7693954]
- batch0 前5 channel1: [-0.0928829, -0.0930704, -0.1361618, -0.2835214, -0.0746850]
- NPU (npu:0): shape (2,96,7) dtype float32 device npu:0 mean -0.036455 std 0.234339
- batch0 前5 channel0: [0.7754821, 0.7455883, 0.8252814, 0.7308655, 0.7694057]
- batch0 前5 channel1: [-0.0928642, -0.0930500, -0.1361364, -0.2834927, -0.0746558]
- 首轮同步耗时 ~162.6 ms, 稳定阶段 1.62 ms/iter
一致性
- 保存 CPU/NPU
prediction_outputs 为 npy, 运行 python scripts/compare_outputs.py --task forecasting --atol 1e-4 --rtol 1e-3
- 结果: max_abs 6.63e-05 mean_abs 1.73e-05 passed True, all finite True, 仅 smoke consistency 单 batch
- 阈值依据 FP32 小模型容差放松为 atol1e-4 rtol1e-3
- 验证无 CPU fallback: 所有参数 device == npu:0
性能
- 预热 3 次, 正式 10 次, 前后
torch.npu.synchronize(), batch 2
- avg 1.62 ms min 1.58 max 1.68 p50 1.64 p90 1.68 p95 1.68 ms/iter (windows)
- 首轮/编译 ~1.64 ms (首个 timed iter)
- 吞吐 1233 windows/s, 616 series/s (batch 2)
- 不含 CSV/预处理计时, 纯模型前向
证据图
assets/agent_workflow.png - 工作流 (侦察/下载/加载/NPU/一致性/性能)
assets/npu_device_call.png - 设备调用 (npu-smi, check_npu, 参数与张量 npu:0)
assets/model_result.png - 默认推理完整输出
- 图片由 xterm.js 根据本次真实日志生成 (prompt
atomgit@pod-a94f8701860f4700b161b00e290de466:~$), 非手绘
限制
- test-* checkpoint, 仅用于适配验证, 非官方生产权重 ibm-granite/granite-timeseries-patchtsmixer
- 固定合成 ETTh1-like 正态输入, 未用真实 ETTh1 数据集评测完整指标 (仅 smoke)
- 单卡 FP32, 未测 BF16/FP16, 未测多 batch/变长 context
- 超出 horizon/channel 配置需改 config