Toto-2.0 是 Datadog 的零样本时间序列基础模型:输入历史序列,输出 9 个分位数预测(q=0.5 为点预测)。整个 Toto 系列有4m / 22m / 313m / 1B / 2.5B 包含了 5 个不同大小的权重版本。
url=https://github.com/DataDog/toto
commit_id=44ea4e88852228039564aa3e76fac26aafac0803 # tag toto-2/v2.0.0
model_name=Toto-2.0
license=Apache-2.0输入数据
| 输入数据 | 数据类型 | 大小 | 数据排布格式 |
|---|---|---|---|
target | FLOAT32 | batch × V × context_length | ND |
target_mask | BOOL | batch × V × context_length | ND |
series_ids | INT64 | batch × 1 | ND |
context_length 即 --context-length;V 为变量数,ascend_infer.py 走单变量示例(V=1)。
输出数据
| 输出数据 | 数据类型 | 大小 | 数据排布格式 |
|---|---|---|---|
quantiles(保存前转 FP32) | FLOAT32 | 9 × batch × V × prediction_length | ND |
输出经 autocast 后的张量类型由实际算子决定,保存前统一转为 FP32。
prediction_length 即 --prediction-length,9 为分位数个数(q=0.1…0.9);分位数在最外维,ascend_infer.py 取 q=0.5 索引得到 (batch, prediction_length)。
| 配套 | 版本 | 来源 |
|---|---|---|
| 硬件 | Atlas 800I A3 | — |
| 固件与驱动 | 25.5.0 | 镜像 / 宿主环境 |
| CANN | 9.0.1 | 镜像内置 |
| Python | 3.12 | 镜像内置 |
| torch / torch_npu | 2.10.0/2.10.0.post2 | 镜像内置,勿重装 |
toto-2(导入名 toto2) | 2.0.0 | 源码安装并应用补丁,见下文 |
| gluonts / pandas | 0.15.1 / 2.2.3 | requirements.txt |
| pyarrow / numpy | 18.1.0 / 1.26.4 | requirements.txt |
export IMAGE=quay.io/ascend/vllm-ascend:v0.23.0rc1-a3
export CONTAINER=${CONTAINER:-toto-infer}
export WORKDIR=${WORKDIR:-$PWD}
docker run -itd -u root --net=host --privileged=true \
--name "${CONTAINER}" \
--shm-size=16g \
--device=/dev/davinci0 \
--device=/dev/davinci_manager \
--device=/dev/devmm_svm \
--device=/dev/hisi_hdc \
-v /usr/local/Ascend/driver:/usr/local/Ascend/driver \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /usr/local/sbin/npu-smi:/usr/local/sbin/npu-smi \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v "${WORKDIR}:${WORKDIR}" \
-v /root/.cache:/root/.cache \
"${IMAGE}" bash
docker exec -it "${CONTAINER}" bash
cd "${WORKDIR}"source /usr/local/Ascend/ascend-toolkit/set_env.sh
npu-smi info
python -c "import torch, torch_npu; print(torch.__version__, torch_npu.__version__, torch.npu.is_available())"预期最后一行形如 2.10.0+cpu 2.10.0.post2 True。
git clone https://gitcode.com/Ascend/ModelZoo-PyTorch
cd ModelZoo-PyTorch/ACL_PyTorch/built-in/nlp/Toto1)业务依赖(torch / torch_npu 由镜像提供):
pip install --no-deps -r requirements.txt
# 预检:requirements.txt 不固定、随镜像/上游走的导入期依赖
# (huggingface-hub / safetensors / fsspec / packaging / tqdm / PyYAML / filelock / typing-extensions / requests)
python -c "import importlib.util as u; p=[('huggingface_hub','huggingface-hub'),('safetensors','safetensors'),('fsspec','fsspec'),('packaging','packaging'),('tqdm','tqdm'),('yaml','PyYAML'),('filelock','filelock'),('typing_extensions','typing-extensions'),('requests','requests')]; m=[d for mod,d in p if u.find_spec(mod) is None]; print('import-time deps OK') if not m else print('MISSING: '+' '.join(m)+' -> pip install --no-deps '+' '.join(m))"预检必须通过再进第 2 步:huggingface-hub / safetensors 是 toto2 的模块级导入依赖,
缺任一个 import toto2 就直接 ModuleNotFoundError(与第 3 步是否执行无关)。
2)源码安装 toto2 并打补丁:
export TOTO_SRC=${TOTO_SRC:-./toto}
git clone https://github.com/DataDog/toto "${TOTO_SRC}"
git -C "${TOTO_SRC}" checkout 44ea4e88852228039564aa3e76fac26aafac0803
git -C "${TOTO_SRC}" apply "$(pwd)/Toto_NPU.patch"
pip install --no-deps -e "${TOTO_SRC}/toto2"
python -c "import inspect, toto2.model as m; print('patched' if 'clamp_min(0.0)' in inspect.getsource(m.PatchedCausalStdScaler) else 'NOT patched')"预期输出 patched。
3)官方评测框架(仅精度验证需要):
export GIFT_EVAL_SRC=${GIFT_EVAL_SRC:-./gift-eval-src}
git clone https://github.com/SalesforceAIResearch/gift-eval "${GIFT_EVAL_SRC}"
git -C "${GIFT_EVAL_SRC:?set the GIFT-Eval source directory}" checkout --detach 0b57dd6937eb
pip install --no-deps -e "${GIFT_EVAL_SRC}"
pip install --no-deps datasets==2.19.2 pyarrow_hotfix dill xxhash multiprocess fsspec aiohttp requests tqdm huggingface-hub packagingexport MODEL_DIR=$PWD/weight # 权重
export GIFT_EVAL_ROOT=$PWD/gift-eval # GIFT-Eval 数据集
export BOOM_DIR=$PWD/boom # 推理示例单序列
export OFFICIAL_DIR=$PWD/official # 官方结果表
export ASCEND_RT_VISIBLE_DEVICES=0 # 选卡:容器内一般为集合内下标,裸机为物理卡号export MODEL_ID=${MODEL_ID:-Datadog/Toto-2.0-4m}
hf download "${MODEL_ID}" --local-dir "${MODEL_DIR}"| 模型 | 权重大小 | 来源 |
|---|---|---|
| Toto-2.0-4m | 16.6 MB | https://huggingface.co/Datadog/Toto-2.0-4m |
| Toto-2.0-22m | 87.7 MB | https://huggingface.co/Datadog/Toto-2.0-22m |
| Toto-2.0-313m | 1.25 GB | https://huggingface.co/Datadog/Toto-2.0-313m |
| Toto-2.0-1B | 4.16 GB | https://huggingface.co/Datadog/Toto-2.0-1B |
| Toto-2.0-2.5B | 9.82 GB | https://huggingface.co/Datadog/Toto-2.0-2.5B |
1)GIFT-Eval 数据集(约 1.6 GB,精度验证用):
hf download Salesforce/GiftEval --repo-type dataset --local-dir "${GIFT_EVAL_ROOT}"数据集布局为 ${GIFT_EVAL_ROOT}/<数据集>/<频率>/data-00000-of-00001.arrow,<数据集>/<频率> 即评测配置名(如 ett1/H):
${GIFT_EVAL_ROOT}/
├── m4_{yearly,quarterly,monthly,weekly,daily,hourly}/data-00000-of-00001.arrow
└── <数据集>/<频率>/data-00000-of-00001.arrow2)推理示例用的单序列(BOOM 的 ds-0-T):
hf download Datadog/BOOM --repo-type dataset --include "ds-0-T/*" --local-dir "${BOOM_DIR}"
test -s "${BOOM_DIR}/ds-0-T/data-00000-of-00001.arrow" && echo okToto/
├── README.md ← 本文档
├── requirements.txt ← 业务依赖
├── Toto_NPU.patch ← 上游 4 处改动
├── ascend_infer.py ← 单序列推理入口
├── eval_accuracy.py ← GIFT-Eval 精度评测
├── eval_performance.py ← 性能评测(延迟 / 吞吐 / 批扫描 / 峰值显存)
├── weight/ ← 权重
├── toto/ ← 上游源码(源码安装方式)
├── gift-eval/ ← GIFT-Eval 数据集
├── gift-eval-src/ ← gift-eval 评测框架
├── boom/ ← 推理示例单序列
├── official/ ← 官方结果表
└── output/ ← predictions.npz / run_meta.json / CSV / JSONascend_infer.py 对单条序列滑窗推理,输出分位数中位(q=0.5)点预测;多序列 / 多变量走精度验证。
python ascend_infer.py \
--model-path "${MODEL_DIR}" \
--data "${BOOM_DIR}/ds-0-T/data-00000-of-00001.arrow" \
--context-length 4096 --prediction-length 96 --stride 96 --max-windows 20 \
--batch-size 20 \
--output ./output预期输出:
[ok] device=npu:0 precision=bf16_autocast windows=20 -> ./output三个入口均使用 FP32 权重和输入,前向统一开启 BF16 autocast。结果保存为 FP32。
产物:output/predictions.npz(y_true (windows, 96) / y_pred (windows, 96) / last_ctx (windows, 1),float32)与 output/run_meta.json。
| 参数 | 默认 | 可选值 | 说明 |
|---|---|---|---|
--model-path | 必填 | 目录 | 权重目录 |
--data | 必填 | Arrow 文件 | 单序列输入 |
--context-length | 4096 | 正整数 | 历史窗口长度 |
--prediction-length | 96 | 正整数 | 预测步长 |
--stride | 96 | 正整数 | 滑窗步长 |
--max-windows | 20 | 正整数 | 最多窗口数 |
--batch-size | 20 | 正整数 | 一次喂多少窗口 |
--decode-block-size | 768 | 正整数 | 解码分块,一般不改 |
--graph / --no-graph | 开 | 开 / 关 | 图模式;与 TASK_QUEUE_ENABLE=2 互斥 |
--output | ./output | 目录 | 结果目录 |
在 GIFT-Eval 上按官方协议进行零样本评测。本文的评测单元是“数据集/采样频率/预测长度档”,例如 ett1/H/short。short 评测 55 个数据集与频率组合,medium、long 各评测其中的 21 个,合计 55 + 21 + 21 = 97 个评测单元,每个单元输出一行指标。
--datasets all 读取 GIFT-Eval 源码仓的 scripts/dataset_configurations.csv,并通过 notebooks/toto_2_0.ipynb 取得实际数据目录名和 short 的评测顺序。已有源码仓时,将 GIFT_EVAL_SRC 指向上述提交的检出目录。变量未设置时使用当前目录下的 gift-eval-src。
精度评测的预测长度由 GIFT-Eval 的 Dataset(name, term).prediction_length 决定,不统一固定为 96。--context-length 控制输入长度。
先备好频率表与官方结果表(取自评测框架仓库,比对时用):
set -euo pipefail
cp "${GIFT_EVAL_SRC}/notebooks/dataset_properties.json" ./dataset_properties.json
for m in Toto-2.0-4m Toto-2.0-22m Toto-2.0-313m Toto-2.0-1B Toto-2.0-2.5B Seasonal_Naive; do
mkdir -p "${OFFICIAL_DIR}/${m}"
cp "${GIFT_EVAL_SRC}/results/${m}/all_results.csv" "${OFFICIAL_DIR}/${m}/"
done先跑单配置确认链路(约 1 分钟,以 Toto-2.0-4m 为例):
python eval_accuracy.py \
--gift-eval-root "${GIFT_EVAL_ROOT}" --model-path "${MODEL_DIR}" \
--datasets ett1/H --term short --batch-size 256 \
--properties ./dataset_properties.json --out-csv ./output/accuracy_smoke.csv[ok] ett1/H/short MASE=0.8486 CRPS=0.1868 precision=bf16_autocast (0.7s) peak_hbm=0.29GB
[summary] expected 1, done 1, failed 0, skipped 0, unresolved 0全量验证:
export BATCH=256 # 按模型取:4m 256 / 22m 256 / 313m 128 / 1B 256 / 2.5B 32
for t in short medium long; do
python eval_accuracy.py \
--gift-eval-root "${GIFT_EVAL_ROOT}" \
--model-path "${MODEL_DIR}" \
--datasets all --term "$t" \
--batch-size "${BATCH}" \
--properties ./dataset_properties.json \
--out-csv "./output/accuracy_$t.csv"
done中断后重跑同一条命令即可,脚本按 --out-csv 跳过全部指标非空的已完成项。
| 参数 | 默认 | 可选值 | 说明 |
|---|---|---|---|
--gift-eval-root | 必填 | 目录 | 数据集根目录 |
--model-path | 必填 | 目录 | 权重目录 |
--datasets | 必填 | 配置名 / all | all 从官方清单按 term 选择 55 / 21 个配置 |
--term | short | short / medium / long | 评测长度档 |
--context-length | 4096 | 正整数 | 官方默认,勿改 |
--batch-size | 512 | 正整数 | 显存不足时降 |
--properties | 空 | JSON | 频率表。缺省时先查已配置的 $GIFT_EVAL_SRC/notebooks/,再查当前目录。未配置源码路径的全量评测最后查 gift-eval-src/notebooks/ |
--out-csv | 必填 | CSV | 逐配置结果,支持断点续跑 |
--official / --naive | 空 | CSV | 给出后自动与官方结果比对 |
下表是 BF16 autocast 的已有精度结果。切换模型时使用不同的 --out-csv 文件。
精度结果(BF16 autocast,Atlas 800I A3 单卡,context_length=4096):表中为各预测长度档的归一化 MASE,即每个评测单元的 MASE 除以对应的 Seasonal Naive MASE 后取几何平均。
| 模型 | batch | short,55 项(本机/官方 MASE) | medium,21 项(本机/官方 MASE) | long,21 项(本机/官方 MASE) | 各档 MASE 相对差范围 |
|---|---|---|---|---|---|
| Toto-2.0-4m | 256 | 0.714265 / 0.713916 | 0.798156 / 0.798151 | 0.834802 / 0.834715 | 0.0006%–0.0488% |
| Toto-2.0-22m | 256 | 0.686822 / 0.686650 | 0.746307 / 0.746151 | 0.780670 / 0.780594 | 0.0097%–0.0250% |
| Toto-2.0-313m | 128 | 0.670542 / 0.670637 | 0.736079 / 0.736196 | 0.758751 / 0.758684 | 0.0088%–0.0158% |
| Toto-2.0-1B | 256 | 0.670784 / 0.670467 | 0.724310 / 0.724269 | 0.753929 / 0.753561 | 0.0056%–0.0489% |
| Toto-2.0-2.5B | 32 | 0.663775 / 0.663464 | 0.725760 / 0.726019 | 0.754776 / 0.754322 | 0.0358%–0.0602% |
各预测长度档的评测总耗时如下,batch 沿用上表。
| 模型 | short,55 项 | medium,21 项 | long,21 项 | 全部 97 项 |
|---|---|---|---|---|
| Toto-2.0-4m | 24 min | 8 min | 7 min | 约 39 min |
| Toto-2.0-22m | 26 min | 9 min | 8 min | 约 42 min |
| Toto-2.0-313m | 45 min | 12 min | 11 min | 约 68 min |
| Toto-2.0-1B | 70 min | 16 min | 15 min | 约 101 min |
| Toto-2.0-2.5B | 102 min | 16 min | 14 min | 约 132 min |
与官方结果比对:在上面任一评测命令后追加两个参数,跑完自动打印逐配置差异与聚合指标:
--official "${OFFICIAL_DIR}/Toto-2.0-4m/all_results.csv" \
--naive "${OFFICIAL_DIR}/Seasonal_Naive/all_results.csv"测单卡前向延迟与吞吐。batch 可按权重目录名中的模型规模自动选择;使用默认 weight 目录名时需显式指定 --batch-size。下面以 4m、batch=384 为例。
python eval_performance.py \
--model-path "${MODEL_DIR}" \
--context-length 4096 --prediction-length 96 \
--batch-size 384 --warmup 3 --rounds 7 --output ./output/perf.json输入为固定 seed 的合成标准正态张量,测前向链路,数据加载不计时;默认图模式(NPU Graph),--no-graph 关闭。
输出格式示例(数值以当前实测为准):
[mode] graph(NPU Graph)
[ok] batch=512 mode=graph median=0.031397s throughput=12289.07/s hbm=0.56GB| 参数 | 默认 | 可选值 | 说明 |
|---|---|---|---|
--model-path | 必填 | 目录 | 权重目录 |
--context-length | 4096 | 正整数 | 官方口径;调小更快但不能与官方结果比精度 |
--prediction-length | 96 | 正整数 | 预测步长 |
--batch-size | 0 | 0 或正整数 | 0=按权重目录名自动取最优批 |
--batches | 空 | 逗号分隔 | 逐点扫描 batch |
--warmup | 3 | 正整数 | 预热轮数(不计入中位数) |
--rounds | 7 | ≥3 | 计时轮数 |
--repeat | 1 | 正整数 | 独立重复次数 |
--graph / --no-graph | 开 | 开 / 关 | 图模式;与 TASK_QUEUE_ENABLE=2 互斥 |
--output | 必填 | JSON | 结果文件 |
以下性能表及 A100 对比来自原整模型 BF16 路径。当前已统一为 autocast,性能与图模式待重新实测,以下历史数据仅供参考。
性能结果(BF16 autocast,Atlas 800I A3 单卡独占,图模式,context=4096、horizon=96,预热 3 轮后计时 7 轮取中位数):
| 模型 | batch | 单次前向 | 每窗口 | 吞吐 | 峰值 HBM |
|---|---|---|---|---|---|
| Toto-2.0-4m | 384 | 31.40 ms | 0.0818 ms | 12230 窗/s | 0.56 GB |
| Toto-2.0-22m | 192 | 39.12 ms | 0.2037 ms | 4908 窗/s | 0.64 GB |
| Toto-2.0-313m | 128 | 185.88 ms | 1.4521 ms | 689 窗/s | 2.01 GB |
| Toto-2.0-1B | 96 | 328.33 ms | 3.4201 ms | 292 窗/s | 4.86 GB |
| Toto-2.0-2.5B | 64 | 456.52 ms | 7.1331 ms | 140 窗/s | 10.23 GB |
换 batch 用 --batches 64,128,256,512 逐点扫描;需要独立重复时加 --repeat 3。共享卡上吞吐偏低,精度不受影响。
** A100 对比**(context=1024、batch=8、horizon=96、bf16,--warmup 10 --rounds 200,每个模型独立跑 3 次取中位):
| 模型 | A3 单批耗时 | A100 单批耗时 |
|---|---|---|
| Toto-2.0-4m | 4.11 ms | 3.8 ms |
| Toto-2.0-22m | 6.34 ms | 5.0 ms |
| Toto-2.0-313m | 27.39 ms | 15.4 ms |
| Toto-2.0-1B | 50.34 ms | 20.9 ms |
| Toto-2.0-2.5B | 80.99 ms | 36.2 ms |
上游 toto2 的 4 处改动,全部在 Toto_NPU.patch(源码安装后 git apply):
| # | 改动 | 原因 | 影响 |
|---|---|---|---|
| 1 | PatchedCausalStdScaler.forward 增加 device.type == "npu" 分支,走 float32 | CANN 不支持 double,to(torch.float64) 静默降级;长上下文方差可能为负 | 避免 NPU 上使用不受支持的 float64 计算,降低长序列出现 NaN 的风险 |
| 2 | 方差加 clamp_min(0.0) | float32 累积舍入可能产生极小负值 | 方差为非负值时保持原值,负值置零后再开平方 |
| 3 | base_gids 掩码赋值改 torch.where | 布尔掩码走 nonzero,形状不可静态化 | 输出逐位相同,解锁图模式 |
| 4 | pyproject.toml:gluonts[torch]>=0.16.0 → ~=0.15.1 | 上游声明与官方 harness 钉的 0.15.1 冲突,带解析会 ResolutionImpossible | 依赖声明与 requirements.txt 一致 |
Q:import torch_npu 失败,或 torch.npu.is_available() 为 False。
A:先 source /usr/local/Ascend/ascend-toolkit/set_env.sh,再用 npu-smi info 确认卡已分配。ASCEND_RT_VISIBLE_DEVICES 取值与环境有关:容器内一般是集合内下标,裸机是物理卡号。
Q:FileNotFoundError: .../data-00000-of-00001.arrow。
A:数据集根目录不对,或配置名与目录大小写不一致(如 LOOP_SEATTLE/H)。
Q:NPU Graph requires TASK_QUEUE_ENABLE=1 or --no-graph。
A:export TASK_QUEUE_ENABLE=1,或加 --no-graph。
| 类型 | 说明 | 公网地址 |
|---|---|---|
| 开源代码仓 | DataDog/toto | https://github.com/DataDog/toto |
| 模型权重 | Toto-2.0-4m | https://huggingface.co/Datadog/Toto-2.0-4m |
| 模型权重 | Toto-2.0-22m | https://huggingface.co/Datadog/Toto-2.0-22m |
| 模型权重 | Toto-2.0-313m | https://huggingface.co/Datadog/Toto-2.0-313m |
| 模型权重 | Toto-2.0-1B | https://huggingface.co/Datadog/Toto-2.0-1B |
| 模型权重 | Toto-2.0-2.5B | https://huggingface.co/Datadog/Toto-2.0-2.5B |
| 评测框架 | gift-eval | https://github.com/SalesforceAIResearch/gift-eval |
| 数据集 | GIFT-Eval | https://huggingface.co/datasets/Salesforce/GiftEval |
| 数据集 | BOOM | https://huggingface.co/datasets/Datadog/BOOM |