g
gcw_coj3XaOd/cisco_time_series_model_1_0_preview
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

cisco-ai/cisco-time-series-model-1.0-preview - 昇腾 NPU 推理部署

1. 模型简介

模型名称: cisco-ai/cisco-time-series-model-1.0-preview

模型链接: HuggingFace

模型描述: Cisco Time Series Model 是一个用于单变量零样本时序预测的基础模型。核心是一系列 decoder-only Transformer 层,基于 TimesFM 2.0 并增加了多分辨率修改,旨在高效利用长上下文。模型接收多分辨率上下文 (xc, xf),其中 xc 的分辨率是 xf 的 60 倍,输出 128 个点的预测及对应的 9 个分位数。

模型架构: PatchedTSMultiResolutionDecoder (Patch-based Decoder Transformer, 50 layers)

参数规模: 498.83M

输入规格:

  • 粗分辨率上下文 (xc): 长度最多 512,分辨率为 60× 细分辨率
  • 细分辨率上下文 (xf): 长度最多 512 (最多 512×60=30720 个原始采样点)
  • 频率索引: 0 (高频率/分钟级)

输出规格:

  • 预测均值: (horizon_len,) numpy array
  • 预测分位数: 9 个分位数 (0.1~0.9),每个 (horizon_len,) numpy array

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch_npu>= 2.1.0昇腾 NPU 后端
numpy>= 1.24.0数值计算
safetensors>= 0.4.0模型权重加载
huggingface_hub>= 0.23.0模型下载
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

pip install torch numpy safetensors huggingface_hub torch_npu

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 cisco-ai/cisco-time-series-model-1.0-preview --local-dir ./model

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

# https://ai.gitcode.com/hf_mirrors/cisco-ai/cisco-time-series-model-1.0-preview

3.3 启动推理脚本

# 运行完整测试(单序列 + 多序列 + 长序列)
python inference.py --model-path ./model/model.safetensors --test --backend npu

# 自定义参数预测
python inference.py --model-path ./model/model.safetensors --horizon-len 128 --agg-factor 60 --backend npu

3.4 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--testflagFalse运行测试用例
--horizon-lenint128预测步长
--agg-factorint60粗/细分辨率聚合因子 (60=分钟→小时)
--backendstrnpu设备后端 (cpu/gpu/npu)

4. 推理调用

4.1 Python API 调用示例

import torch_npu
import numpy as np
from inference import CiscoTsmMR, TimesFmHparams, TimesFmCheckpoint

# 初始化 NPU 设备
torch.npu.set_device(0)
device = torch.device("npu", 0)

# 创建模型超参数
hparams = TimesFmHparams(
    num_layers=50,
    context_length_fine=512,
    context_length_coarse=512,
    horizon_length=128,
    use_positional_embedding=False,
)

# 加载 checkpoint
ckpt = TimesFmCheckpoint(model_path="./model/model.safetensors")

# 创建模型
model = CiscoTsmMR(
    hparams=hparams,
    checkpoint=ckpt,
    use_resolution_embeddings=True,
    use_special_token=True,
)

# 单序列推理
input_series = np.random.randn(30720).astype(np.float32)
forecast = model.forecast(input_series, horizon_len=128)
print(f"Mean forecast (first 10): {forecast[:10]}")

4.2 命令行调用示例

# 单序列预测
python inference.py --model-path ./model/model.safetensors --backend npu

# 多序列批量预测
python inference.py --model-path ./model/model.safetensors --batch-size 4 --backend npu

# 长序列预测
python inference.py --model-path ./model/model.safetensors --horizon-len 240 --backend npu

5. 推理成功日志

4.1 模型加载

[INFO] NPU device: Ascend910_9362
[INFO] [Model] cisco-ai/cisco-time-series-model-1.0-preview
[INFO] [Device] npu
[INFO] [Model] Loaded in 5.24 seconds
[INFO] [Model] Total parameters: 498832800 (498.83M)
[Status] SUCCESS

4.2 单条推理

[Test 1] Single series forecasting (horizon=128)
  Input series length: 30720
  Forecast horizon: 128
  Mean forecast (first 10): [162.87 164.54 166.26 167.42 168.22 168.94 169.22 169.58 169.80 169.90]
  Q0.1 (first 5): [162.21 163.44 165.18 166.29 167.19]
  Q0.5 (first 5): [162.88 164.42 166.14 167.37 168.15]
  Q0.9 (first 5): [163.64 165.45 167.20 168.52 169.23]
  Inference time: 0.35 seconds
  [Test 1] PASSED

4.3 批量推理

[Test 2] Multiple series forecasting (2 series)
  Series 1 mean (first 5): [162.87 164.54 166.26 167.42 168.22]
  Series 2 mean (first 5): [79.70 79.64 79.53 79.48 79.50]
  Inference time: 0.06 seconds
  [Test 2] PASSED

6. 测试样例及输出结果

样例 1:单序列预测 (horizon=128)

运行命令:

python inference.py --model-path ./model/model.safetensors --backend npu

输出:

[INFO] Mean forecast (first 10): [162.8717 164.5449 166.2567 167.4188 168.2167 168.9427 169.2167 169.5842 169.8027 169.8956]
[INFO] Inference time: 0.35 seconds
[INFO] [Test 1] PASSED

样例 2:多序列批量预测

运行命令:

# inference.py 内置 Test 2 自动执行

输出:

[INFO] Series 1 mean (first 5): [162.8717 164.5449 166.2567 167.4188 168.2167]
[INFO] Series 2 mean (first 5): [79.6994 79.6358 79.5318 79.4785 79.4956]
[INFO] Inference time: 0.06 seconds
[INFO] [Test 2] PASSED

样例 3:长序列预测 (horizon=240)

运行命令:

python inference.py --model-path ./model/model.safetensors --horizon-len 240 --backend npu

输出:

[INFO] Mean forecast (first 10): [162.8717 164.5449 166.2567 167.4188 168.2167 168.9427 169.2167 169.5842 ...]
[INFO] Mean forecast (last 10): [139.9758 139.3790 138.7508 138.3758 138.5786 138.8284 139.3424 139.9815 ...]
[INFO] Inference time: 0.08 seconds
[INFO] [Test 3] PASSED

7. Agent 适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


8. 精度评测

测试数据: 合成正弦波时间序列 (30720 点,模拟分钟级监控数据)

评测指标:

指标结果说明
模型加载时间5.24s4.5GB safetensors → NPU
单序列推理 (h=128)0.35s含前处理 + 推理 + 后处理
双序列批量推理0.06sbatch_size=2
长序列推理 (h=240)0.08sautoregressive decoding
模型参数量498.83M50-layer Transformer

评测命令:

python inference.py --model-path ./model/model.safetensors --test --backend npu

实际输出:

[INFO] All tests PASSED
[INFO] [Status] SUCCESS - Model loaded and ready for inference

9. NPU 配置说明

  • NPU 型号: Ascend910_9362
  • NPU 数量: 2 卡
  • 推理设备: npu:0
  • CANN 版本: 8.5.1
  • 显存占用: ~10.8 GB (模型 4.5GB + 中间激活)
  • Tensor Parallel: 单卡推理 (模型 498M 参数可单卡承载)

10. 已知问题

无。模型在 Ascend910 NPU 上通过 torch_nPU 后端完整运行,所有测试用例通过。