模型名称: ibm-research/test-patchtsmixer 模型链接: https://huggingface.co/ibm-research/test-patchtsmixer 模型描述: PatchTSMixer 是 IBM Research 提出的Patch-based时间序列混合模型,用于多变量时间序列预测任务。该模型将时间序列切分为patch,通过多层MLP混合器进行编码和预测,支持long-horizon forecasting。 模型架构: Patch-based Time Series Mixer (PatchTSMixer) 参数规模: 约 19.6 万参数 (196,144) 任务类型: 多变量时间序列预测 (Time Series Forecasting)
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch / torch_npu | 2.1.0+ | 昇腾 NPU 后端 |
| transformers | >= 4.57.0 | HuggingFace 库(包含 PatchTSMixer) |
| huggingface_hub | >= 0.20.0 | 模型加载 |
| numpy | >= 1.24.0 | 数值计算 |
| 昇腾驱动 | CANN 8.0.RC2+ | 推荐最新版 |
安装命令:
pip install torch torch_npu transformers huggingface_hub numpy# 检查 NPU 设备
npu-smi info# 使用内置测试数据(正弦波)进行推理
export TORCH_DEVICE_BACKEND_AUTOLOAD=0
python inference.py --device npu:0
# 使用自定义输入数据(npy格式,shape需为 512x7)
python inference.py --input_file my_timeseries.npy --device npu:0
# 指定模型路径
python inference.py --model_path /path/to/model --device npu:0| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --model_path | str | /data/models/ibm-research_test-patchtsmixer | 模型路径 |
| --input_file | str | None | 输入npy文件路径(shape: 512x7) |
| --device | str | npu:0 | 推理设备 |
| --context_length | int | 512 | 输入序列长度 |
| --num_channels | int | 7 | 输入通道数(变量数) |
| --prediction_length | int | 96 | 预测步长 |
| --num_targets | int | 3 | 目标变量数 |
模型期望输入形状为 (context_length, num_input_channels),即 (512, 7) 的 numpy 数组:
context_length=512:历史时间步长num_input_channels=7:多变量时间序列的变量数输入:
python inference.py --device npu:0程序自动生成 7 通道正弦波测试数据(512 个时间步)
输出:
[INFO] 检测到 2 个 NPU 设备: Ascend910_9362
[INFO] 加载模型: /data/models/ibm-research_test-patchtsmixer
[INFO] 模型参数量: 196,144
[模型] ibm-research/test-patchtsmixer
[设备] Ascend910_9362 (npu:0)
[输入] past_values (512x7)
[输出] prediction (96x7), range=[-0.6114, 0.6880]
[耗时] 174.9ms
[状态] SUCCESS
[预测结果] 全通道预测 shape: (96, 7)
[预测结果] 全通道范围: [-0.6114, 0.6880]
[预测结果] 目标变量均值范围: [-0.0220, 0.0363]
[预测结果] 目标变量标准差范围: [0.7107, 0.7187]输入:
# 创建自定义测试数据
python3 -c "
import numpy as np
data = np.random.randn(512, 7).astype(np.float32)
np.save('test_input.npy', data)
"
python inference.py --input_file test_input.npy --device npu:0输出:
[INFO] 加载模型: /data/models/ibm-research_test-patchtsmixer
[INFO] 模型参数量: 196,144
[模型] ibm-research/test-patchtsmixer
[设备] Ascend910_9362 (npu:0)
[输入] past_values (512x7)
[输出] prediction (96x7), range=[-2.1456, 2.8931]
[耗时] 168.2ms
[状态] SUCCESS


测试数据: 内置正弦波测试数据(模拟多变量时间序列) 评测指标: 预测值范围验证
| 指标 | 结果 |
|---|---|
| 全通道预测范围 | [-0.6114, 0.6880] |
| 目标变量均值范围 | [-0.0220, 0.0363] |
| 目标变量标准差范围 | [0.7107, 0.7187] |
| 推理耗时 (NPU) | ~175ms |
torch_npu 调用昇腾 NPU 设备.safetensors)不包含在此仓库中,请从 HuggingFace 下载--model_path 指定的路径(512, 7) 形状的 numpy 数组,对应模型的 context_length=512 和 num_input_channels=7prediction_length=96)