HaS-820m 是一个基于 BLOOM 架构的因果语言模型,参数量为 750M,采用 24 层 Transformer 解码器结构,隐藏层维度 1536,支持 16 头注意力计算。该模型在华为昇腾 Ascend910 NPU 上完成了完整的适配验证,实测可通过 vLLM-Ascend 框架进行服务化推理部署,亦支持使用原生 transformers 库直接加载推理。
| 组件 | 版本/规格 |
|---|---|
| 操作系统 | Linux (aarch64) |
| NPU 硬件 | Ascend910 (64GB HBM) |
| CANN 版本 | 8.5.1 |
| Python | 3.11.14 |
| PyTorch | 2.9.0 |
| torch_npu | 2.9.0.post1 |
| vLLM | 0.18.0 |
| vLLM-Ascend | 0.18.0 |
| transformers | 4.27.0+ |
python3 -m vllm.entrypoints.openai.api_server \
--model /path/to/HaS-820m \
--trust-remote-code \
--dtype float16 \
--max-model-len 2048 \
--gpu-memory-utilization 0.9 \
--port 8001 \
--host 0.0.0.0 \
--enforce-eager注意:该模型 head_dim=96,需添加
--enforce-eager参数以绕过 NPU 融合算子的 head_dim 限制。同时需设置VLLM_WORKER_MULTIPROC_METHOD=fork环境变量以确保 monkey-patch 正确传播。
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained(
"/path/to/HaS-820m",
trust_remote_code=True,
torch_dtype=torch.float16
).to("npu:0")
tokenizer = AutoTokenizer.from_pretrained("/path/to/HaS-820m", trust_remote_code=True)服务启动后,通过 curl 发送推理请求:
curl http://localhost:8001/v1/completions \
-H "Content-Type: application/json" \
-d '{
"model": "/path/to/HaS-820m",
"prompt": "The meaning of life is",
"max_tokens": 100,
"temperature": 0.7
}'预期返回包含模型生成的续写文本,响应状态码为 200。
在 Ascend910 NPU 上,使用 transformers 原生推理(batch_size=1)的实测表现:
| 指标 | 数值 |
|---|---|
| 模型参数量 | 750.8M |
| 权重格式 | float16 |
| 权重存储 | 1.4 GB |
| 推理设备 | NPU:0 |
| 单次推理显存 | ~1.5 GB |
模型在任意文本生成任务上可正常产出语义连贯的续写内容。以下为实测输出示例:
输入:"Once upon a time, in a land far, far away," 输出为一段完整的英文叙事文本,具备合理的语法结构和词汇多样性。
输入:"The meaning of life is" 输出围绕生命意义展开论述,句子结构完整,逻辑通顺。
--enforce-eager 开启 eager 模式