ohhoohho/HaS-820m
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

HaS-820m 昇腾 NPU 适配

在华为昇腾 NPU(Ascend 910B)上实现 SecurityXuanwuLab/HaS-820m 的服务化推理。

1. 模型简介

项值
模型名称SecurityXuanwuLab/HaS-820m
来源腾讯安全玄武实验室 Hide-and-Seek 隐私保护模型
架构BloomForCausalLM(BLOOM)
参数量~750.8M
结构24 层 decoder,hidden_size 1536,16 head,vocab 46145
权重格式pytorch_model.bin(FP16,~1.5 GB)
任务类型text-generation(hide 隐私匿名化 / seek 信息还原)

2. 适配状态

项值
适配状态成功
推理框架transformers + torch_npu(服务化推理)
硬件Ascend 910B(2 逻辑卡)
服务化推理✅ 支持(OpenAI 兼容 HTTP 服务)
vLLM-Ascend❌ 不支持(BLOOM head_dim=96 不在 Ascend 融合注意力支持范围[64/128/192]内)

说明:HaS-820m 基于 BLOOM 架构,使用 ALiBi 位置编码,其 head_dim=96(hidden_size 1536 / 16 heads)。 华为昇腾 NPU 的 FusedInferAttentionScore 算子仅支持 head_dim ∈ {64, 128, 192},因此 vLLM-Ascend 无法直接支持 BLOOM 模型。本适配采用 transformers + torch_npu 方式,搭配 FastAPI 提供 OpenAI 兼容服务。

3. 验证环境

组件版本
Python3.11.14
torch2.9.0
torch-npu2.9.0.post1
transformers4.57.6
CANN8.5.1
NPUAscend 910B

4. 复现步骤

4.1 拉取权重

# 方式一:HuggingFace 镜像(推荐)
huggingface-cli download SecurityXuanwuLab/HaS-820m --local-dir ./HaS-820m

# 方式二:hf-mirror
pip install huggingface-hub
HF_ENDPOINT=https://hf-mirror.com huggingface-cli download SecurityXuanwuLab/HaS-820m --local-dir ./HaS-820m

# 方式三:ModelScope
pip install modelscope
python3 -m modelscope download --model SecurityXuanwuLab/HaS-820m --local_dir ./HaS-820m

4.2 安装依赖

pip install -r requirements.txt

4.3 服务化推理

# 指定本机权重目录(可选)
export MODEL_DIR=/path/to/HaS-820m

# 启动 OpenAI 兼容 HTTP 服务,端口 8000
python3 inference.py serve

4.4 验证生成

# 前台单次生成(本地自检)
python3 inference.py cli --prompts "介绍一下华为昇腾 AI 处理器。"

# 向已启动的服务发送请求
python3 inference.py client --prompt "Paraphrase the text:张三在北京的字节跳动研发部工作。"

4.5 验证结果示例

prompt: 介绍一下华为昇腾AI处理器。
completion: 它的核心思想是利用云计算和大数据分析技术,实现对产品质量、服务提供商及客户端的完美结合。

5. 目录结构

HaS-820m/
├── inference.py        # 推理脚本(服务化/前台生成/客户端)
├── README.md           # 本说明文档
├── requirements.txt    # 环境依赖清单
└── assets/             # 截图素材(用户自行添加)

6. 参考

  • 模型主页:https://huggingface.co/SecurityXuanwuLab/HaS-820m
  • 原始仓库:https://gitcode.com/ohhoohho/HaS-820m