#NPU #Ascend #Ascend910 #time-series #forecasting #TimeSeriesTransformer
huggingface/time-series-transformer-tourism-monthlyhttps://huggingface.co/huggingface/time-series-transformer-tourism-monthly2a40ad41f6ffe61e7bef6099b08c6c2fce36ac35 (main, 2026-08-20)time_series_transformer (TimeSeriesTransformerForPrediction), 时间序列概率预测 (probabilistic forecasting with Student-t)d_model=26, encoder_layers=2, decoder_layers=2, encoder_ffn_dim=32, decoder_ffn_dim=32, encoder_attention_heads=2, decoder_attention_heads=2, context_length=24, prediction_length=24, lags_sequence=[1,2,3,4,5,6,7,11,12,13,23,24,25,35,36,37], feature_size=27, num_static_categorical_features=1, num_static_real_features=1, num_time_features=2, cardinality=[366], embedding_dimension=[6], distribution_output=student_t, num_parallel_samples=100, loss=nll, scaling=Truemodel.safetensors 130KB + pytorch_model.bin 148KB 共 278KB (30.5K 参数, FP32), 总权重字节 283590time-series / 概率预测 (routing: time-series family, 24-step monthly forecast)license: mit, datasets monash_tsf)transformers (TimeSeriesTransformerForPrediction), 兼容 4.40.1model 仓, 公开, topics NPU Ascend Ascend910Time Series Transformer 是 Hugging Face 官方为时序预测训练的 vanilla encoder-decoder Transformer, 在 Monash tourism-monthly 上训练 30 epochs, 推理时自回归生成 100 个采样并可取 median/mean 作为点预测。本适配锁定官方 tourism-monthly 权重, 未更换模型, 仅迁移推理到 Ascend npu:0。
| 项 | 值 |
|---|---|
| 任务 | forecasting (probabilistic) 月度旅游流量 24 步预测 |
| 输入轴顺序 | past_values [batch, past_length]=[1,61] where 61 = context 24 + max(lags)=37; past_time_features [1,61,2], past_observed_mask [1,61], static_categorical_features [1,1] (时序ID), static_real_features [1,1], future_time_features [1,24,2] |
| 输出轴顺序 | 概率分布参数 params tuple (df, loc, scale) each [1,24] + 采样 sequences [1,100,24] (median [1,24]), future_time_features 已逆缩放回原始量纲 (原始 tourism 数值) |
| 通道 | input_size=1 单变量, num_dynamic_real_features=0 无外生变量 |
| 频率/时间特征 | num_time_features=2 (month-of-year Fourier), past_length 固定 61, 不可任意截断;lags_sequence 16 项已编码在权重中 |
| 缩放方式 | scaling=True per-window TimeSeriesMeanScaler (窗口均值/方差缩放, 模型内部完成, 输出已逆变换) |
| 数据来源 | hf-internal-testing/tourism-monthly-batch (train-batch.pt, 64 样本, 来自 Monash tourism-monthly, 可复现) |
| 数据 SHA | 样本 0 past_values SHA256 前缀 10a68d22e699 (raw float32 bytes), 固定索引可复现 |
| 列名/dtype | 纯 Tensor float32/int64, 无 DataFrame 列顺序问题;past_values float32, past_time_features float32, static_categorical_features int64 |
| 预处理契约 | 不改变轴顺序, 持官方 lags 顺序, past_observed_mask 全 1 (无缺失), future_observed_mask 仅训练时用于 loss, 推理时可传 |
| 真实样例 | 样本 0 past_values [0:5]=[19081,20436,27477,26577,23441], future_values [0:5]=[22816,35055,33590,36115,32583] (原始 tourism 数值) |
| 是否随机输入 | 否, 固定 HF 真实 batch 样本 0, 业务结果为确定性分布参数 + 采样 median |
/usr/local/Ascend/cann-8.5.1, NPU Ascend910_9362 (910B), 设备数 2, 目标 npu:0npu-smi info, python scripts/check_npu.py (torch.npu.is_available()==True, device_count>=1)pip install -r requirements.txtpip install -r requirements.txt
# 模型本地快照已在 working/models/... 但 inference.py 支持自动从 HF Hub 拉取
# 如需离线, 提前下载: huggingface-cli download huggingface/time-series-transformer-tourism-monthly --local-dir working/models/huggingface-time-series-transformer-tourism-monthly默认在 npu:0 上执行, 自动同步计时, 失败则非零退出:
python inference.py
# 或指定参数
python inference.py --model huggingface/time-series-transformer-tourism-monthly --device npu:0 --seed 0
# benchmark 已默认在脚本内执行 (warmup 3, test 10)inference.py 自包含, 默认 python inference.py 完成真实 NPU 推理, 打印模型名、任务、backend、device、dtype、首个参数 device、输入摘要、输出摘要、同步耗时和最终状态。所有参数显式搬运到 npu:0, 无静默 CPU fallback。输出包含确定性 loc/scale/df 与采样 median.
以下为本次在 npu:0 上的真实输出 (与 working/evidence_logs/model_result.log 一致, UTC 2026-08-20):
past_values [1,61] float32 on npu:0, SHA 10a68d22e699, preview [19081,20436,27477,26577,23441], future_time_features [1,24,2]First param device: npu:0, dtype: torch.float32, Params on NPU: 99/99, NPU available: True, device_name: Ascend910_9362loc [1,24] float32 on npu:0, preview loc [0:10]=[0.889,1.112,1.176,1.238,1.090,1.413,1.290,1.180,0.934,1.143], scale [0:10]=[0.146,0.150,0.150,0.150,0.145,0.155,0.151,0.148,0.141,0.143], df [0:10]=[6.172,6.060,6.090,6.114,6.311,6.048,6.157,6.230,6.431,6.387], loss 9.517980sequences [1,100,24] on npu:0, median [1,24] preview [25312.42,32398.61,32756.86,35000.49,31001.40,38375.98,35601.24,31154.84,26758.64,32761.56], sequences mean 32030.08 std 6885.06 (采样因 aten::_standard_gamma CPU fallback 导致 RNG 分支, 详见一致性节)0.2363s, forward 稳定推理 0.0067s, generate 单次 0.1701s (含 torch.npu.synchronize() 前后)CPU 基线 (同一权重/输入/seed/dtype/eval mode) 在 working/cpu_for_compare.npy 上的 loc 预览 [0.889,1.112,1.176,1.238,1.090] 与 NPU 数值一致 (误差 2.21e-05)。
loc 参数 (点预测核心) 原始 tensor [1,24], 非标签, 非 Top-5, 保存为 .npy (另保存 df/scale 验证)working/cpu_for_compare.npy shape [1,24] (loc)working/npu_for_compare.npy shape [1,24] (loc)python scripts/compare_outputs.py --cpu working/cpu_for_compare.npy --npu working/npu_for_compare.npy --task forecasting --atol 1e-4 --rtol 1e-3max_abs_error 2.22e-05, mean_abs_error 1.38e-05, finite True, passed True (阈值 1e-4/1e-3 严格通过, FP32)df max 1.19e-05, scale max 4.76e-07 均通过同阈值;generate median 因采样 aten::_standard_gamma 在 NPU 上 CPU fallback 导致 RNG 路径差异, median max 2782 mean 873 (非确定性, 不作为严格一致性门禁, 已在推理日志中说明)2a40ad41f6... 权重, transformers 后端npu:0, 输入输出均在 npu:0, 仅 lgamma/_standard_gamma 算子因 NPU 未支持而 fallback 到 CPU (已在日志中告警, 不影响分布参数一致性)torch.npu.synchronize() 前后计时, 预热 3 次, 正式 10 次, batch 1:
0.2363s (forward, 含首次 model(past_values...))avg 0.0067s, min 0.0065s, max 0.0069s, p50 0.0066s, p90 0.0068s, p95 0.0068s150.33 windows/s (1/avg), series/s 同值 (univariate)avg 0.0962s (采样路径, 含 100 并行采样与 CPU fallback)6.6 MB (torch.npu.max_memory_allocated(0))复现:
python inference.py自动执行 warmup+benchmark 并打印上述指标
三张 PNG 由 scripts/render_xterm_evidence.mjs --style raw 根据本次真实日志生成, 深灰背景、白色等宽字体, 提示符 atomgit@pod-a94f8701860f4700b161b00e290de466:~$, 非 Pillow 模拟:
assets/agent_workflow.png — 侦察、下载、加载、NPU 推理、一致性、benchmark 与提交校验assets/npu_device_call.png — npu-smi info, torch.npu.is_available(), 参数 device/dtype, 输入输出 Tensor deviceassets/model_result.png — python inference.py 完整输出 (含 schema、真实预测、同步耗时)图片由 xterm.js 渲染本次真实日志, 非手绘。

context_length=24 (past 61) 与 prediction_length=24 (配置文件固定), 超长 context 需重训input_size=1, num_input_channels 未配置多变量fit() 训练迁移; 概率采样 num_parallel_samples=100 路径因 NPU aten::_standard_gamma 不支持而 CPU fallback, 采样结果不具严格跨设备比特一致性, 但分布参数 loc/scale/df 严格一致past_time_features 与 future_time_features (2 维月度特征), 静态特征 static_categorical_features [366] 需正确编码