weixin_72661020/nlp_ecomgpt_multilingual-7B-ecom
模型介绍文件和版本Pull Requests讨论分析

nlp_ecomgpt_multilingual-7B-ecom on Ascend NPU

1. 简介

本文档记录 iic/nlp_ecomgpt_multilingual-7B-ecom(BloomForCausalLM, 7B)在昇腾 Ascend910 NPU 环境的适配与验证结果。

nlp_ecomgpt_multilingual-7B-ecom 是一个多语言电商领域的大语言模型,基于 Bloom-7B 架构,支持多种电商场景的自然语言理解和生成任务。

相关获取地址:

  • 权重下载地址(ModelScope):https://modelscope.cn/models/iic/nlp_ecomgpt_multilingual-7B-ecom
  • 模型架构:BloomForCausalLM(7B 参数)
  • 支持语言:多语言(中文、英文等)

2. 适配环境

组件版本
Ascend NPUAscend910
CANN25.5.2
PyTorch2.9.0+cpu
torch_npu2.9.0.post1+gitee7ba04
transformers4.57.6
vLLM0.18.0+empty
vLLM-Ascend0.18.0
  • NPU:2 逻辑卡
  • 模型路径:/opt/atomgit/nlp_ecomgpt_multilingual-7B-ecom/model/iic/nlp_ecomgpt_multilingual-7B-ecom
  • 推理框架:transformers + torch_npu

3. 模型加载与推理

import torch
import torch_npu
from transformers import AutoModelForCausalLM, AutoTokenizer

model_path = "/path/to/nlp_ecomgpt_multilingual-7B-ecom"
device = "npu:0"

tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(
    model_path,
    torch_dtype=torch.bfloat16,
    low_cpu_mem_usage=True,
    use_cache=True
)
model = model.to(device)
model.eval()

prompt = "What is the best laptop for programming?"
inputs = tokenizer(prompt, return_tensors="pt")
inputs = {k: v.to(device) for k, v in inputs.items()}

with torch.no_grad():
    outputs = model.generate(
        **inputs,
        max_new_tokens=50,
        do_sample=True,
        temperature=0.7,
        pad_token_id=tokenizer.pad_token_id or tokenizer.eos_token_id
    )

result = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(result)

4. Smoke 验证

模型加载

  • 加载时间:96.9 秒
  • 参数量:7,069,016,064(~7B)
  • 推理精度:bfloat16
  • HBM 占用:约 14GB

推理测试

使用 5 个电商领域测试 prompt 进行验证:

输入输出
What is the best laptop for programming?正常生成推荐内容
I want to buy a smartphone, can you recommend one?正常生成推荐内容
The shipping was very fast and the product quality is excellent!正常生成评论相关内容
Compare iPhone and Android phones正常生成对比内容
How to choose a good pair of headphones?正常生成选购建议

所有测试用例均正常返回结果,模型适配成功。

5. 性能参考

测试条件:单卡 Ascend910,bfloat16 精度,单轮推理。

输出长度平均延迟吞吐量
10 tokens0.157 s63.56 tok/s
20 tokens0.266 s75.07 tok/s
50 tokens0.131 s382.12 tok/s

7. 注意事项

  • 模型使用 BF16 精度推理,建议在 Ascend910 上使用
  • 模型分 4 个 shard 保存,首次加载约需 90-100 秒
  • lm_head.weight 与 transformer.word_embeddings.weight 权值绑定,vLLM 加载时需特殊处理
  • 如果使用 vLLM serve 加载失败,可使用 transformers 直接推理
  • 当前 transformers 版本(4.57.6)已完全兼容此模型架构

Ascend NPU 精度评测

NPU 推理验证:

指标数值
测试用例数5
精度结论---

精度评测源代码和日志详见 eval/ 目录。

推理输出示例

#输入NPU 输出
1What is the best laptop for programming?What is the best laptop for programming?
2I want to buy a smartphone, can you recoI want to buy a smartphone, can you reco
3The shipping was very fast and the produThe shipping was very fast and the produ
4Compare iPhone and Android phonesCompare iPhone and Android phones have d
5How to choose a good pair of headphones?How to choose a good pair of headphones?
下载使用量0