模型名称: huggingface/time-series-transformer-tourism-monthly
模型链接: HuggingFace
模型描述: 基于 Transformer 编码器-解码器架构的时间序列预测模型,专为月度旅游数据 forecasting 训练。输入历史时间序列及时间特征,输出未来 24 个月的预测值(Student-T 分布采样)。
模型架构: TimeSeriesTransformer (Encoder-Decoder Transformer)
参数规模: 30,537 参数
输入规格:
past_values: (batch_size, 61) — 过去 61 个时间步的值past_time_features: (batch_size, 61, 2) — 过去时间步的时间特征past_observed_mask: (batch_size, 61) — 观测掩码static_categorical_features: (batch_size, 1) — 静态类别特征static_real_features: (batch_size, 1) — 静态实数特征future_time_features: (batch_size, 24, 2) — 未来时间步的时间特征输出规格:
sequences: (batch_size, num_samples, prediction_length) — 预测采样序列| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | >= 2.1.0 | PyTorch 框架 |
| torch-npu | >= 2.1.0 | 昇腾 NPU 后端 |
| transformers | >= 4.27.0 | HuggingFace Transformers |
| huggingface_hub | >= 0.20.0 | 模型下载 |
| numpy | >= 1.24.0 | 数值计算 |
| 昇腾驱动 | CANN 8.0+ | 推荐 CANN 8.5.1 |
安装命令:
pip install torch-npu>=2.1.0 transformers>=4.27.0 huggingface_hub>=0.20.0 numpy>=1.24.0# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"huggingface-cli download huggingface/time-series-transformer-tourism-monthly --local-dir ./model_weights# 基础推理(batch_size=2)
python inference.py --model-path ./model_weights --batch-size 2
# 自定义参数
python inference.py --model-path ./model_weights --batch-size 4 --num-samples 200本模型为标准 PyTorch 模型,直接通过 inference.py 脚本启动推理,无需额外服务进程:
python inference.py --model-path ./model_weights --batch-size 2推理脚本支持单批次推理和自回归生成,自动完成模型加载、NPU 迁移、前向传播和序列采样全流程。
基础调用:
python inference.py --model-path ./model_weights --batch-size 2自定义参数调用:
python inference.py --model-path ./model_weights --batch-size 4 --num-samples 200使用自定义测试数据调用:
python inference.py --model-path ./model_weights --batch-path ./my_data.pt --batch-size 8| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --model-path | str | 必填 | 模型 checkpoint 路径 |
| --batch-path | str | 内置路径 | 测试数据 .pt 文件路径 |
| --batch-size | int | 2 | 推理批次大小 |
| --num-samples | int | 100 | 自回归采样数量 |
[模型] huggingface/time-series-transformer-tourism-monthly
[设备] Ascend910_9362 (npu:0)
[输入] past_values: torch.Size([2, 61]), future_time_features: torch.Size([2, 24, 2])
[输出] sequences: torch.Size([2, 100, 24])
[前向传播耗时] 0.2766s
[自回归生成耗时] 0.1441s
[状态] SUCCESS运行命令:
python inference.py --model-path ./model_weights --batch-size 2输出:
============================================================
Time Series Transformer - Ascend NPU Inference
============================================================
[INFO] Checking NPU device availability...
[OK] NPU device count: 2
[OK] NPU device name: Ascend910_9362
[INFO] Loading model from: ./model_weights
[OK] Model loaded in 0.03s
[INFO] Total parameters: 30,537
[INFO] Moving model to NPU device...
[OK] Model moved to NPU in 1.14s
[INFO] Running forward pass...
[OK] Forward pass completed in 0.28s
[OK] Loss: 9.638490
[INFO] Generating predictions...
[OK] Generate completed in 0.14s
[OK] Prediction sequences shape: torch.Size([2, 100, 24])
[INFO] Mean predictions (first sample, first 5 steps):
[24700.682 32572.451 32531.746 36262.902 30570.146]
============================================================
[SUMMARY] Inference Results
============================================================
[MODEL] huggingface/time-series-transformer-tourism-monthly
[DEVICE] Ascend910_9362 (npu:0)
[BATCH] 2
[INPUT] past_values: torch.Size([2, 61])
[OUTPUT] sequences: torch.Size([2, 100, 24])
[PARAMS] 30,537
[FORWARD] 0.2766s
[GENERATE] 0.1441s
[STATUS] SUCCESS
============================================================


测试数据: hf-internal-testing/tourism-monthly-batch (64 samples)
| 指标 | 结果 | 说明 |
|---|---|---|
| 训练 Loss (NLL) | 9.638490 | 使用官方测试 batch 前向传播 |
| 参数量 | 30,537 | 模型总参数量 |
| 前向传播耗时 | 0.28s | batch_size=2, Ascend910 |
| 自回归生成耗时 | 0.14s | 100 parallel samples, 24 步 |
评测命令:
python inference.py --model-path ./model_weights --batch-size 2aten::lgamma.out 和 aten::_standard_gamma 算子当前在 NPU 后端回退到 CPU 执行(用于 Student-T 分布计算),对性能有一定影响,但功能正确。