S
Solis_caser/Granite-PatchTSMixer-Ascend-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

ibm-granite/granite-timeseries-patchtsmixer — 昇腾 NPU 适配与精简交付

模型介绍

本仓库适配 Hugging Face 官方时间序列模型 ibm-granite/granite-timeseries-patchtsmixer(固定 revision 90dc5a88d45f032b7dceefb5d814ca2af54f2ff9)到华为昇腾(Ascend)NPU,并完成真实 NPU 上的固定官方 ETTh1 样本前向推理。运行时按固定 MODEL_ID + revision 下载 config 与权重、按固定官方 ETDataset commit 下载 ETTh1.csv,缓存置于仓库外,禁止更换 checkpoint/数据源。模型为 PatchTSMixerForPrediction(PatchTSMixer 预测头):context_length=512、prediction_length=96、num_input_channels=7、patch 16×stride 16(32 patches)、d_model=48、2 层、distribution_output=student_t、loss=mse。这是 7 个传感器通道(ETTh1:HUFL/HULL/MUFL/MULL/LUFL/LULL/OT)的多元时间序列预测模型。

上游模型

资产运行时下载源固定值SHA256
config.jsonHF 官方 ibm-granite/granite-timeseries-patchtsmixer 固定 revision;失败回退比赛镜像 ai.gitcode.com/hf_mirrors/… 同 revision1182 bytes1574679e…b1525d
model.safetensors同上789328 bytes9b474a93…602a4f
ETTh1.csv官方 ETDataset 固定 commit 1d16c8f4f943005d613b5bc962e9eeb06058cf07(raw.githubusercontent.com/zhouhaoyi/ETDataset/…/ETT-small/ETTh1.csv)2589657 bytesf18de3ad…5ee066
  • 固定 revision:90dc5a88d45f032b7dceefb5d814ca2af54f2ff9
  • 数据与权重均为真实官方文件,非随机/合成样本。ETTh1.csv 含 17420 数据行 + 1 表头行(date + 7 数值列),每小时一个观测。
  • 缓存目录位于仓库外(tempfile.gettempdir() 下,按 model/revision 分目录),脚本复用已校验缓存,不写入仓库。

输入格式

模型输入为多元时间序列张量,本仓使用 ETTh1 固定窗口:

  • past_values:[batch, context_length, num_input_channels] = [1, 512, 7],来自 ETTh1 行 [11008, 11520),用 train 行 [0, 8640) 的 mean/std 标准化。
  • future_values:[batch, prediction_length, num_input_channels] = [1, 96, 7],来自 ETTh1 行 [11520, 11616),同一套统计标准化,作为真标签参与 MSE。
  • observed_mask:[1, 512, 7],全 1(真实观测)。
  • 全部为 float32,显式搬上 npu:0。输出 prediction_outputs 形状 [1, 96, 7]。

NPU 环境

推理在真实昇腾 NPU 上完成,而非 CPU 回退。运行环境由平台提供(本机实测):

  • 设备:Ascend910(npu-smi 显示 2 张健康芯片,Phy-ID 6/7,CANN 8.5.1)
  • 框架:torch 2.9.0+cpu + torch_npu 2.9.0.post1 + transformers 4.57.6 + numpy 1.26.4
  • 注意:torch、torch_npu 与 CANN 为底层昇腾栈,由运行环境提供,不能由 pip 替换,故不在 requirements.txt 中列出;如需自行部署,请按昇腾官方安装 CANN Toolkit + torch_npu 配套版本。
  • 应用层依赖见 requirements.txt:transformers==4.57.6、numpy>=1.24.0。

运行命令

pip install -r requirements.txt
flock -x -w 1800 /tmp/ascend-model-agent-npu-v1.lock bash -c 'python3 inference.py'

脚本按固定 MODEL_ID/revision 运行时下载 config 与权重(官方 HF 优先、失败回退比赛镜像),按固定 ETDataset commit 下载 ETTh1.csv;缓存优先复用(仓库外目录),下载后严格校验 bytes/SHA256。随后在 npu:0 上执行完整流程,打印每步证据(资产 SHA256、tensor 设备/形状、推理结果、最终 GO/NO_GO 判定)。退出码 0 表示通过全部断言(GO),非 0 表示 NO_GO。

实际结果

outputs/inference_results.json 中的本次真实运行结果(MODEL_ID=ibm-granite/granite-timeseries-patchtsmixer,revision 90dc5a88…,data_commit 1d16c8f4…,设备 npu:0):

{
  "model_id": "ibm-granite/granite-timeseries-patchtsmixer",
  "revision": "90dc5a88d45f032b7dceefb5d814ca2af54f2ff9",
  "data_commit": "1d16c8f4f943005d613b5bc962e9eeb06058cf07",
  "device": "npu:0",
  "outputs": {
    "prediction_outputs": [1, 96, 7],
    "prediction_outputs_device": "npu:0",
    "prediction_outputs_dtype": "torch.float32",
    "loss": 0.28261271119117737,
    "all_finite": true,
    "fixed_sample_mse_npu": 0.28261271119117737
  },
  "latency": {"timed_forward_seconds": 0.001597}
}
  • 参数、past_values/future_values/observed_mask、prediction_outputs、loss 均验证为 npu:0;输出 [1,96,7]、float32、全部 finite。
  • 固定样本 MSE 在 NPU 上计算为 0.28261,与模型 return_loss=True 返回的 loss 一致。
  • 七通道首个预测 [0.247046, 0.503542, 0.359562, 0.540095, -0.098541, 0.342299, -0.843927],首个标签 [0.351338, 0.699467, 0.463907, 0.553277, -0.396441, 0.246813, -0.862362]。
  • 最终判定:GO。

限制

  • 锁定条件:revision、SHA256、形状 [1,512,7]→[1,96,7]、设备 npu:0 均为固定断言,任一不符即 NO_GO。
  • 仅 NPU 前向:若断言失败、只能 CPU 前向或结果非 finite,明确报告 NO_GO,不伪造。
  • 串行保护:所有 NPU 相关命令(npu-smi、torch_npu 初始化、smoke、推理、复跑)均通过 flock -x -w 1800 /tmp/ascend-model-agent-npu-v1.lock 串行执行。
  • 本仓不含完整训练 CSV 缓存、wheel、临时文件或失败日志。

许可证

  • 模型权重与配置来自 Hugging Face ibm-granite/granite-timeseries-patchtsmixer,遵循其模型卡/上游许可证。
  • ETTh1 数据集为公开的 ETDataset(ETT)子集,遵循 ETT 原始许可条款。
  • 本仓适配代码与文档仅供比赛交付用途。

截图证据

本仓库已归档三张由真实适配与 NPU 运行页面截取的原始证据图:

文件内容
assets/agent_workflow.png模型 ID、固定 revision、资产校验、推理脚本和交付状态
assets/npu_device_call.png昇腾 NPU、参数、输入、输出与 loss 的 device/dtype/shape 证据
assets/model_result.png最终运行命令、真实输入窗口、真实输出、MSE 与耗时

机器可读的同次真实结果保存在 outputs/inference_results.json。截图均保持用户确认的原始像素,未裁剪、未编辑、未生成。