#NPU
ibm-research/test-patchtsmixer (PatchTSMixerForPrediction, 2层, d_model=48)929deb5554d0dc787505243f5372463b241f0c68 (blobs 789KB model.safetensors, 196K params)max_pool -> Linear 1536->96 -> point forecast [B,96,7]), mode=common_channeltransformers PatchTSMixerForPrediction.from_pretrained + torch_npu, 无 remote codetime-series-forecasting注意: 本仓库为
test-patchtsmixer官方测试 checkpoint (README 说明正式模型为 https://huggingface.co/ibm-granite/granite-timeseries-patchtsmixer),权重与 granite-timeseries-patchtsmixer 结构一致 (d_model 48, 2 layers),已在单卡npu:0验证真实权重推理。
| 项 | 值 |
|---|---|
| 任务 | forecasting (点预测) |
| 架构族 | time-series PatchTSMixer |
| 加载后端 | transformers PatchTSMixerForPrediction |
| dtype | float32 |
| context_length | 512 |
| prediction_length | 96 |
| num_input_channels | 7 |
| num_targets | 3 (配置名义,实际输出 7 通道) |
| patch_length / patch_stride | 16 / 16 |
| num_patches | 32 |
| scaling | true (PatchTSMixerStdScaler per-channel, 模型内部) |
| mode | common_channel |
| head_aggregation | max_pool |
| input_shape | [B, T=512, C=7] float32 past_values + [B, T, C] observed_mask |
| output_shape | [B, H=96, C=7] forecast tensor prediction_outputs + loc [B,1,7] |
| 频率 | 无显式 freq token; 依赖内部 patch 位置 |
| 缺失 | observed_mask 全 True, 无插值 |
| 验证策略 | CPU vs NPU forecast tensor 对比 (forecasting) |
| 输入示例 | 确定性合成 (seed 42): t=0..511, freq=0.02*(c+1), value=sin(2π freq t + b*0.5) + 0.1 N(0,1) + c*0.1, batch=2, SHA256 2ce714834dabe91c (前16) |
| 预处理 | 无外部归一化; 缩放在模型内部; 输入为 raw float32 |
| 轴顺序 | 严格 [B,T,C] (禁止转置); 内部 patchify 为 [B,C,num_patches,patch_length] |
Ascend910_9362 (npu:0), driver 25.5.5, 2 NPUs (0000:0B:00.0, 0000:0A:00.0)/usr/local/Ascend/cann-8.5.1torch.npu.is_available()==True, device_count==2, torch.npu.get_device_name(0)==Ascend910_9362HF_ENDPOINT=https://hf-mirror.com (国内镜像, 无手动 http_proxy 覆盖)snapshot_download 或本地 working/models/test-patchtsmixer -> PatchTSMixerForPrediction.from_pretrained -> model.to("npu:0"), 所有 Tensor 显式 to(npu:0), 校验首参数 devicepip install -r requirements.txt
# 首次运行自动从 HF 镜像下载权重 (若本地不存在), 缓存至 HF hub 或 /tmp/test-patchtsmixer_download依赖见 requirements.txt: torch, torch_npu, transformers, safetensors, huggingface_hub, numpy.
默认命令完成真实 NPU 推理、同步计时与校验:
python inference.py流程:
torch.npu.is_available() 并锁定 npu:0.working/models/test-patchtsmixer 或 HF 缓存加载同权重 PatchTSMixerForPrediction.npu:0 并断言首参数 device==npu:0 (无 CPU fallback).past_values [2,512,7] + observed_mask 并移至 npu:0.torch.npu.synchronize() 计时.prediction_outputs [2,96,7] 预览、统计、SHA256、device 校验与 SUCCESS.无 CPU fallback: 输出 tensor device 校验为 npu:0, 无固定 device="cpu".
在 npu:0 (batch=2, context 512, horizon 96, 7ch, seed 42) 执行 python inference.py:
[INFO] model_name=ibm-research/test-patchtsmixer revision=929deb5554d0dc787505243f5372463b241f0c68
[INFO] config context_length=512 prediction_length=96 num_input_channels=7 d_model=48 num_layers=2 patch_length=16 num_patches=32 num_targets=3
[INFO] past_values shape (2, 512, 7) device cpu
[INFO] input preview ch0 first5 [0.049671, 0.111506, 0.313458, 0.520427, 0.458338]
[INFO] input stats mean 0.306118 std 0.739892 min -1.193994 max 1.843679
[INFO] input SHA256 2ce714834dabe91c
[INFO] input device npu:0
[INFO] warmup done compile/first-run 169.36 ms
[CHECK] first param device npu:0 output device npu:0 fallback_detected False
[RESULT] output prediction_outputs shape (2, 96, 7) device npu:0 dtype torch.float32
[RESULT] loc shape (2, 1, 7)
[RESULT] output preview first window first3 steps first3 channels:
[[ 0.62826025 0.24495828 -0.47008938]
[ 0.5110709 0.15090051 -0.40747142]
[ 0.39897928 0.06587921 -0.2994752 ]]
[RESULT] output stats mean 0.296376 std 0.270607 min -0.470089 max 1.293187
[RESULT] output SHA256 e6a295a4d5c32bdb
[PERF] compile/first-run 169.36 ms
[PERF] stable 10 runs avg 1.64 ms min 1.57 max 1.78 p50 1.64 p90 1.68 p95 1.73
[PERF] throughput 1219.89 windows/s
[SUCCESS] NPU inference completed on npu:0loc 同步返回 [2,1,7].
同权重、同输入、预处理、dtype、seed 下 CPU vs NPU forecast 对比:
python .opencode/skills/npu-adapt-skills/scripts/compare_outputs.py --cpu working/cpu_test_patchtsmixer.npy --npu working/npu_test_patchtsmixer.npy --task forecasting --atol 1e-4 --rtol 1e-3输出:
{
"task": "forecasting",
"cpu_shape": [2, 96, 7],
"npu_shape": [2, 96, 7],
"finite": true,
"atol": 1e-04, "rtol": 1e-03,
"max_abs_error": 5.03e-05,
"mean_abs_error": 1.46e-05,
"passed": true
}阈值 atol=1e-4, rtol=1e-3 适用于 FP32 PatchTSMixer (LayerNorm + MLP + Gated Attention + Linear head), 实测 max_abs 5.03e-05 < 阈值, 无 fallback, shape 一致.
torch.npu.synchronize()1043456 bytes (权重 789KB + 激活)三张 PNG 由 xterm.js 基于本次真实日志生成 (raw 风格, 提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$), 仅展示, 非手绘:

Manifest working/evidence_test_patchtsmixer.json 关联每张图与其源日志、命令、exit_code 与 UTC 时间.
distribution_output=student_t 的概率采样 (num_parallel_samples=100) 未在本次验证采样路径.npu:0; 多卡未用.