ChatTime 是一个多模态时间序列基础模型(论文:ChatTime: A Unified Multimodal Time Series Foundation Model, AAAI 2025)。它把时间序列当作一种"外语",与文本统一建模。本模型 ChengsenWang/ChatTime-1-7B-Chat 是基于 ChatTime-1-7B-Base 在 ChatTime-1-Finetune-100K 指令数据上微调得到的 7B 规模对话版模型,底层架构为 LlamaForCausalLM(32 层,hidden=4096,42,001 词表),支持:
本仓库将 ChatTime 官方推理链路(Discretizer + Serializer + prompt 模板 + 采样生成)原样迁移到华为昇腾 NPU 单卡上,使用模型真实权重在 npu:0 完成端到端推理验证。
ChengsenWang/ChatTime-1-7B-Chat20baa88d6ab838b34abbd1d2b1f4cea57c8ff870| 项目 | 值 |
|---|---|
| NPU | Ascend910 (Ascend910_9362) x2,本任务使用 npu:0,HBM 64GB |
| CANN | /usr/local/Ascend/cann-8.5.1,npu-smi 25.5.5 |
| torch | 2.9.0+cpu |
| torch_npu | 2.9.0.post1+gitee7ba04 |
| transformers | 4.57.6 |
| numpy / pandas / scikit-learn / sentencepiece | 1.26.4 / 2.3.3 / 1.8.0 / 0.2.1 |
| Python | 3.11.14 |
设备可用性实测:
{
"torch_npu_available": true,
"npu_available": true,
"device_count": 2,
"device_name": "Ascend910_9362",
"error": null
}pip install -r requirements.txt模型权重先下载到本地(使用 huggingface_hub,环境已配置国内镜像直连):
python -c "from huggingface_hub import snapshot_download; snapshot_download('ChengsenWang/ChatTime-1-7B-Chat', local_dir='./model')"执行默认 NPU 推理(Traffic 零样本预测,hist_len=120,pred_len=24,8 个采样,bf16,seed=0):
CHATTIME_MODEL_DIR=/path/to/ChatTime-1-7B-Chat python3 inference.pyinference.py 自包含:内部实现 Discretizer / Serializer / prompt 模板,加载 LlamaForCausalLM 后显式迁移到 npu:0,使用 model.generate 完成采样生成,对 8 个采样取中位数得到最终 forecast。异常返回非零退出码。
数据契约(与官方一致):
[hist_len],float;默认 hist_len=120,预测 pred_len=24。###<value>###(4 位小数),NaN 序列化为 ###Nan###。[pred_len] forecast(已 inverse transform 回原始数值域),单位与输入一致。默认命令 python3 inference.py(npu:0,bf16)真实输出:
[MODEL] ChengsenWang/ChatTime-1-7B-Chat
[TASK] time-series zero-shot forecasting (Traffic sample)
[INPUT] hist_len=120 pred_len=24 hist_sha=fca96fc6a6196491
[INPUT] hist_min=-1.451566 hist_max=2.331956
[INPUT] input_tensor_device='npu:0' dtype=torch.bfloat16
[LOAD] model_device=npu:0 dtype=torch.bfloat16 num_parameters=6.82B load_time=8.96s
[RESULT] forecast_len=24
[RESULT] forecast=[0.5204, -0.004, -0.5749, -0.8644, -1.1001, -1.2586, -1.3207, -1.29, -1.1459, -0.833, -0.3002, 0.1246, 0.7792, 0.8121, 0.8204, 1.0369, 1.2938, 1.5427, 1.7126, 1.7012, 1.7255, 1.6997, 1.5404, 1.052]
[TIME] inference_total=2.964s (includes first-run compile, 8 samples)
[STATUS] PASS与官方 Traffic 样例真实值(pred_data)对比(固定单窗口验证):
| 指标 | 值 |
|---|---|
| MAE | 0.144556 |
| RMSE | 0.177252 |
CPU 与 NPU 使用完全相同的权重、数据切片(Traffic hist_len=120)、离散化/序列化预处理、采样参数、随机种子(seed=0)、eval 模式和 bf16 dtype。NPU 端模型与输入张量均位于 npu:0。
| 项目 | 值 |
|---|---|
| CPU forecast | 见 forecast_cpu.npy,耗时 1799.264s |
| NPU forecast | 见 forecast_npu.npy,耗时 2.936s |
| max_abs_error | 0.326896 |
| mean_abs_error | 0.092129 |
| 一致性结论 | PASS(atol=0.35, rtol=0.2,见 consistency.json) |
两者均为 8 个采样取中位数后的点预测,差异来源为采样随机性(NPU/CPU RNG 流不同)与数值精度,均值绝对误差 0.09 在数据尺度内可接受,属于固定样例 smoke consistency,不是完整数据集精度评测。
--mode benchmark:预热 1 次,正式测试 10 次,每次 torch.npu.synchronize() 计时(npu:0,bf16,hist=120,pred=24,8 samples)。
| 指标 | 值 |
|---|---|
| avg | 2.631s / window |
| min | 2.595s |
| max | 2.707s |
| p50 | 2.616s |
| p90 | 2.681s |
| p95 | 2.694s |
| 吞吐 | 0.380 windows/s |
计时包含单次预测完整生成(两次 chunk 生成、8 采样),不含模型加载与预处理。首轮编译已并入首跑耗时报告(inference_total=2.964s),benchmark 为稳定阶段。
以下三张图片均由 xterm.js 根据本次真实执行日志渲染(raw 模式),仅展示真实 stdout/stderr:
assets/agent_workflow.png:侦察、下载、加载、NPU 推理、一致性、性能与提交校验工作流。assets/npu_device_call.png:npu-smi info、torch.npu.is_available()、设备名、模型参数 device/dtype 证据。assets/model_result.png:python3 inference.py 的真实完整输出(含 forecast、耗时与 PASS)。pipeline 与 device_map="auto" 加载;本仓库改为显式 model.to("npu:0") + model.generate,数值行为与官方链路一致。#NPU、Ascend、Ascend910、time-series、forecasting、llama