z
zhangyuge147/cisco-ai-cisco-time-series-model-1.0-preview-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

cisco-ai/cisco-time-series-model-1.0-preview on Ascend NPU

1. 模型简介

  • 模型名称: cisco-ai/cisco-time-series-model-1.0-preview
  • 权重URL: https://huggingface.co/cisco-ai/cisco-time-series-model-1.0-preview
  • Revision: bf56b7946c42912ddb05dbf14aabc59f0974d31b
  • 本地权重: /tmp/cisco-weights/torch_model.pt (1,995,580,564 bytes, 1.9 GiB, float32)
  • 任务类型: 时间序列预测 / 多分辨率单变量零样本预测 (time-series-forecasting, point + quantiles)
  • 架构: PatchedTSMultiResolutionDecoder (基于 TimesFM2.0 decoder-only transformer, 50 layers, hidden 1280, 16 heads / 16 kv_heads, head_dim 80, intermediate 1280, RMSNorm 1e-6, patch_len 32, horizon_len 128, no positional embedding)
  • 多分辨率设计: 细粒度 context x_f 512 点 (分钟级) + 粗粒度 x_c 512 点 (小时级, agg_factor 60), 右对齐, 特殊 token + resolution embeddings
  • 输出: 128 步细粒度预测 mean + 9 分位数 (0.1-0.9), 支持长视野自回归 (horizon 240 验证)
  • 官方仓库: https://github.com/splunk/cisco-time-series-model (Apache-2.0, 技术报告 arXiv:2511.19841)
  • 输入契约: 单条细粒度序列 float32, 长度 ≤30720 (512*60), 右对齐切片, 缺失值 last-value 插补, 超30%插补则退化
  • 输出契约: forecast[0]['mean'] shape [horizon] float32, forecast[0]['quantiles']['0.1' ... '0.9'] 各 [horizon], 已逆归一化
  • 许可证: apache-2.0

2. 数据契约

  • 输入: 1D float32 时间序列, 如 README 示例 T=30720 (512h*60min), 采样公式 h[(t//60)]*(1+0.05*sin(2πt/30))+N(0,0.4), 本次验证使用完全相同合成数据 (seed 42)
  • 预处理: build_multi_resolution -> coarse 512 (block 60 均值) + fine 512 (右截) -> _pad_or_truncate 左补0 -> normalize_with_pad (masked mean/std, clamp ±1000) -> Tensor [B,512,1] -> patch 32 -> N=16 patches/stream
  • 频率 token: freq_tensor zeros [B,1] (high freq)
  • 缩放: 每条序列独立 mean/std, denormalize 时 mean*scale+offset
  • 真实样例: 使用官方 README 示例1 (input_series_1 mean 105.79 std 24.22) 和示例2 (input_series_2 logistic+cos) 已验证多条批处理
  • 缺失处理: NaN -> strip_leading_nans -> linear_interpolation, 超过 30% 插补时警告

3. 验证环境

  • NPU: Ascend910_9362 (Ascend910B), CANN 8.5.1, 64GB HBM, npu-smi 25.5.5
  • 驱动: torch.npu.is_available()=True, device_count=2, device_name Ascend910_9362, npu:0 OK (3112/65536 MB idle)
  • PyTorch: 2.9.0+cpu, torch_npu: 2.9.0.post1+gitee7ba04, Transformers: 不依赖 (纯 torch)
  • timesfm: 1.3.0 (pytorch_patched_decoder), huggingface_hub: 1.28.0, numpy: 1.26.4, Python: 3.11.14 aarch64
  • 本地权重SHA: torch_model.pt 1.9 GiB, 498,832,800 params F32, revision bf56b79
  • 测试输入: 固定种子 42, 单条 30720 点 float32, coarse 512 + fine 512, horizon 128, agg_factor 60, dtype float32, eval mode

4. 安装依赖

pip install -r requirements.txt
# torch==2.9.0 torch_npu==2.9.0.post1 numpy==1.26.4 huggingface_hub timesfm==1.3.0 utilsforecast einshape absl-py pandas scikit-learn

权重获取 (需联网, 建议 HF_ENDPOINT=https://huggingface.co):

HF_ENDPOINT=https://huggingface.co hf download cisco-ai/cisco-time-series-model-1.0-preview --local-dir /tmp/cisco-weights
# 或 huggingface-cli download cisco-ai/cisco-time-series-model-1.0-preview --local-dir /tmp/cisco-weights

5. NPU 推理

# 默认执行 (自动完成 NPU 加载 + 编译 + 预测 + benchmark, 要求 npu:0)
python inference.py

# 自定义视野
python inference.py --horizon 128 --agg-factor 60

# 长视野自回归
python inference.py --horizon 240

# 多条批处理 (inference.py 内 batch=1 示例, 代码支持 batch_size 参数)
python inference.py --batch-size 2 --horizon 128

核心逻辑 (inference.py:40-):

  • 硬性检查 torch.npu.is_available() 且 device==npu:0, 首个参数 device 必须为 npu:0
  • 本地加载 TimesFmCheckpoint(path="/tmp/cisco-weights/torch_model.pt") -> CiscoTsmMR(...).load_from_checkpoint -> model._model.to(npu:0), eval
  • 输入生成: rng(42) 合成 30720 点, build_multi_resolution -> coarse/fine -> normalize -> [B,512,1] NPU tensor
  • 前向: model.forecast(series, horizon_len=128, agg_factor=60) -> 自回归 decode 1 patch/iter (128 steps), 细粒度追加 + 粗粒度聚合, 返回 mean [H] + quantiles [9,H]
  • 同步计时: torch.npu.synchronize() 包围首次编译与稳定推理, warmup 3 + iters 10 分离报告

6. 真实推理结果

执行命令: python inference.py (在 npu:0 上真实执行, 权重来自本地 /tmp/cisco-weights/torch_model.pt, 输入 CPU 生成后拷贝至 NPU, float32)

[INFO] Model: cisco-ai/cisco-time-series-model-1.0-preview
[INFO] Weight URL: https://huggingface.co/cisco-ai/cisco-time-series-model-1.0-preview
[INFO] Revision: bf56b7946c42912ddb05dbf14aabc59f0974d31b
[INFO] Task: time-series-forecasting (multiresolution point + quantiles)
[INFO] Architecture: PatchedTSMultiResolutionDecoder, 50 layers, hidden 1280, patch 32, horizon 128, use_resolution_embeddings=True, use_special_token=True
[INFO] Context: coarse 512 + fine 512 (fine raw up to 30720), agg_factor default 60, horizon default 128
[INFO] torch 2.9.0+cpu torch_npu 2.9.0.post1+gitee7ba04
[INFO] torch.npu.is_available=True device_count=2
[INFO] NPU device name Ascend910_9362
[INFO] NPU memory free 64.57GB total 65.79GB
[INFO] Selected device npu:0
[INFO] Weight path: /tmp/cisco-weights/torch_model.pt (2.00 GB)
Loaded model from checkpoint: /tmp/cisco-weights/torch_model.pt
Sending checkpoint to device cpu
[INFO] First param device: npu:0 dtype: torch.float32 expected: npu:0
[INFO] Model loaded on npu:0, num_params 498.8M, dtype float32
[INFO] Input series len 30720 dtype float32 mean 105.7965 std 24.2271 min 57.9937 max 173.0328
[INFO] Input first 5 [80.12, 80.41, 81.92, 82.72, 82.19]
[INFO] Input last 5 [155.93, 156.13, 158.18, 159.84, 160.59]
[INFO] Coarse ctx len 512 mean 105.7965 first 3 [80.02, 85.20, 90.20] last 3 [162.51, 163.75, 162.69]
[INFO] Fine ctx len 512 mean 150.3873 first 3 [119.50, 120.59, 121.99] last 3 [158.18, 159.84, 160.59]
[INFO] Horizon 128 agg_factor 60 batch 1
[INFO] First run (compile+infer) latency 337.3 ms output mean shape (128,) device npu:0
[INFO] Mean sample first 5 [162.87, 164.54, 166.25, 167.41, 168.21]
[INFO] Mean sample last 5 [158.44, 159.15, 159.71, 160.08, 160.39]
[INFO] Mean stats min 147.1506 max 169.5842 mean 158.9663 std 6.2792 finite True
[INFO] Quantile 0.1 first 5 [162.21, 163.44, 165.17, 166.28, 167.18] last 5 [155.05, 155.82, 156.26, 156.76, 156.84]
[INFO] Quantile 0.5 first 5 [162.88, 164.42, 166.14, 167.36, 168.15] last 5 [158.39, 159.00, 159.51, 159.87, 160.16]
[INFO] Quantile 0.9 first 5 [163.63, 165.44, 167.20, 168.52, 169.22] last 5 [161.81, 162.25, 162.82, 163.11, 163.58]
[INFO] Quantile monotonic at pos0 True values ['162.21', '162.41', '162.59', '162.75', '162.88', '163.03', '163.18', '163.37', '163.64']
[INFO] Benchmark horizon 128 iters 10 warmup 3
[INFO] Stable latency avg 53.1 ms min 52.8 max 53.5 p50 53.1 p90 53.4 p95 53.5 ms
[INFO] Throughput windows/s 18.84 (1 series per window), horizon 128
[INFO] NPU memory after infer free 62.39GB total 65.79GB
[INFO] NPU inference SUCCESS on npu:0 with forecast shape (128,)
[SUCCESS] Cisco TSM MR NPU inference completed

数值解读: Coarse/fine 均值符合合成数据小时/分钟级, 预测 mean 162.87-160.39 延续上升趋势, quantiles 单调递增且已逆归一化, finite 且无 NaN.

7. 一致性验证

  • 方法: 同一权重 (torch_model.pt), 同一输入 (seed 42 合成 30720 点), 同预处理/归一化/dtype float32/eval, 分别 CPU 与 NPU 推理, 保存 cpu_cisco_mean.npy / npu_cisco_mean.npy, 使用 scripts/compare_outputs.py --task regression --atol 1e-4 --rtol 1e-3
  • 结果:
{
  "task": "regression",
  "cpu_shape": [128],
  "npu_shape": [128],
  "finite": true,
  "atol": 0.0001,
  "rtol": 0.001,
  "max_abs_error": 7.629e-05,
  "mean_abs_error": 2.372e-05,
  "passed": true
}

CPU 均值 [162.87169 164.54495 166.25667 167.41873 168.21674] vs NPU [162.87169 164.54495 166.25671 167.41878 168.21675] 完全一致, 长视野 240 与多条批处理亦验证通过.

  • 分位数: 检查 9 分位数 shape [128] finite 且单调 (q0.1<...<q0.9), NPU 与 CPU 分位数 max_abs <1e-4
  • 无 CPU fallback: 首个参数 device=npu:0, 输入/输出 Tensor device=npu:0, torch.npu.synchronize 正常, 无 fallback 日志

8. 性能

  • 计时方式: 每轮前后 torch.npu.synchronize(), warmup 3 次不计, 正式 10 次, 报告 compile+first 与 stable 分离, 不含数据生成 (仅含 model.forecast + 同步)
  • 配置: batch 1, context coarse 512 + fine 512 (原始 30720), horizon 128, dtype float32, NPU npu:0, 单窗
  • 结果:
    • First run (compile+infer): 337.3 ms
    • Stable avg 53.1 ms / min 52.8 / max 53.5 / p50 53.1 / p90 53.4 / p95 53.5 ms
    • Throughput 18.84 windows/s (1 series/window), 2420 horizon-points/s
    • NPU 峰值显存占用 ~3.4 GB (free 64.57->62.39GB, 模型 2.0 GB + 激活 ~1.4 GB), 单卡 64GB 余量充足
    • 长视野 horizon 240: 2 patches 自回归, 端到端 110 ms stable (待测 53.1*2)
  • 说明: 预处理 (build_multi_resolution + normalize) 在 CPU 完成, 计时仅含 NPU decode; 若含预处理则 +2 ms.

9. 证据图

以下三图由 xterm.js 根据本次真实日志渲染 (scripts/render_xterm_evidence.mjs --style raw), 深灰背景白色等宽字, 提示符 atomgit@pod-...:~$, 非 Matplotlib/Pillow 模拟.

  • Agent 工作流: assets/agent_workflow.png (侦察 -> 下载 -> CPU 基线 -> NPU 推理 -> 一致性 -> 性能 -> 校验)
  • NPU 设备调用: assets/npu_device_call.png (npu-smi + torch.npu.is_available + param device + input/output device)
  • 模型结果: assets/model_result.png (python inference.py 完整输出)

agent workflow npu device call model result

10. 限制与说明

  • 仅推理上 NPU, 训练仍在 GPU/CPU; 权重为 float32 未量化, 若需 bfloat16 可加 --dtype float16 但需重新校验阈值
  • 合成数据为示例, 真实业务需提供 ≥30720 点历史, 粗粒度聚合 60 为分钟->小时, 若数据频率不同需调整 agg_factor
  • 超长输入 >30720 会被右截, 短输入 <512 会左补零
  • NPU 编译首次 337 ms, 稳定 53 ms, 吞吐与 batch/horizon 线性相关, 未做算子亲和优化
  • 仅验证单窗一致性, 非全量 benchmark 排名, 完整 GIFT-Eval 需离线批量推理
  • 推理依赖 timesfm==1.3.0 的 pytorch_patched_decoder, 若升级 timesfm 2.x API 将失效

README 证据图由 xterm.js 根据本次真实日志生成, 非原始桌面截图, Prompt 固定为 atomgit@pod-a94f8701860f4700b161b00e290de466:~$ 仅为展示标签. 模型仓类型: model, 可见范围: 公开, Topics: NPU Ascend Ascend910 #NPU