本文档记录 LLM-Research/Meta-Llama-3.1-8B(预训练基础版,8B 参数)在 vLLM-Ascend 0.18.0rc1 环境下的快速部署与验证结果。
Meta Llama 3.1 8B 是 Meta 发布的多语言大语言模型,采用优化的 Transformer 架构,支持 GQA(分组查询注意力机制),上下文长度达 128K,词汇量为 128K,精度为 BF16。该模型在昇腾 NPU 上可通过 vLLM-Ascend 进行原生推理,其架构 LlamaForCausalLM 已得到 vLLM-Ascend 的完整支持,无需额外适配即可运行。
相关获取地址:
quay.io/ascend/vllm-ascend:v0.18.0rc1参考文档:
| 组件 | 版本 |
|---|---|
vllm-ascend | 0.18.0rc1 |
vllm | 0.18.0+empty |
transformers | 4.57.6 |
torch-npu | 2.9.0.post1+gitee7ba04 |
CANN | 8.5.1 |
SOC | ascend910_9391 |
1 逻辑卡(Ascend910,64GB HBM)/opt/atomgit/Meta-Llama-3.1-8B8000{
"architectures": ["LlamaForCausalLM"],
"hidden_size": 4096,
"intermediate_size": 14336,
"num_attention_heads": 32,
"num_hidden_layers": 32,
"num_key_value_heads": 8,
"head_dim": 128,
"max_position_embeddings": 131072,
"rope_theta": 500000.0,
"vocab_size": 128256,
"torch_dtype": "bfloat16",
"tie_word_embeddings": false
}启动前可先检查端口:
ss -lntp | grep ':8000 ' || true已验证通过的启动命令:
export ASCEND_VISIBLE_DEVICES=0,1
export ASCEND_RT_VISIBLE_DEVICES=0,1
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
export TASK_QUEUE_ENABLE=1
export OMP_PROC_BIND=false
export OMP_NUM_THREADS=1
vllm serve /opt/atomgit/Meta-Llama-3.1-8B \
--host 0.0.0.0 \
--port 8000 \
--tensor-parallel-size 1 \
--seed 1024 \
--served-model-name meta-llama-3.1-8b \
--max-model-len 4096 \
--max-num-seqs 16 \
--gpu-memory-utilization 0.90 \
--trust-remote-code \
--dtype bfloat16说明:
max-model-len 可根据需要调整,模型支持最大 128K 上下文ASCEND_VISIBLE_DEVICES 需设置为逻辑设备编号(从 0 开始),而非物理芯片 ID基础检查:
curl -sf http://127.0.0.1:8000/v1/models推理测试:
curl -sf http://127.0.0.1:8000/v1/completions \
-H "Content-Type: application/json" \
-d '{
"model": "meta-llama-3.1-8b",
"prompt": "The capital of France is",
"max_tokens": 32,
"temperature": 0
}'验证结果:
/v1/models 返回 200,模型 meta-llama-3.1-8b 已加载/v1/completions 返回 200,输出 a city of many faces. It is a city of history, a city of culture, a city of art, a city of fashion, a city of food使用 MMLU 5-shot 对模型进行精度评测,对比官方基准。
python scripts/eval_accuracy.py --api http://127.0.0.1:8000 --model_name meta-llama-3.1-8b --baseline 66.7 --output scripts/accuracy_results.json| 参数 | 值 |
|---|---|
| 数据集 | MMLU |
| 评测方式 | 5-shot |
| 样本总数 | 14,042 |
| 科目数 | 57 |
| Temperature | 0 |
| 指标 | NPU 结果 | 官方基准(GPU) | 差异 |
|---|---|---|---|
| Macro Avg Accuracy | 66.30% | 66.7% | -0.40% |
| Micro Avg Accuracy | 65.40% | - | - |
| 科目 | 正确/总数 | 准确率 |
|---|---|---|
| abstract_algebra | 30/100 | 30.0% |
| anatomy | 85/135 | 63.0% |
| astronomy | 109/152 | 71.7% |
| business_ethics | 67/100 | 67.0% |
| computer_security | 82/100 | 82.0% |
| high_school_geography | 165/198 | 83.3% |
| high_school_government_and_politics | 173/193 | 89.6% |
| high_school_psychology | 465/545 | 85.3% |
| high_school_us_history | 170/204 | 83.3% |
| international_law | 102/121 | 84.3% |
| management | 85/103 | 82.5% |
| marketing | 189/234 | 80.8% |
| miscellaneous | 621/783 | 79.3% |
| professional_medicine | 246/272 | 90.4% |
| sociology | 178/201 | 88.6% |
| us_foreign_policy | 90/100 | 90.0% |
| world_religions | 144/171 | 84.2% |
结论:NPU 上 MMLU 5-shot Macro Avg 为 66.30%,与官方 GPU 基准 66.7% 差异 -0.40%,小于 1% 精度要求阈值,验证通过。
测试条件:128 input / 128 output / concurrency=4,20 requests。
| 指标 | 数值 |
|---|---|
duration | 14.40 s |
request_throughput | 1.389 req/s |
output_throughput | 177.75 tok/s |
total_token_throughput | 295.79 tok/s |
mean_latency_ms | 2879.12 ms |
median_latency_ms | 2878.85 ms |
p99_latency_ms | 2909.23 ms |
mean_tpot_ms | 22.49 ms/token |
设备编号:ASCEND_VISIBLE_DEVICES 需使用从 0 开始的逻辑设备编号。如系统显示物理 Chip ID 为 4/5,实际需设置为 0,1。使用错误的设备编号会导致 aclInit 错误(error code 107001)。
模型架构兼容:LlamaForCausalLM 已被 vLLM-Ascend 0.18.0 原生支持,无需额外适配代码或算子替换。
显存占用:8B BF16 模型约占用 16GB HBM,Ascend910 单卡(64GB)有充足余量。可通过 --gpu-memory-utilization 控制预分配比例。
此为基础版模型:本验证使用的是预训练基础版(非 Instruct 版),输出为续写模式。如需对话场景,建议使用 meta-llama/Llama-3.1-8B-Instruct。