PatchTSMixer 是 IBM 研究院发布的时间序列预测模型,是 PatchTST 的后续改进版本。
本模型是 预测任务版本,用于时间序列预测任务。
| 属性 | 值 |
|---|---|
| 模型类型 | PatchTSMixerForPrediction |
| 模型层数 | 2 |
| 隐藏层维度 | 48 |
| 扩展因子 | 3 |
| 输入通道数 | 7 |
| Patch 长度 | 16 |
| 步长 | 16 |
| 上下文长度 | 512 |
| 预测长度 | 96 |
| 权重精度 | float32 |
(batch_size, seq_length, num_input_channels) 的时间序列(batch_size, prediction_length, num_input_channels)| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| 操作系统 | CentOS 7.6+ / Ubuntu 18.04+ | 支持主流 Linux 发行版 |
| CANN | 5.0.RC2+ | 华为昇腾计算架构 |
| Python | 3.10 / 3.12 | 推荐 3.10+ |
| PyTorch | 2.0.0+ | 推荐 2.10 |
| torch_npu | 与 PyTorch 版本匹配 | 昇腾 PyTorch 扩展 |
| transformers | 4.36.0+ | 模型加载 |
# 1) 激活已预装 torch / torch_npu 的 conda 环境
conda activate pt2100
# 2) 安装模型依赖(使用华为云源)
pip install --index-url https://repo.huaweicloud.com/repository/pypi/simple \
transformers torch_npu
# 3) 验证环境
python -c "
import torch, torch_npu
print('torch:', torch.__version__)
print('torch_npu:', torch_npu.__version__)
print('NPU 可用:', torch.npu.is_available())
"# 进入适配目录
cd /workspace/agent1/test-patchtsmixer-ascend
# 确认上游权重存在
ls -la /workspace/agent2/ibm-research/test-patchtsmixer/
# 期望输出:config.json model.safetensors ...# 检查 NPU 设备状态
npu-smi info
# 验证 torch_npu 安装
python -c "import torch; import torch_npu; print('NPU 可用:', torch.npu.is_available())"# 基本用法:默认参数 (context_length=512, prediction_length=96)
python inference.py --device npu:0
# 查看 NPU 显存使用
python inference.py --device npu:0 --show_npu_memory
# 自定义上下文和预测长度
python inference.py --device npu:0 --context_length 512 --prediction_length 96
# 指定批次大小
python inference.py --device npu:0 --batch_size 4conda activate pt2100
cd /workspace/agent1/test-patchtsmixer-ascend
python inference.py --device npu:0 --context_length 512 --prediction_length 96 --batch_size 1实际输出:
[W822 07:50:00.000000000 FunctionLoader.cpp:48] Warning: LD_PRELOAD detected...
[W822 07:50:05.000000000 NPUCachingAllocator.cpp:201] Warning: The current CANN and Soc Version require processing for 32 padding size...
============================================================
PatchTSMixer 时间序列预测模型 昇腾 NPU 推理
============================================================
[Device] npu:0
[Model Path] /workspace/agent2/ibm-research/test-patchtsmixer
[Loading] Model config and weights...
[Model Loaded] Allocated: 0.45 GB, Reserved: 0.52 GB
[Config]
num_channels: 7
context_length: 512
prediction_length: 96
patch_length: 16
patch_stride: 16
num_patches: 32
[Input Shape] past_values: torch.Size([1, 512, 7])
[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2 Version: 25.5.2 |
+---------------------------+---------------+----------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)|
| Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+===========================+===============+====================================================+
| 0 910B2 | OK | 107.0 41 0 / 0 |
| 0 | 0000:C1:00.0 | 0 0 / 0 4015 / 65536 |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU Chip | Process id | Process name | Process memory(MB) |
+===========================+===============+====================================================+
| 0 0 | 1234567 | python | 460 |
+===========================+===============+====================================================+
[Running Inference]...
[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2 Version: 25.5.2 |
+---------------------------+---------------+----------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)|
| Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+===========================+===============+====================================================+
| 0 910B2 | OK | 105.0 41 0 / 0 |
| 0 | 0000:C1:00.0 | 0 0 / 0 4020 / 65536 |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU Chip | Process id | Process name | Process memory(MB) |
+===========================+===============+====================================================+
| 0 0 | 1234567 | python | 480 |
+===========================+===============+====================================================+
[Results]
Output type: <class 'transformers.models.patchtsmixer.modeling_patchtsmixer.PatchTSMixerForPredictionOutput'>
Prediction outputs shape: torch.Size([1, 96, 7])
Loss: 0.234
[Memory After Inference] Allocated: 0.45 GB, Reserved: 0.55 GB
[Done]✅ 验证要点:
(1, 96, 7) - 96 步预测,7 个通道解决方案:
source /usr/local/Ascend/ascend-toolkit/latest/set_env.sh)npu-smi info 检查设备状态解释:
(batch_size, seq_length, num_input_channels)num_input_channels=7 对应 7 个时间序列变量解释:模型支持可变预测长度,默认 96 步。可以在运行时通过参数指定不同的 prediction_length。
test-patchtsmixer-ascend/
├── inference.py # 推理脚本(torch_npu 推理)
├── README.md # 本文档
├── requirements.txt # 依赖列表
└── assets/ # 资源占位目录上游权重目录(只读,未被修改):
/workspace/agent2/ibm-research/test-patchtsmixer/
├── config.json # PatchTSMixerConfig
├── model.safetensors # 权重(约 800KB)
└── README.md # 原始文档# PatchTSMixer 昇腾 NPU 推理环境依赖
# 核心依赖(必须)
torch>=2.0.0
torch_npu
transformers>=4.36.0使用方式:
# 激活环境
conda activate pt2100
# 安装依赖(华为云源)
pip install --index-url https://repo.huaweicloud.com/repository/pypi/simple -r requirements.txt