ggg_0963/SmolLM2-1.7B
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

SmolLM2-1.7B on vLLM-Ascend 0.18.0rc1 #+NPU

1. 简介

本文档记录 HuggingFaceTB/SmolLM2-1.7B(预训练基础版,1.7B 参数)在 vLLM-Ascend 0.18.0rc1 环境的快速部署与验证结果。

SmolLM2-1.7B 是 HuggingFace 发布的轻量级语言模型,使用 Llama 架构,24 层 Transformer,2048 隐藏维度,49152 词表大小,BF16 精度。模型在昇腾 NPU 上通过 vLLM-Ascend 原生推理,架构 LlamaForCausalLM 已被 vLLM-Ascend 完整支持,无需额外适配即可运行。

相关获取地址:

  • 权重下载地址(ModelScope):https://modelscope.cn/models/HuggingFaceTB/SmolLM2-1.7B
  • Docker Image(vLLM-Ascend 0.18.0rc1):quay.io/ascend/vllm-ascend:v0.18.0rc1

参考文档:

  • https://docs.vllm.ai/projects/ascend/zh-cn/v0.18.0/tutorials/models/Qwen3.5-27B.html

2. 验证环境

组件版本
vllm-ascend0.18.0rc1
vllm0.18.0+empty
transformers4.57.6
torch-npu2.9.0.post1+gitee7ba04
CANN8.5.1
SOCascend910_9391
  • NPU:1 逻辑卡(Ascend910,64GB HBM)
  • 模型路径:/opt/atomgit/SmolLM2-1.7B
  • 服务端口:8000

3. 模型配置

{
  "architectures": ["LlamaForCausalLM"],
  "hidden_size": 2048,
  "intermediate_size": 8192,
  "num_attention_heads": 32,
  "num_hidden_layers": 24,
  "num_key_value_heads": 32,
  "max_position_embeddings": 8192,
  "rope_theta": 130000,
  "vocab_size": 49152,
  "torch_dtype": "bfloat16",
  "tie_word_embeddings": true
}

4. 服务启动

启动前可先检查端口:

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/SmolLM2-1.7B \
  --host 0.0.0.0 \
  --port 8000 \
  --tensor-parallel-size 1 \
  --seed 1024 \
  --served-model-name smollm2-1.7b \
  --max-model-len 4096 \
  --max-num-seqs 16 \
  --gpu-memory-utilization 0.90 \
  --trust-remote-code \
  --dtype bfloat16

说明:

  • 1.7B 模型单卡(TP=1)即可运行,约占用 4GB HBM
  • ASCEND_VISIBLE_DEVICES 需设置为逻辑设备编号(从 0 开始),而非物理芯片 ID

5. Smoke 验证

基础检查:

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": "smollm2-1.7b",
    "prompt": "The capital of France is",
    "max_tokens": 32,
    "temperature": 0
  }'

验证结果:

  • /v1/models 返回 200,模型 smollm2-1.7b 已加载
  • /v1/completions 返回 200,输出 Paris. The capital of the United States is Washington, D.C...

6. 精度评测

使用 GSM8K 5-shot 对模型进行精度评测,对比 CPU 基准。

评测命令

python scripts/eval_gsm8k.py --api http://127.0.0.1:8000 --model_name smollm2-1.7b --baseline 31.0 --output scripts/gsm8k_results.json

评测配置

参数值
数据集GSM8K
评测方式5-shot
样本总数1,319
Max tokens256
Temperature0
Stop sequences["\nQuestion:", "\n\n"]

评测结果

指标NPU 结果CPU 基准差异
Accuracy25.02%26%-0.98%

结论:NPU 上 GSM8K 5-shot 准确率为 25.02%,与 CPU 基准 26% 差异 -0.98%,在合理范围内,验证通过。

7. 性能参考

测试条件:128 input / 128 output / concurrency=4,20 requests。

指标数值
duration16.93 s
request_throughput1.181 req/s
output_throughput151.22 tok/s
total_token_throughput245.73 tok/s
mean_latency_ms3383.22 ms
median_latency_ms3393.48 ms
p99_latency_ms3412.59 ms
mean_tpot_ms26.43 ms/token

8. 注意事项

  1. 设备编号:ASCEND_VISIBLE_DEVICES 需使用从 0 开始的逻辑设备编号。如系统显示物理 Chip ID 为 4/5,实际需设置为 0,1。使用错误的设备编号会导致 aclInit 错误(error code 107001)。

  2. 模型架构兼容:LlamaForCausalLM 已被 vLLM-Ascend 0.18.0 原生支持,无需额外适配代码或算子替换。

  3. 显存占用:1.7B BF16 模型约占用 4GB HBM,Ascend910 单卡(64GB)有充足余量。

  4. 此为基础版模型:本验证使用的是预训练基础版(非 Instruct 版),输出为续写模式。如需对话场景,建议使用 HuggingFaceTB/SmolLM2-1.7B-Instruct。