任务ID a1d608a124fd4f32a397b3fda742c7d3 · 原始权重 https://huggingface.co/ibm-granite/granite-timeseries-patchtst
#NPU
本仓库将 HuggingFace 上的 ibm-granite/granite-timeseries-patchtst(PatchTSTForPrediction,ETTh1 7通道,context 512,prediction 96,patch 12/12,d_model 128,3层 Transformer,16头,约614K参数,~2.4 MB model.safetensors)适配为可在单卡昇腾 Ascend 910B(npu:0)上真实运行的 GitCode AI model 仓库。支持点预测时间序列预测,输出预报张量,指标 MAE/RMSE 可在下游评估。
model.safetensors 2.4 MB,config.json context 512 prediction 96 patch 12(_name_or_path namctin/patchtst_etth1_forecast),transformers 4.36.0 版配置移植transformers 4.57.6 的 PatchTSTForPrediction(无需 trust_remote_code)| 项 | 值 |
|---|---|
| 模型 | ibm-granite/granite-timeseries-patchtst(revision 7fe295d, PatchTST, 614K, ETTh1) |
| 架构 | PatchTSTForPrediction(channel-independent patch embedding + 3层 Transformer encoder + prediction head) |
| 任务 | 时间序列点预测 forecasting(time-series-models.md 路线),验收 forecast tensor |
| 输入 | past_values [batch, time, channel] = [batch, 512, 7],7通道 ETTh1(HUFL,HULL,MUFL,MULL,LUFL,LULL,OT),float32,scaling std,past_observed_mask 默认为全1 |
| 输出 | prediction_outputs [batch, prediction_length, num_input_channels] = [batch, 96, 7],点预测 float32,已 inverse scale |
| 数据契约 | 轴顺序固定 [B,T,C](不可转置),context 512,horizon 96,patch 12/12→42 patches,通道 7,频率小时级 ETTh1,缩放 std(mean 0 std 1 逆变换已合并到 head),无辅助协变量,输入有限值校验 |
| 路由 | 点预测(参考 time-series-models.md),保存 forecast 并比较 MAE/RMSE,有标签可用 SMAPE |
npu:0)torch 2.9.0+cpu + torch_npu 2.9.0.post1,transformers 4.57.6,numpy 1.26.4,huggingface_hub/tmp/models/granite-timeseries-patchtst(或 hub cache models--ibm-granite--granite-timeseries-patchtst),首次约 2.4 MB + 331 KB 图片pip install -r requirements.txtinference.py 为自包含脚本,默认使用确定性合成 ETTh1-like 多变量时序(seed 42)在 npu:0 上完成 CPU 基线、NPU 推理、一致性与性能基准。核心 forward 的所有参数与参与计算的 Tensor 均显式位于 npu:0(见 npu_device_call.png 与 model_result.png)。计时前后均调用 torch.npu.synchronize()。
python inference.py
MODEL_DIR=/tmp/models/granite-timeseries-patchtst python inference.py以确定性合成 ETTh1 多变量时序(seed 42,past_values [2,512,7] 均值 0.0083 std 1.0022)为例:
past_values shape (2,512,7) float32,patching 42 patches(12/12),scaling std,axis [B,T,C]。forecast shape (2,96,7) 均值 0.037661 std 0.164059,样例 batch0 ch0 前5 [0.20202, 0.176456, 0.153266, 0.171155, 0.181743];batch1 ch0 前5 [-0.140478, -0.189977, -0.213437, -0.11593, -0.078209]。npu:0 上 forecast shape (2,96,7) 均值 0.0377,样例 batch0 ch0 前5 [0.20214, 0.176585, 0.153398, 0.171286, 0.18185];batch1 ch0 前5 [-0.140393, -0.189878, -0.213325, -0.115818, -0.078109]。[STATUS] SUCCESS - NPU inference completed without CPU fallback完整输出见 model_result.png。
python .claude/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu /tmp/cpu_granite.npy --npu /tmp/npu_granite.npy --task forecasting --atol 5e-4 --rtol 1e-3max_abs 1.64e-04,mean_abs 4.54e-05,atol=5e-4 rtol=1e-3 PASS,有限值 Trueatol=5e-4 为 FP32 跨设备正常波动avg 2.47 ms, min 2.45, max 2.52, p50 2.46, p90 2.52, p95 2.52(batch 2)808.52 windows/s(2 windows / 0.00247s)三图由 scripts/render_xterm_evidence.mjs --style raw 根据本次真实日志生成:
