基于 vLLM-Ascend 的 tara-1b 大语言模型部署、验证与交付指南。 适用硬件:华为昇腾 Atlas 800 A2 / A3 系列(Ascend910B)。
| 项目 | 最低配置 | 推荐配置 |
|---|---|---|
| NPU | Ascend910B4 x1 | Ascend910B4 x1 |
| CPU | ARM 64核 | ARM 64核 |
| 内存 | 256 GB | 512 GB |
| 存储 | 100 GB SSD | 200 GB NVMe SSD |
| 网络 | 10 Gbps | 25 Gbps |
| 组件 | 版本要求 | 安装命令/说明 |
|---|---|---|
| OS | EulerOS 2.10 / CentOS 7.6 / Ubuntu 22.04 | - |
| CANN Toolkit | >= 8.0.RC2 | 昇腾官网下载 |
| Python | 3.9 / 3.10 / 3.11 | conda create -n tara python=3.11 |
| PyTorch | >= 2.1.0 | pip install torch |
| torch_npu | 与 CANN 匹配版本 | pip install torch_npu |
| vLLM | >= 0.17.0rc1 | pip install vllm |
| vLLM-Ascend | 与 vLLM 匹配 | pip install vllm-ascend |
# 1. 加载 CANN 环境
source /usr/local/Ascend/ascend-toolkit/set_env.sh
# 2. 创建并激活 Python 虚拟环境
conda create -n tara python=3.11 -y
conda activate tara
# 3. 安装核心依赖
pip install torch==2.1.0
pip install torch_npu==2.1.0 # 请根据 CANN 版本选择对应 torch_npu
pip install vllm==0.17.0rc1
pip install vllm-ascend
# 4. 安装评测依赖(可选)
pip install openai requests datasets
# 5. 验证安装
python -c "import torch; import torch_npu; import vllm; print('All imports OK')"
npu-smi info在启动服务前,确保以下环境变量已设置:
export VLLM_USE_MODELSCOPE=true
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
export HCCL_BUFFSIZE=512
export OMP_PROC_BIND=false
export OMP_NUM_THREADS=1
export TASK_QUEUE_ENABLE=1
export VLLM_WORKER_MULTIPROC_METHOD=spawn提示:可将上述变量写入
~/.bashrc或项目根目录的.env文件。
将 tara-1b 模型权重下载或挂载到服务器指定目录:
# 示例路径
MODEL_PATH=/data/models/tara-1b
# 确认目录结构
ls -la $MODEL_PATH
# 预期输出:config.json, tokenizer.json, model.safetensors / pytorch_model.bin, 等/data/models/tara-1b/
├── config.json
├── tokenizer.json
├── tokenizer_config.json
├── generation_config.json
├── model.safetensors.index.json
├── model-00001-of-00002.safetensors
├── model-00002-of-00002.safetensors
└── special_tokens_map.jsoncd tara-1b-deliverable
bash scripts/start_server.sh /data/models/tara-1b 8000脚本将自动:
# 设置环境变量
source scripts/set_env.sh # 或手动 export
# 启动 vLLM 服务
vllm serve /data/models/tara-1b \
--host 0.0.0.0 \
--port 8000 \
--served-model-name tara-1b \
--tensor-parallel-size 1 \
--data-parallel-size 1 \
--max-model-len 32768 \
--max-num-seqs 64 \
--max-num-batched-tokens 4096 \
--gpu-memory-utilization 0.85 \
--trust-remote-code \
--dtype auto \
--device npu \
--seed 1024 \
--compilation-config '{"cudagraph_mode":"FULL_DECODE_ONLY"}' \
--async-scheduling| 参数 | 值 | 说明 |
|---|---|---|
--tensor-parallel-size | 1 | Tensor 并行大小,1B 模型单卡即可 |
--data-parallel-size | 1 | Data 并行大小 |
--max-model-len | 32768 | 最大上下文长度 32K |
--max-num-seqs | 64 | 每 DP 组最大并发请求数 |
--max-num-batched-tokens | 4096 | 单步最大处理 tokens |
--gpu-memory-utilization | 0.85 | HBM 利用率上限 |
--compilation-config | FULL_DECODE_ONLY | 图编译模式,优化 decode 阶段 |
--async-scheduling | - | 异步调度,提升吞吐 |
服务启动后,执行健康检查:
# 健康检查
curl -s http://localhost:8000/health
# 预期返回:{"status":"ok"}
# 查看模型列表
curl -s http://localhost:8000/v1/models | python -m json.tool
# 预期返回:包含 "tara-1b"curl http://localhost:8000/v1/completions \
-H "Content-Type: application/json" \
-d '{
"model": "tara-1b",
"prompt": "The future of artificial intelligence is",
"max_tokens": 100,
"temperature": 0.7,
"top_p": 0.9,
"stop": ["\n\n"]
}'预期响应:
{
"id": "cmpl-xxx",
"object": "text_completion",
"created": 1715420000,
"model": "tara-1b",
"choices": [
{
"text": " incredibly promising, with advances in...",
"index": 0,
"logprobs": null,
"finish_reason": "length"
}
],
"usage": {
"prompt_tokens": 8,
"completion_tokens": 100,
"total_tokens": 108
}
}curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "tara-1b",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "请用一句话解释什么是人工智能。"}
],
"max_tokens": 128,
"temperature": 0.7
}'预期响应:
{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"model": "tara-1b",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "人工智能是计算机科学的一个分支,旨在创建能够执行通常需要人类智能的任务的系统。"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 32,
"total_tokens": 57
}
}from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8000/v1",
api_key="not-needed",
)
# Completions
response = client.completions.create(
model="tara-1b",
prompt="The future of AI is",
max_tokens=100,
temperature=0.7,
)
print(response.choices[0].text)
# Chat
response = client.chat.completions.create(
model="tara-1b",
messages=[
{"role": "user", "content": "Hello!"}
],
max_tokens=50,
)
print(response.choices[0].message.content)# 单条推理
python scripts/inference.py \
--model-path /data/models/tara-1b \
--prompt "1+1等于几?" \
--max-tokens 50
# 批量推理
python scripts/inference.py \
--model-path /data/models/tara-1b \
--batch-file prompts.txt \
--output results.json
# 快速基准测试
python scripts/inference.py \
--model-path /data/models/tara-1b \
--benchmark \
--num-prompts 100 \
--input-len 128 \
--output-len 128确保 vLLM 服务已在 http://localhost:8000 运行。
# GSM8K 数学推理评测
python eval/accuracy_run.py \
--server-url http://localhost:8000 \
--dataset gsm8k \
--num-samples 100
# HumanEval 代码生成评测
python eval/accuracy_run.py \
--server-url http://localhost:8000 \
--dataset humaneval \
--num-samples 164结果将保存至 ./accuracy_results/ 目录:
accuracy_results/
├── tara-1b_gsm8k_result.json # 结构化结果
├── tara-1b_gsm8k_report.md # Markdown 报告
└── tara-1b_humaneval_result.json| 数据集 | 指标 | 参考值 | 说明 |
|---|---|---|---|
| GSM8K | accuracy | 待实测 | 数学推理能力 |
| HumanEval | pass@1 | 待实测 | 代码生成能力 |
| C-Eval | accuracy | 待实测 | 中文综合评测 |
注:具体参考值需根据模型官方发布数据或客户要求确定。
# 全部模式测试(API 模式)
python eval/performance_run.py \
--server-url http://localhost:8000 \
--mode all \
--input-len 200 \
--output-len 200 \
--num-prompts 200
# 单独测试 Serve 吞吐
python eval/performance_run.py \
--server-url http://localhost:8000 \
--mode serve \
--input-len 200 \
--output-len 200 \
--num-prompts 200 \
--concurrency 10
# 单独测试延迟
python eval/performance_run.py \
--server-url http://localhost:8000 \
--mode latency \
--input-len 512 \
--output-len 256 \
--num-iterations 10| 测试模式 | 关键指标 | 1B 模型参考范围 |
|---|---|---|
| Serve | QPS | 20 - 80 req/s |
| Serve | TTFT | 50 - 200 ms |
| Serve | TPOT | 20 - 80 ms |
| Latency | P50 | 80 - 300 ms |
| Latency | P99 | 200 - 800 ms |
| Throughput | tokens/sec | 500 - 2000 tok/s |
注:实际数值取决于硬件配置、输入输出长度和并发度。
perf_results/
├── tara-1b_perf_report_20240101_120000.json
└── tara-1b_perf_summary.md# 收集所有信息并生成完整报告
python eval/log_generator.py --collect-all --output-dir ./logs
# 仅收集环境信息
python eval/log_generator.py --collect-env --output-dir ./logslogs/
├── tara-1b_deployment_report.json # 结构化 JSON 报告
├── tara-1b_deployment_report.md # Markdown 汇总
├── npu_smi.txt # NPU 状态
├── npu_smi_version.txt # 驱动版本
├── pip_list.txt # Python 包列表
└── ascend_env.txt # 环境变量| JSON 字段 | 说明 |
|---|---|
success | 验证流程整体是否通过 |
summary | 人类可读的结果摘要 |
environment.npu | NPU 硬件与驱动信息 |
environment.python | Python 环境与关键包版本 |
server | vLLM 服务健康状态 |
accuracy | 精度评测汇总 |
performance | 性能评测汇总 |
model_info | 模型文件信息 |
No NPU detected排查步骤:
npu-smi info 确认驱动是否正常echo $ASCEND_HOME_PATHls -la /dev/davinci*解决方案:
--gpu-memory-utilization(如 0.75)--max-model-len(如 16384)--max-num-seqs(如 32)优化建议:
--compilation-config 已设置npu-smi info -t power--max-num-batched-tokens排查步骤:
--max-model-len 以支持更长输入max_tokens 不超过模型限制)排查步骤:
temperature=0 进行评测| 序号 | 文件/目录 | 说明 | 路径 |
|---|---|---|---|
| 1 | readme.md | 部署文档(本文档) | ./readme.md |
| 2 | scripts/inference.py | 推理脚本 | ./scripts/inference.py |
| 3 | scripts/start_server.sh | 服务启动脚本 | ./scripts/start_server.sh |
| 4 | eval/accuracy_run.py | 精度评测源码 | ./eval/accuracy_run.py |
| 5 | eval/performance_run.py | 性能评测源码 | ./eval/performance_run.py |
| 6 | eval/screenshot_guide.md | 自验证截图指南 | ./eval/screenshot_guide.md |
| 7 | eval/log_generator.py | 日志与报告生成 | ./eval/log_generator.py |
| 8 | accuracy_results/ | 精度评测结果(运行后生成) | ./accuracy_results/ |
| 9 | perf_results/ | 性能评测结果(运行后生成) | ./perf_results/ |
| 10 | logs/ | 验证报告与日志(运行后生成) | ./logs/ |
# 1. 启动服务
bash scripts/start_server.sh /data/models/tara-1b 8000
# 2. 验证服务
curl http://localhost:8000/v1/completions \
-H "Content-Type: application/json" \
-d '{"model":"tara-1b","prompt":"Hello","max_tokens":50}'
# 3. 精度评测
python eval/accuracy_run.py --dataset gsm8k
# 4. 性能评测
python eval/performance_run.py --mode all
# 5. 生成报告
python eval/log_generator.py --collect-all文档版本: v1.0
生成日期: 2026-05-10
适用模型: tara-1b
适用平台: 华为昇腾 Atlas 800 A2/A3 (Ascend910B)