本仓库适配 huggingface/time-series-transformer-tourism-monthly,模型架构为 TimeSeriesTransformerForPrediction,用于单变量月度时间序列预测。推理使用真实预训练权重、Transformer 编码器/解码器、lag 特征提取、参数投影与 Student‑T 分布头,并通过 torch_npu 在昇腾 Ascend 910B4 上执行。
huggingface/time-series-transformer-tourism-monthly2a40ad41f6ffe61e7bef6099b08c6c2fce36ac35model.safetensors,132652 bytesc887afd2e56856b968d39ace57d520cbefb17762036956bba83d78000401afe1Transformers 4.40.2 原始 generate() 会在 Student‑T 随机采样时调用 aten::_standard_gamma;当前 CANN/torch_npu 组合会将该算子回退到 CPU。为满足神经推理路径不得 CPU fallback 的验收要求,inference.py 严格沿用官方自回归循环,仅将 distr.sample() 替换为 NPU 上的 distr.mean,输出模式记为 autoregressive_student_t_conditional_mean。编码器、解码器、lag、参数投影和 Student‑T 头均未替换,预训练权重未修改;同时输出每一步的 Student‑T scale、标准差和自由度诊断。
已验收环境:
| 组件 | 版本/设备 |
|---|---|
| NPU | Ascend910B4-1,8 卡可见,本模型使用 npu:3 |
| CANN Toolkit | 8.5.1 (V100R001C25SPC002B220) |
| Python | 3.11.14 |
| torch | 2.9.0+cpu(与 torch_npu 配套,不能替换) |
| torch_npu | 2.9.0 |
| transformers | 4.40.2 |
| numpy | 1.26.4 |
| safetensors | 0.8.0 |
除容器内匹配的 torch/torch_npu 外,其余依赖使用阿里云镜像安装:
python -m pip install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt/work/pipeline/models/tabular16/time-series-transformer-tourism-monthly。requirements.txt 中的非 torch 依赖。python inference.py \
--device npu:3 \
--model-dir /work/pipeline/models/tabular16/time-series-transformer-tourism-monthly \
--num-parallel-samples 1若 NPU 初始化失败、任何神经张量不在 NPU、或推理异常,脚本会以非零状态退出,不会静默改用 CPU。CPU 只用于构造测试时间特征和对已 detach() 的结果进行 JSON 格式化。
输入由 inference.py 自行生成:61 个历史月度值(24 context + 最大 lag 37)、2 个时间特征、24 步未来时间特征、观测掩码以及静态特征。完整验收命令:
python inference.py --device npu:3 --num-parallel-samples 1关键实测输出:
inference mode : autoregressive_student_t_conditional_mean
input devices : past_values=npu:3, past_time_features=npu:3,
future_time_features=npu:3, past_observed_mask=npu:3,
static_categorical_features=npu:3, static_real_features=npu:3
model param devices: ['npu']
sequences shape : (1, 1, 24)
sequences device : npu:3
scale device : npu:3
stddev device : npu:3
output mode : autoregressive_student_t_conditional_mean
elapsed : 0.5914 s
peak NPU memory : 32.16 MiB
exit_code : 024 步条件均值预测为:
[36.858929, 38.397743, 36.934170, 33.670902, 30.814571, 29.340801,
28.585932, 27.867996, 27.678743, 29.059650, 32.566872, 35.421158,
38.300804, 39.419937, 38.069550, 35.417168, 33.215855, 32.151028,
31.646858, 30.938936, 30.480429, 31.574429, 34.678997, 36.835812]



torch.npu.is_available() 为 False,先确认特权容器映射了 NPU 设备并已加载 CANN 环境。aten::_standard_gamma、npu_cpu_fallback 或 fall back to run on the CPU,说明误用了上游随机采样路径,本仓库验收脚本会直接判失败。该适配保持上游 MIT 许可证。测试序列为 CC0-1.0。条件均值预测适用于确定性部署验证;若业务必须进行随机 Student‑T 采样,需要等待 _standard_gamma 获得原生 NPU 支持后重新验收,不能接受静默 CPU fallback。