TinyLlama-1.1B-Chat-v1.0 NPU 适配验证
#+NPU
1. 简介
本仓库记录 TinyLlama-1.1B-Chat-v1.0 模型在 Ascend NPU 上的适配和验证结果。
2. 验证环境
| 组件 | 版本 |
|---|
| Python | 3.11.14 |
| PyTorch | 2.9.0+cpu |
| torch_npu | 2.9.0 |
| transformers | 4.57.6 |
| vllm-ascend | 0.18.0rc1 |
| CANN | 8.5.1 |
| NPU | Ascend 910B2 |
| modelscope | 1.36.3 |
3. 模型下载
modelscope download --model AI-ModelScope/TinyLlama-1.1B-Chat-v1.0
4. 模型架构
| 参数 | 值 |
|---|
| 架构 | LlamaForCausalLM |
| 隐藏层大小 | 2048 |
| 层数 | 22 |
| 注意力头数 | 32(键值头数:4) |
| 中间层大小 | 5632 |
| 词表大小 | 32000 |
| 总参数量 | ~1.1B |
5. 基础推理验证
#!/usr/bin/env python3
import torch_npu
from vllm import LLM, SamplingParams
MODEL_PATH = "/home/openmind/volume/modelscope/hub/models/AI-ModelScope/TinyLlama-1___1B-Chat-v1___0"
llm = LLM(
model=MODEL_PATH,
trust_remote_code=True,
dtype="float16",
tensor_parallel_size=1,
max_model_len=2048,
gpu_memory_utilization=0.9,
enforce_eager=True,
)
sampling = SamplingParams(max_tokens=64, temperature=0)
outputs = llm.generate(["The capital of France is"], sampling)
print(outputs[0].outputs[0].text)
冒烟测试结果 (4/4 通过)
| 测试 | 输入 | 输出 |
|---|
| 常识推理 | The capital of France is | Paris. |
| 代码生成 | def fibonacci(n): | (生成内容) |
| 翻译 | Translate to English: Bonjour le monde | (生成内容) |
| 数学运算 | 2 + 3 * 4 = | 12 |
6. 精度评测
ARC-Challenge 25-shot
| 指标 | hardware: NPU (vLLM-Ascend tp=1) | 基线 (GPU) | 误差 |
|---|
| 准确率 | 23.98% (281/1172) | 24.00% | -0.02% |
| 评测时间 | 116s | - | - |
| 吞吐量 | 10.13 samples/s | - | - |
7. 性能基准
输入长度 vs 输出吞吐量 (output_len=128, num_prompts=10):
| 输入长度 | 吞吐量 (tokens/s) |
|---|
| 32 | 291.61 |
| 128 | 287.22 |
| 512 | 280.67 |
| 1024 | 277.46 |
| 2048 | 283.28 |
8. 注意事项
- 模型为 Llama 架构,单卡即可加载(~2.2GB)
enforce_eager=True 确保在 NPU 上使用 eager 模式
- 小模型吞吐量高,输出约 280-290 tokens/s