g
gcw_coj3XaOd/ChatTime-1-7B-Chat
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

ChatTime-1-7B-Chat - 昇腾 NPU 推理部署

1. 模型简介

模型名称: ChengsenWang/ChatTime-1-7B-Chat

模型链接: HuggingFace

模型描述: ChatTime 是一个多模态时间序列基础模型,将时间序列视为"外语",基于 LLaMA 架构进行序列到序列的预测。通过离散化(Discretizer)和序列化(Serializer)将连续数值转换为类语言 token,使 LLaMA 语言模型能够直接进行时间序列预测。

模型架构: LLaMA (LlamaForCausalLM) + 自定义时间序列Tokenizer

参数规模: 6.67B

输入规格:

  • 历史时间序列:1D numpy array, shape=(seq_len,),float32
  • 序列长度:通常 96~192 步

输出规格:

  • 预测序列:1D numpy array, shape=(pred_len,),float32
  • 预测步数:默认 16 步,支持任意长度

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch-npu>= 2.1.0昇腾 NPU 后端
transformers>= 4.36.0HuggingFace Transformers
scikit-learn>= 1.3.0MinMaxScaler 离散化
numpy>= 1.24.0数值计算
sentencepiece>= 0.1.99Tokenizer 依赖
protobuf>= 3.20.0模型序列化
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

pip install torch-npu transformers scikit-learn numpy sentencepiece protobuf

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 ChengsenWang/ChatTime-1-7B-Chat --local-dir ./weights

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

huggingface-cli download https://ai.gitcode.com/hf_mirrors/ChengsenWang/ChatTime-1-7B-Chat --local-dir ./weights

3.3 运行推理

# 单条推理(预测16步)
python3 inference.py --model-path ./weights --pred-len 16

# 自定义预测步数
python3 inference.py --model-path ./weights --pred-len 32 --num-samples 4

3.4 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--pred-lenint16预测步数
--num-samplesint8生成采样数(越多越稳定但越慢)
--devicestrnpu:0NPU 设备 ID

4. 推理成功日志

4.1 单条推理日志

[设备] NPU:0 Ascend910_9362 (count=2)
[数据] 历史序列长度: 192, 真实值长度: 16
[模型] 加载模型权重: ./weights
[模型] CPU加载完成: 0.6s, 移动到NPU...
[模型] NPU加载完成: 5.5s
[模型] 参数量: 6.82B
[模型] 分词器加载完成, vocab_size=32000
[耗时] 模型加载: 6.70s

[推理结果]
[耗时] 推理时间: 3.13s
[输入] 历史序列 (192步): [0.04967142 0.1072897 ...]
[输出] 预测序列 (16步): [-0.91228325 -0.8765457 ...]
[指标] MAE: 0.2893
[指标] MSE: 0.1544

[状态] SUCCESS
[基准测试] 8次推理统计:
  总耗时: 9.83s (加载6.70s + 推理3.13s)

5. 测试样例及输出结果

样例 1:正弦波预测(192步历史 → 16步预测)

运行命令:

python3 inference.py --model-path ./weights --pred-len 16

输出:

[输出] 预测序列 (16步): [-0.91228325 -0.8765457  -0.91063744 -0.90758094 -0.8765457  -0.84739139
 -0.85044789 -0.86220366 -0.85938228 -0.84880209 -0.85985251 -0.85726624
 -0.85491509 -0.84621582 -0.85985251 -0.87560524]
[对比] 真实序列 (16步): [-0.94739984 -1.11626458 -0.98265312 -0.95499709 -1.06084417 -0.9216977
 -0.88206435 -0.93992465 -0.71543531 -0.60966167 -0.46215917 -0.36140914
 -0.49400865 -0.33423153 -0.0696126   0.0513786 ]
[指标] MAE: 0.2893
[指标] MSE: 0.1544
[状态] SUCCESS

6. Agent适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

测试数据: 合成正弦波(sin(t) + 0.1*noise),192步历史 → 16步预测

评测指标:

指标结果说明
MAE0.2893平均绝对误差
MSE0.1544均方误差

评测命令:

python3 inference.py --model-path ./weights --pred-len 16 --num-samples 8

8. NPU 配置说明

  • NPU 型号: Ascend910_9362
  • NPU 数量: 2 卡
  • 单卡 HBM: 64GB
  • 总 HBM: 128GB
  • 数据类型: bfloat16
  • 模型占用: ~13GB(3个safetensors shards)
  • CANN 版本: 8.5.1
  • 推理耗时: 模型加载 6.7s,推理 3.13s(16步,8样本)

9. 已知问题

无