1
gcw_xUvjaUyi/cisco-time-series-model-1.0-preview-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

cisco-time-series-model-1.0-preview · 昇腾 NPU 推理

cisco-ai/cisco-time-series-model-1.0-preview 是 Cisco/Splunk 的多分辨率时序预测基础模型 (arXiv:2511.19841):基于 TimesFM2.0 变体 PatchedTSMultiResolutionDecoder 的 50 层 decoder-only transformer,通过 Resolution Embeddings + Special Token 实现多分辨率 (fine + coarse)上下文高效长序列预测。本仓库将其适配到昇腾 Ascend 910 NPU:架构代码 (Apache-2.0)已内嵌在单文件 inference.py 中,torch_npu 原生跑通 128 步预测。

模型信息

项值
HF 模型cisco-ai/cisco-time-series-model-1.0-preview
架构PatchedTSMultiResolutionDecoder(TimesFM2 变体)
参数498,832,800(约 4.99 亿)
权重文件torch_model.pt(1.99GB,fp32)
context_length_fine / coarse512 / 512
horizon_length128
patch_length32
freq_size3
num_hidden_layers50
hidden_size1280
quantiles0.1 ~ 0.9(9 个分位数)
agg_factor_default60
任务单变量零样本预测,输出 128 点 mean + 9 分位数

环境

项值
NPUAscend 910(Ascend910_9362)
CANN8.5.1
torch2.9.0+cpu
torch_npu2.9.0.post1
transformers4.57.6
推理设备npu:0(固定)

权重从 hf-mirror 自动下载,缓存路径固定为 ./model_weights/cisco-ai__cisco-time-series-model-1.0-preview/, 启动时优先加载本地缓存,命中则跳过下载。

安装

pip install -r requirements.txt

使用

1) CLI 单次推理(时序模型用 --text 数值数组)

python3 inference.py --text "[400.556,401.231,406.269,408.330,406.506,412.002,...]"

--text 传细分辨率(fine-resolution)时间序列上下文数值数组(支持任意长度,模型内部会 拆成 fine ≤512 + coarse ≤512 双分辨率上下文)。输出 JSON 包含:

  • forecast_mean:128 点均值预测
  • quantiles:0.1~0.9 共 9 个分位数预测
  • latency_ms、npu_name、device 等元信息

2) FastAPI 服务

uvicorn inference:app --host 0.0.0.0 --port 8001

POST /predict,请求体:

{"text": [400.556, 401.231, 406.269, ...], "horizon": 128}

返回推理 JSON:

{
  "model": "cisco-ai/cisco-time-series-model-1.0-preview",
  "device": "npu:0",
  "horizon": 128,
  "input_length": 1024,
  "latency_ms": 434.678,
  "forecast_mean": [379.137, 380.472, ...],
  "quantiles": {"0.1": [376.944, ...], ..., "0.9": [503.436, ...]}
}

健康检查:GET /health

昇腾 NPU 适配要点

  1. 代码全域无 GPU 设备调用;模型与输入 Tensor 全部迁移到 npu:0。
  2. main 入口带 try-except:torch_npu import 失败或 npu:0 不可用时打印清晰错误并优雅退出。
  3. 架构代码(PatchedTimeSeriesDecoder、PatchedTSMultiResolutionDecoder 等)来自 Apache-2.0 的 google-research/timesfm pytorch_patched_decoder.py 及 splunk/cisco-time-series-model,已内嵌到 inference.py,自包含运行。
  4. 权重加载校验 state_dict 键与实现一致(strict=False 并报告缺失/多余键)。

文件结构

  • inference.py:自包含推理入口(CLI + FastAPI 双模式)
  • requirements.txt:依赖清单
  • model_weights/:权重缓存(git 忽略,不提交)
  • assets/:验证截图

验证截图

agent_workflow

npu_device_call

model_result