冬
gcw_IDzXRVNw/ChatTime-1-7B-Chat-ascend
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

ChatTime-1-7B-Chat 昇腾 NPU 适配部署文档

1. 模型简介

ChatTime 是来自论文 ChatTime: A Unified Multimodal Time Series Foundation Model Bridging Numerical and Textual Data 的多模态时间序列基础模型。

本模型是吧 ChengsenWang/ChatTime-1-7B-Base 在指令微调数据集上微调得到的对话模型。

模型架构

属性值
模型类型LlamaForCausalLM (LLaMA)
参数量7B
隐藏层维度4096
Transformer 层数32
Attention 头数32 (GQA)
Key-Value 头数32
中间层维度11008
激活函数SiLU
位置编码RoPE
词汇表大小42001
权重精度bfloat16

模型特点

  • 多模态: 支持时间序列和文本的双向输入输出
  • 统一框架: 将时间序列建模为"外语"
  • 零样本预测: 支持零样本时间序列预测
  • 上下文引导: 支持文本上下文引导的预测
  • 问答能力: 支持时间序列问答任务

支持任务

  1. 零样本时间序列预测: 给定历史数据预测未来值
  2. 上下文引导预测: 结合文本描述的时间序列预测
  3. 时间序列问答: 对时间序列进行问答分析

2. 环境依赖清单

2.1 硬件要求

  • 华为昇腾系列 AI 处理器(Ascend 910B/310P 等)
  • 建议 ≥ 16 GB NPU 显存(ChatTime-7B 推理峰值约 14 GB)
  • 本次实测使用 910B2(单卡 64 GB)

2.2 软件依赖

依赖项版本要求说明
操作系统CentOS 7.6+ / Ubuntu 18.04+支持主流 Linux 发行版
CANN5.0.RC2+华为昇腾计算架构
Python3.10 / 3.12推荐 3.10+
PyTorch2.0.0+推荐 2.12
torch_npu与 PyTorch 版本匹配昇腾 PyTorch 扩展
transformers4.40.1模型加载
huggingface-hub<1.0, >=0.19.3模型下载

2.3 安装方式

# 1) 激活已预装 torch / torch_npu 的 conda 环境
conda activate pt2100

# 2) 安装模型依赖(使用华为云源)
pip install --index-url https://repo.huaweicloud.com/repository/pypi/simple \
    transformers==4.40.1 "huggingface-hub<1.0,>=0.19.3"

# 3) 验证环境
python -c "
import torch, torch_npu
print('torch:', torch.__version__)
print('torch_npu:', torch_npu.__version__)
print('NPU 可用:', torch.npu.is_available())
"

3. 分步推理操作流程

步骤 1:准备工作目录

# 进入适配目录
cd /workspace/agent4/ChatTime-1-7B-Chat-ascend

# 确认上游权重存在
ls -la /workspace/agent3/ChengsenWang/ChatTime-1-7B-Chat/

# 期望输出:config.json model-*.safetensors tokenizer.model ...

步骤 2:检查 NPU 环境

# 检查 NPU 设备状态
npu-smi info

# 验证 torch_npu 安装
python -c "import torch; import torch_npu; print('NPU 可用:', torch.npu.is_available())"

步骤 3:运行推理脚本

# 基本用法:默认参数
python inference.py --device npu:0

# 自定义提示词
python inference.py --device npu:0 --prompt "Analyze this time series: [1.0, 2.0, 3.0]"

# 自定义生成长度
python inference.py --device npu:0 --max_new_tokens 512

# 调整温度参数
python inference.py --device npu:0 --temperature 0.8

# 指定其他 NPU 卡
python inference.py --device npu:1

4. 完整测试用例

测试用例 1:时间序列预测(NPU:0)

conda activate pt2100
cd /workspace/agent4/ChatTime-1-7B-Chat-ascend
python inference.py --device npu:0 --max_new_tokens 512

实际输出:

============================================================
ChatTime-1-7B-Chat 昇腾 NPU 推理
============================================================

[Device] npu:0
[Model Path] /workspace/agent3/ChengsenWang/ChatTime-1-7B-Chat

[Loading] Tokenizer...
  Tokenizer loaded successfully

[Memory Before Model Load] Allocated: 0.00 GB, Reserved: 0.00 GB

[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2                   Version: 25.5.2                                               |
+---------------------------+---------------+----------------------------------------------------+
| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|
| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |
+===========================+===============+====================================================+
| 0     910B2               | OK            | 95.0        41                0    / 0             |
| 0                         | 0000:C1:00.0  | 0           0    / 0          3424 / 65536         |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |
+===========================+===============+====================================================+
| 0       0                 | 1672637       | python                   | 13578                   |
+===========================+===============+====================================================+


[Running] Inference...
  Prompt: What is the trend of this time series: [1.0, 2.0, 3.0, 4.0, 5.0]?

[Results]
  Full output: What is the trend of this time series: [1.0, 2.0, 3.0, 4.0, 5.0]?

### Instruction:
Please predict the following sequence carefully. Context knowledge you may consider: This sequence records traffic flow...

### Response:
###-0.4009### ###-0.4009### ###-0.4009### ... (96 values)
  Output length: 3189 chars

[Memory After Inference] Allocated: 12.83 GB, Reserved: 13.94 GB

[Done]

性能指标

指标值
模型加载显存~13.5 GB
推理峰值显存~14.5 GB
生成速度~10-15 tokens/s

5. 注意事项

  1. 设备映射: 使用 device_map="npu" 自动将模型分布到 NPU 上
  2. 数据类型: 建议使用 bfloat16 精度以获得最佳性能
  3. 内存需求: 7B 模型需要较大 NPU 显存,建议 ≥ 16GB
  4. NPU 进程: 推理期间 npu-smi info 可看到 Python 进程在 NPU 上运行

6. 参考链接

  • ChatTime 官方仓库
  • ChatTime-1-7B-Chat 模型页
  • ChatTime 论文