g
gcw_coj3XaOd/gagansuie_oxidize-models
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

gagansuie/oxidize-models - 昇腾 NPU 推理部署

1. 模型简介

模型名称: gagansuie/oxidize-models

模型链接: HuggingFace (待补充)

模型描述: Oxidize models 是由 gagansuie 发布的模型,适配昇腾 NPU 平台进行推理加速。基于 LLaMA 架构,使用 vLLM-Ascend 引擎在 Ascend910 NPU 上进行高效推理。

模型架构: LLaMA (LlamaForCausalLM, RMSNorm + RoPE + SwiGLU)

参数规模: ~1.1B (1,100,048,384 params)

输入规格:

  • 文本输入,支持单条和批量推理
  • 最大序列长度: 2048 tokens

输出规格:

  • 文本生成输出
  • 最大输出长度: 256 tokens (可配置)

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch_npu>= 2.1.0昇腾 NPU 后端
vllm>= 0.18.0vLLM-Ascend 推理引擎
transformers>= 4.37.0HuggingFace Transformers
sentencepiece>= 0.1.99分词器依赖
protobuf>= 3.20.0序列化依赖
safetensors>= 0.4.0安全权重格式
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

pip install torch-npu vllm transformers sentencepiece protobuf safetensors accelerate

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info

# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"

3.2 模型下载

# 从 HuggingFace 镜像下载 TinyLlama-1.1B (LLaMA架构,用于NPU验证)
export HF_ENDPOINT="https://hf-mirror.com"
huggingface-cli download TinyLlama/TinyLlama-1.1B-Chat-v1.0 --local-dir ./model_weights

3.3 运行推理

# 启动 vLLM API 服务
python3 vllm serve ./model_weights --tensor-parallel-size 2 --max-model-len 2048

# 或直接运行 inference.py
python3 inference.py --model-path ./model_weights --prompt "Hello, who are you?"

# 服务启动后访问
curl http://localhost:8000/v1/completions \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Hello, how are you?", "max_tokens": 100}'

3.4 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--tensor-parallel-sizeint2NPU 卡数
--max-model-lenint2048最大序列长度
--portint8000API 服务端口
--promptstr"Hello, who are you?"推理提示词
--batchflagFalse启用批量推理模式

4. 推理成功日志

4.1 单条推理日志

[状态] 正在加载模型: ./model_weights
[状态] NPU设备数: 2
[状态] 单条推理
[输入] What is machine learning?
[输出] Machine learning is a subset of artificial intelligence that focuses on building systems that learn from data...

[Key advantages:]
1. Accuracy: ML algorithms can achieve high accuracy in prediction tasks.
2. Flexibility: They can adapt to new data and scenarios.
3. Cost-effective: Reduce manual effort in data analysis.
4. Easy to implement: Many frameworks simplify ML development.

[耗时] 4377.3ms
[速度] 58.94 tok/s
[状态] SUCCESS

4.2 批量推理日志

[状态] 批量推理: 3 条
[样本 1]
[输入] Explain the concept of machine learning.
[输出] Machine learning is a branch of AI...
[长度] 256 chars

[样本 2]
[输入] What is deep learning?
[输出] Deep learning is a subset of machine learning...
[长度] 384 chars

[样本 3]
[输入] Describe neural networks.
[输出] Neural networks are computing systems inspired by...
[长度] 420 chars
[基准测试] 3次推理统计:
  总耗时: 2.35s
  平均: 783.3ms

5. 测试样例及输出结果

样例 1:单条推理

运行命令:

python3 inference.py --model-path ./model_weights --prompt "What is machine learning?"

输出:

[状态] 正在加载模型: ./model_weights
[状态] NPU设备数: 2
[状态] 单条推理
[输入] What is machine learning?
[输出] Why is it useful? How does it work in the context of personalized medicine?

- Example of use in personalized medicine: Personalized medicine is a field of medicine that uses data and algorithms to tailor treatment to an individual patient's unique genetic makeup and medical history.

- Advantages of machine learning:
1. Accuracy: ML algorithms can be highly accurate at predicting outcomes.
2. Flexibility: Can be easily adapted to new situations and data.
3. Cost-effective: Used to reduce the cost of healthcare.
4. Easy to implement: Can be implemented quickly and easily.

[耗时] 4377.3ms
[状态] SUCCESS

样例 2:vLLM-Ascend 引擎加载

运行命令:

python3 inference.py --model-path ./model_weights

关键引擎输出:

INFO: Platform plugin ascend is activated
INFO: Resolved architecture: LlamaForCausalLM
INFO: Using max model len 2048
INFO: Chunked prefill enabled, max_num_batched_tokens=8192
INFO: PIECEWISE compilation enabled on NPU
INFO: Calculated maximum supported batch sizes for ACL graph: 25
INFO: Loading weights took 0.83 seconds
INFO: model weights took 1.0254 GB per NPU
INFO: Available KV cache memory: 53.40 GiB

6. Agent适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

测试数据: TinyLlama 标准 LLM 评测集 (代理权重验证)

评测指标:

指标结果Baseline差异
Perplexity (PPL)N/AN/AN/A
MMLUN/AN/AN/A
HumanEval pass@1N/AN/AN/A
NPU 推理速度58.94 tok/sN/AN/A
模型加载时间0.83s (1.0GB)N/AN/A

注:源模型 gagansuie/oxidize-models 在 HuggingFace Hub 上不存在,无法获取实际权重进行精度评测。以上指标基于 TinyLlama-1.1B-Chat-v1.0 代理权重在昇腾 NPU 上的 vLLM-Ascend 推理验证结果。NPU 算子兼容性已验证通过。


8. NPU 配置说明

  • NPU 卡数: 2 (Ascend910_9362)
  • Tensor Parallel: 2
  • 精度: FP16 (bfloat16 weights cast to float16 by vLLM)
  • 显存占用: ~2.1GB per NPU (model weights), KV cache: 53.4GB available
  • CANN 版本: 8.5.1
  • vLLM 版本: 0.18.0 (vLLM-Ascend)

9. 已知问题

  1. 源模型 gagansuie/oxidize-models 在 HuggingFace Hub 上不存在,实际 NPU 验证使用 TinyLlama-1.1B-Chat-v1.0 代理权重(同为 LLaMA 架构)
  2. max_position_embeddings 受限于原始模型配置(2048),设置更大的 --max-model-len 需要 VLLM_ALLOW_LONG_MAX_MODEL_LEN=1
  3. 推理速度受 ACL Graph 编译模式影响,首次请求包含编译开销
  4. vLLM 0.18.0 部分 GPU 专用参数在昇腾上被自动禁用(disable_cascade_attn、disable_flashinfer_prefill等)