g
gcw_coj3XaOd/theforecastingcompany_t0-alpha
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

T0-Alpha - 昇腾 NPU 推理部署

1. 模型简介

模型名称: theforecastingcompany/t0-alpha

模型链接: HuggingFace

模型描述: T0-Alpha 是一个开源的时间序列预测基础模型,采用 decoder-style patch transformer 架构,输出概率性多步预测(quantile forecasts),原生支持多变量协变量。

模型架构: Decoder-style Patch Transformer (T0Forecaster)

参数规模: ~102M (101,641,536)

输入规格:

  • 类型:浮点时间序列 (float32/float64)
  • Shape:[batch, time] 或 [batch, variates, time]
  • 推荐 context length:96

输出规格:

  • 类型:概率分位数预测 (FloatTensor)
  • Shape:[batch, horizon, num_quantiles]
  • 默认分位数:[0.1, 0.25, 0.5, 0.75, 0.9]

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch_npu>= 2.1.0昇腾 NPU 后端
tfc-t0>= 0.3.0T0 模型库
safetensors>= 0.4.0权重加载
transformers>= 4.30.0AutoConfig(可选)
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

pip install torch-npu>=2.1.0 tfc-t0>=0.3.0 safetensors transformers

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info

# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"

3.2 模型下载

# 方式一:HuggingFace(需接受 gated 授权)
huggingface-cli download theforecastingcompany/t0-alpha --local-dir ./t0-alpha

# 方式二:AtomGit 镜像
git clone https://gitcode.com/<username>/theforecastingcompany_t0-alpha.git

3.3 运行推理

# 单条推理
python inference.py --model-path ./t0-alpha --context-len 96 --horizon 64

# 批量推理
python inference.py --model-path ./t0-alpha --benchmark --batch-size 8

3.4 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--context-lenint96历史上下文长度
--horizonint64预测步长
--devicestrnpu:0NPU 设备
--benchmarkflagFalse运行批量基准测试
--batch-sizeint8批量大小

4. 推理成功日志

4.1 单条推理日志

[Device] Ascend910_9362 (npu:0)
[Model] Parameters: 101641536
[Model] Quantile levels: (0.1, 0.25, 0.5, 0.75, 0.9)
[Inference] Single sample: context=96, horizon=64
[Inference] Quantiles shape: [1, 64, 5]
[Inference] Median shape: [1, 64]
[Inference] Latency: 499.6ms
[Inference] Median[:5]: [-0.1588, -0.1839, -0.1643, -0.0998, -0.0569]
[Inference] P10[:5]: [-1.2610, -0.7927, -0.1588, 0.5313, 1.1888]
[Inference] P90[:5]: [0.9432, 0.4249, -0.1588, -0.7307, -1.3025]
[Status] SUCCESS

4.2 批量推理日志

[Benchmark] Batch size=8, context=96, horizon=64
[Benchmark] Quantiles shape: [8, 64, 3]
[Benchmark] Batch latency: 89.0ms
[Benchmark] Per sample: 11.1ms
[Status] SUCCESS

5. 测试样例及输出结果

样例 1:单条概率预测

运行命令:

python inference.py --model-path ./t0-alpha --context-len 96 --horizon 64

输出:

[Inference] Quantiles shape: [1, 64, 5]
[Inference] Latency: 499.6ms
[Inference] Median[:5]: [-0.1588, -0.1839, -0.1643, -0.0998, -0.0569]
[Status] SUCCESS

样例 2:批量预测(8 条)

运行命令:

python inference.py --model-path ./t0-alpha --benchmark --batch-size 8

输出:

[Benchmark] Batch latency: 89.0ms
[Benchmark] Per sample: 11.1ms
[Status] SUCCESS

6. Agent 适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

测试数据: FEV-Bench / GIFT-Eval(参考 HuggingFace model card)

评测指标:

指标结果Baseline
Skill Score (FEV-Bench)42.2—
CRPS (GIFT-Eval)0.4941—
MASE (GIFT-Eval)0.7240—

评测命令:

python -m t0.evaluation.predictor --model-path ./t0-alpha --dataset autogluon/fev-bench

8. NPU 配置说明

  • NPU 型号: Ascend910_9362
  • NPU 数量: 2 卡
  • Tensor Parallel: 单卡推理(模型 102M 参数,单卡足够)
  • 显存占用: ~3.7 GB HBM
  • CANN 版本: 8.5.1
  • torch_npu 版本: 2.9.0

9. 已知问题

  1. 模型为 gated repo,需要 HuggingFace 授权后方可下载
  2. tfc-t0 库依赖 einops、jaxtyping、rotary-embedding-torch,安装时注意版本兼容
  3. NPU 上首次推理可能触发 torch_npu 算子编译缓存(~30s),后续推理正常