模型适配 · 自然语言处理(NLP)· 因果语言模型 · vLLM-Ascend 服务化推理 · 昇腾 NPU
Beta 版本头信息
{hardware NPU}/v1/completions)提供服务化推理,无需修改任何模型代码。{hardware NPU} Ascend 910B(torch_npu 2.9.0.post1,NPU 0)| 组件 | 版本 |
|---|---|
| python | 3.11.14 |
| torch | 2.9.0 |
| torch-npu | 2.9.0.post1 |
| vllm | 0.18.0 |
| vllm-ascend | 0.18.0 |
| transformers | 4.57.6 |
| CANN | 8.5.1 |
| NPU | Ascend 910B (Ascend910_9362) × 2(本次部署使用 NPU 0) |
| 权重 | hmellor/tiny-random-LlamaForCausalLM(model.safetensors bf16 → vLLM 按 float16 加载,2.1 MB) |
tiny-random-LlamaForCausalLM 是 LlamaForCausalLM 标准架构,vLLM 原生支持(llm_arch = LlamaForCausalLM),
vLLM-Ascend 0.18.0 通过 VLLM_TARGET_DEVICE=ascend 自动激活昇腾平台插件,在 NPU 上
加载权重并完成 KV-cache 分配与推理,代码零改动。
关键启动参数(见 inference.py):
| 参数 | 取值 | 说明 |
|---|---|---|
--model | 本地权重路径 / HF repo id | 指定模型 |
--dtype | float16 | 权重精度 |
--max-model-len | 128 | 最大上下文长度 |
--gpu-memory-utilization | 0.2 | 显存/内存占用比例 |
--device-ids | 0 | 使用的 NPU 设备号 |
--enforce-eager | — | 关闭 graph 编译,保证开箱即用 |
注:本环境因
--model位置参数不会覆盖 vLLM 内部默认模型(Qwen/Qwen3-0.6B), 脚本中必须显式传--model,否则会尝试回连 huggingface.co。
# 方式一:AtomGit 镜像(gitcode.com)
git clone https://gitcode.com/hf_mirrors/hmellor/tiny-random-LlamaForCausalLM.git
# 方式二:hf-mirror 镜像
HF_ENDPOINT=https://hf-mirror.com python -c "
from huggingface_hub import snapshot_download
snapshot_download('hmellor/tiny-random-LlamaForCausalLM', local_dir='./tiny-random-LlamaForCausalLM')
"pip install -r requirements.txt# 前台启动 OpenAI 兼容服务(默认端口 8000)
python inference.py --model /path/to/tiny-random-LlamaForCausalLM --port 8000 --device-ids 0服务启动后提供:
GET /v1/models 模型列表/健康检查POST /v1/completions 文本生成# 健康检查
python inference.py --health --port 8000
# 自检生成
python inference.py --test --port 8000
# 或直接用 curl
curl http://localhost:8000/v1/completions \
-H 'Content-Type: application/json' \
-d '{"model":"tiny-random-LlamaForCausalLM","prompt":"The capital of France is","max_tokens":16,"temperature":0}'python inference.py --offline --model /path/to/tiny-random-LlamaForCausalLMPROMPT : The capital of France is
OUTPUT : Var populated kilometerзда moins합 meer weitiginomer clészewломNonMessages polynomialsantsåстWORD Legнаügelized
PROMPT : Machine learning is
OUTPUT : sogonnes IN Fight explaografieoscidis Aer Р到 країelihoodчник Professional gru neighb\ Unit especie Stuart %cureno nuncaincludegraphics Sydneystabshow$). guessing注:此模型为随机初始化权重(非训练版),输出为随机 token,属于正常现象。
/v1/models:
{"object":"list","data":[{"id":"tiny-random-LlamaForCausalLM","object":"model",
"created":1787028478,"owned_by":"vllm",
"root":"/opt/atomgit/models/hmellor/tiny-random-LlamaForCausalLM","parent":null,
"max_model_len":128,"permission":[...]}]}/v1/completions:
PROMPT : The capital of France is
OUTPUT : Var populated kilometerзда moins합 meer weitiginomer clészewломNonMessages polynomialsantsåстWORD Legнаügelized广Whodisragment volte miniotti vulner
USAGE : prompt_tokens=6 completion_tokens=32INFO 08-21 07:24:53 [model_runner_v1.py:2565] Starting to load model /opt/atomgit/models/hmellor/tiny-random-LlamaForCausalLM...
INFO 08-21 07:24:53 [default_loader.py:384] Loading weights took 0.01 seconds
INFO 08-21 07:24:54 [model_runner_v1.py:2592] Loading model weights took 0.0049 GB
INFO 08-21 07:24:56 [worker.py:357] Available KV cache memory: 12.21 GiB
INFO: Application startup complete.截图素材待补充(
assets/目录):
| 截图 | 说明 |
|---|---|
assets/agent_workflow.png | 适配/部署流程图 |
assets/npu_device_call.png | NPU 设备调用截图(npu-smi info / 日志中的 NPU 状态) |
assets/model_result.png | 模型推理结果截图(completions 返回) |