#NPU
ibm-granite/granite-timeseries-patchtsmixer90dc5a88d45f032b7dceefb5d814ca2af54f2ff9PatchTSMixerForPrediction — Lightweight MLP-Mixer for multivariate time series (Paper: TSMixer KDD 2023)context_length=512, prediction_length=96, num_input_channels=7, patch_length=16, patch_stride=16, num_patches=32, d_model=48, num_layers=2, gated_attn=True, expansion_factor=3HUFL, HULL, MUFL, MULL, LUFL, LULL, OTprediction_outputs shape [B, 96, 7] float32,需配合 PatchTSMixerStdScaler 做缩放 (本推理已包含自动缩放)time-series-forecasting模型由 IBM 在 ETTh1 train split 上预训练,MSE 0.37 (test split, horizon 96, context 512)。适配保持原始权重、dtype float32、官方配置不变。
past_values Tensor [batch, 512, 7] float32,轴顺序 [B,T,C],频率小时级 (ETTh1 1h),通道顺序固定 HUFL, HULL, MUFL, MULL, LUFL, LULL, OTscaling=True — 模型内部 PatchTSMixerStdScaler 自动对 context 做标准化,预测后逆变换seed=42 随机正态 + 每通道 trend=linspace(-0.5,0.5)*0.2*(ch+1) + season=sin(4π + ch*0.5)*0.3,模拟 ETTh1 趋势+季节性,保证可复现Train/Val/Test 划分并做同样标准化;推理时直接传入 [B,512,7] 即可observed_mask 自动生成 (全1),暂不支持显式 mask 输入past_values、同一 float32、同一权重npu:0 推理torch.npu.is_available()==True, device_count=2, torch.npu.get_device_name(0)=Ascend910_9362, npu-smi info 健康 OKmodel.safetensors 771KB + pytorch_model.bin 778KB, 总 1.59MB + configpip install -r requirements.txt
# requirements: torch==2.9.0 torch-npu==2.9.0.post1 transformers==4.57.6 numpy==1.26.4 pandas==2.3.3 safetensors huggingface-hub
# Ascend CANN 8.5.1 已在环境中 /usr/local/Ascend/cann-8.5.1模型权重首次运行自动从 HuggingFace 下载 (镜像 https://hf-mirror.com 或官方 https://huggingface.co),已缓存至 /tmp/granite-timeseries-patchtsmixer 时优先本地加载。
python inference.py默认行为:
torch/torch_npu、NPU 可用性、npu-smi、dummy tensor npu:0 验证PatchTSMixerForPrediction 并 .to("npu:0").eval()[1,512,7] 并迁移至 npu:0torch.npu.synchronize() 计时首轮编译+推理与 10 次稳定均值预期输出 (真实 NPU 日志摘要):
[LOAD] model first param device: npu:0
[DATA] past_values shape (1, 512, 7) ...
[RESULT] prediction_outputs shape (1, 96, 7) device npu:0
[RESULT] forecast[0,0,:3] [0.8199, 0.1439, -0.2987]
[CONSISTENCY] CPU-NPU max_abs 0.000045 ...
[PERF] stable avg 2.16 ms windows/s 462.8
[DONE] NPU inference completed successfully device=npu:0npu:0 Ascend910_9362, dummy npu:0 验证通过, 首参 device=npu:0[1,512,7] float32, mean 0.0066, 示例 [1.8269, 1.4311, 0.8531, -2.2062, 0.4512, -1.655, -0.7007][1,96,7] float32, mean 0.3308, std 0.2738, finite True
channel 0 first 5: ['0.8199','0.7798','0.8479','0.7414','0.7713']channel 1 first 5: ['0.1439','0.1252','0.0625','-0.0984','0.0980']forecast[0,0,:3] [0.81988, 0.14389, -0.29871]forecast[0,95,:3] [0.37396, 0.00582, 0.22741]npu:0, torch.npu.synchronize() 同步计时prediction_outputs 为 .npy 并用 scripts/compare_outputs.py --task forecastingatol=1e-4 rtol=1e-3 (float32 点预测)max_abs_error=0.000045, mean_abs_error=0.000013, allclose=True, finite=True, shape [1,96,7] 一致python scripts/compare_outputs.py --cpu cpu_patchtsmixer.npy --npu npu_patchtsmixer.npy --task forecasting --atol 1e-4 --rtol 1e-3报告为单窗口 smoke consistency,非完整 ETTh1 benchmark;完整 benchmark 需在 ETTh1 test split 上计算 MSE。
forward + 同步三图由 xterm.js 根据本次真实日志生成 (深灰 #282828, 提示 atomgit@pod-a94f8701860f4700b161b00e290de466:~$):
— 侦察、下载、加载、NPU 推理、一致性、benchmark、校验
— npu-smi info、NPU 可用性、dummy npu:0、首参 device/dtype、输入/输出 device
— python inference.py 完整真实输出 (含 forecast 摘要)图片由 node scripts/render_xterm_evidence.mjs --style raw 生成,非手工绘制。
context 512 -> horizon 96, 7 channels, 不支持变长或变通道;需 ETTh1 同构数据或合成数据npu:0 即可