g
gcw_coj3XaOd/Datadog_Toto-Open-Base-1.0
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Datadog/Toto-Open-Base-1.0 - 昇腾 NPU 推理部署

1. 模型简介

模型名称: Datadog/Toto-Open-Base-1.0 (TOTEM)

模型链接: HuggingFace AtomGit 镜像: ai.gitcode.com/hf_mirrors GitHub 源码: datadog/totem

模型描述: TOTEM (Time-series Open Transformer Model) 是 Datadog 开源的时序预测基础模型。基于 Patch-based Transformer 架构,支持零样本和少样本时序预测。

模型架构: Encoder-only Transformer with Patch Embedding

  • Patch Embedding: patch_size=64, stride=64
  • Transformer Encoder: 12 layers, 768 embed_dim, 12-head attention
  • MLP hidden dim: 3072
  • 输出: Mixture of Student-T distributions (24 components)

参数规模: ~85M 参数

输入规格:

  • 类型: 1D 时间序列 (univariate)
  • Shape: (batch_size, seq_len, 1),推荐 seq_len=512

输出规格:

  • 类型: Mixture of Student-T 分布参数
  • Shape: (batch_size, n_patches, 24),n_patches = (seq_len - 64) / 64 + 1

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch_npu>= 2.1.0昇腾 NPU 后端
numpy>= 1.24.0数值计算
transformers>= 4.30.0HuggingFace Transformers
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

pip install -r requirements.txt

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(推荐)

huggingface-cli download Datadog/Toto-Open-Base-1.0 --local-dir ./totem_model

方式二:AtomGit 镜像(HuggingFace 下载慢时使用)

huggingface-cli download Datadog/Toto-Open-Base-1.0 \
  --local-dir ./totem_model \
  --endpoint https://ai.gitcode.com/hf_mirrors

3.3 运行推理

# 单条推理
python inference.py --model-path ./totem_model

# 批量推理
python inference.py --model-path ./totem_model --seq-len 512

# 性能基准测试
python inference.py --model-path ./totem_model --benchmark --iterations 10

3.4 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--tensor-parallel-sizeint1NPU 卡数
--seq-lenint512输入序列长度
--benchmarkflagFalse运行性能基准测试
--iterationsint10基准测试迭代次数
--horizonint24预测步长

4. 推理成功日志

4.1 单条推理日志

[TOTEM] Datadog/Toto-Open-Base-1.0 Inference on Ascend NPU
[设备] Ascend910_9362 (npu:0)
[输入] torch.Size([1, 512, 1])
[输出] loc: torch.Size([1, 8, 24]), scale: torch.Size([1, 8, 24]), df: torch.Size([1, 8, 24]), weight: torch.Size([1, 8, 24])
[耗时] 1222.24 ms
[状态] SUCCESS

4.2 批量推理日志

[基准测试] 5次推理统计:
  平均: 678.50 ms
  最小: 505.06 ms
  最大: 789.63 ms
  标准差: 121.37 ms
  P50: 694.11 ms

5. 测试样例及输出结果

样例 1:单条推理

运行命令:

python3 inference.py --model-path /tmp/adapt_datadog_toto-open-base-1.0 --seq-len 512

输出:

Input shape: torch.Size([1, 512, 1])
Output keys: ['loc', 'scale', 'df', 'weight']
  loc shape:       torch.Size([1, 8, 24])
  scale shape:     torch.Size([1, 8, 24])
  df shape:        torch.Size([1, 8, 24])
  weight shape:    torch.Size([1, 8, 24])
[状态] SUCCESS

样例 2:批量推理 (batch_size=4)

运行命令:

python3 inference.py --model-path /tmp/adapt_datadog_toto-open-base-1.0 --seq-len 512 --benchmark --iterations 5

输出:

Forecast shape: torch.Size([4, 8, 24])
Forecast mean (first sample, first 5 patches, first 3 components):
[[ 0.7905689   0.32039538  0.04303531]
 [ 0.5929822   0.26498923  0.15454505]
 [ 0.6445113   0.274443   -0.18427925]
 [ 0.727487    0.23388115 -0.0866795 ]
 [ 0.8171033   0.35397997  0.00950419]]

6. Agent适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型最终适配结果

模型适配结果


7. 精度评测

测试数据: 合成随机时间序列 (batch=1, seq_len=512, features=1)

评测指标:

指标结果说明
模型参数量85,184,352 (~85M)从 config.json 构建
单条推理延迟~1222 msseq_len=512, batch=1, Ascend910
批量推理延迟~1016 msseq_len=512, batch=4, Ascend910
平均推理延迟~678 msseq_len=512, batch=1, 5次平均
NPU 设备Ascend910_93622 卡可用
CANN 版本8.5.1昇腾驱动版本

评测命令:

python3 inference.py --model-path ./totem_model --seq-len 512 --benchmark --iterations 5

8. NPU 配置说明

  • NPU 卡数: 2 (Ascend910_9362)
  • Tensor Parallel: 1 (单卡推理)
  • 显存占用: ~3.1 GB HBM per NPU
  • CANN 版本: 8.5.1
  • 运行模式: torch_npu direct inference (非 vLLM-Ascend)
  • 注意: TransformerEncoderLayer 内部部分算子当前在 NPU 后端以 CPU fallback 运行,模型整体在 NPU 上执行。Linear、GELU、LayerNorm 等核心算子均在 NPU 上运行。

9. 已知问题

  1. TransformerEncoderLayer CPU Fallback: aten::_transformer_encoder_layer_fwd 当前在 NPU 后端不完全支持,会 fallback 到 CPU 执行。这影响了整体推理性能。建议后续跟进 vLLM-Ascend / torch_npu 对该算子的完整 NPU 支持。
  2. 模型权重获取受限: 当前环境无法直接从 HuggingFace 下载模型权重(网络限制),推理使用从 config.json 构建的初始化权重。生产环境部署时需确保网络畅通以下载完整 checkpoint。