w
gcw_uQ09W7jl/ibm-research-test-patchtsmixer-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

ibm-research/test-patchtsmixer - Ascend NPU 适配

#NPU #Ascend #Ascend910

模型 ibm-research/test-patchtsmixer(PatchTSMixerForPrediction,时间序列预测基础模型)已适配并在单卡昇腾 NPU(Ascend 910)上完成真实推理验证。

  • 模型 / revision:ibm-research/test-patchtsmixer(main)
  • 任务:多变量时间序列点预测(forecasting),7 通道,context 512 → prediction 96
  • 架构:PatchTSMixerForPrediction(transformers,loss=mse → 确定性点预测,输出已在原始数据尺度)
  • 加载后端:transformers.from_pretrained + torch_npu,无需 trust_remote_code
  • 权重:model.safetensors(约 0.20M 参数,float32)

数据契约

  • 数据源:公开 ETTh1 数据集(ETT-small),date + 7 个负载/温度通道
  • 通道顺序:HUFL, HULL, MUFL, MULL, LUFL, LULL, OT(保持官方顺序,不重排)
  • 输入张量:(batch, context_length, num_input_channels) = (1, 512, 7),dtype float32
  • 输出张量:(batch, prediction_length, num_input_channels) = (1, 96, 7),模型内部经 loc/scale 反归一化,返回原始数据尺度
  • 数据 SHA-256:1951ef88397ffebe8c5c8b2c9afaee1c54266cb65e985ceee8f275a56cd8cee1

环境

  • 昇腾:Ascend910(npu-smi 25.5.5),torch.npu.is_available()==True,设备数 2,目标设备 npu:0
  • 软件:Python 3.11、torch 2.9.0、torch_npu 2.9.0、transformers 4.57.6
  • CANN:8.5.1

安装

pip install -r requirements.txt

NPU 推理

默认命令在 npu:0 完成真实推理(需已联网下载权重,或通过环境变量指定本地模型/数据目录):

python inference.py --benchmark

可选参数:--model-dir、--local-csv、--context 512 --horizon 96、--benchmark。 inference.py 自包含,无本地私有依赖;模型与所有张量均显式置于 npu:0。

真实结果(npu:0)

  • 首次编译 + 推理:159.794 ms
  • 稳定推理:avg 1.640 ms(min 1.606 / max 1.680 / p50 1.633 / p90 1.675 / p95 1.677 ms)
  • 吞吐:609.68 windows/s
  • 峰值显存:1.3 MB
  • 预测误差(ETTh1 真实值,96 步 × 7 通道):MAE=1.1892 RMSE=1.8908
  • 首 8 步 OT 通道:pred 6.068, 6.140, 6.376, 6.526, 6.692, 6.867, 6.811, 6.963

一致性(CPU vs NPU)

同一权重、同一数据切片、同一 seed(42)、同一 dtype(float32)、同一预处理与 eval 模式:

  • 阈值:atol=1e-3, rtol=1e-3(FP32)
  • max_abs_error=3.22e-4,mean_abs_error=4.72e-5
  • 结果:通过

性能说明

性能测试:预热 3 次、正式 10 次,每轮前后 torch.npu.synchronize();首轮编译与稳定推理分开报告。数值为单窗口单次前向,不含 CSV 读取与 DataFrame 预处理时间。

证据图

以下三张图片由 xterm.js 依据本次真实运行日志(stdout/stderr、命令、退出码、UTC 时间戳)渲染生成,非人工补写或绘图库模拟:

  • assets/agent_workflow.png:侦察、数据检查、CPU 基线、NPU 推理、一致性、提交校验全流程
  • assets/npu_device_call.png:npu-smi、NPU 可用性、设备名、模型参数 device/dtype、输入输出 Tensor device
  • assets/model_result.png:python inference.py --benchmark 的真实完整输出

限制

  • 本模型为点预测(loss=mse),虽配置 distribution_output=student_t,但 MSE loss 分支使用确定性输出,未输出分位数样本
  • 单窗口 (1,512,7) 已验证;更大 batch 需按显存与算子支持复核
  • 验证数据集为 ETTh1 固定窗口切片,属 smoke/一致性验证,不构成完整 benchmark 排名