g
gcw_coj3XaOd/VisualQuality-R1-7B
模型介绍
文件和版本
Pull Requests
讨论
分析

TianheWu/VisualQuality-R1-7B - 昇腾 NPU 推理部署

1. 模型简介

模型名称: TianheWu/VisualQuality-R1-7B

模型链接: HuggingFace

模型描述: VisualQuality-R1-7B 是一个基于 Qwen2.5-VL 架构的视觉质量评估模型,能够对输入图像进行质量评分和分析。

模型架构: Qwen2.5-VL (Vision-Language Model)

参数规模: ~8.3B

输入规格:

  • 图像:224x224 RGB(支持任意尺寸,自动预处理)
  • 文本:自然语言问题/指令

输出规格:

  • 文本:图像质量评估描述和评分

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch_npu>= 2.1.0昇腾 NPU 后端
transformers>= 4.51.0HuggingFace Transformers(实测 4.57.6)
accelerate>= 0.25.0用于 device_map 自动分配
Pillow>= 9.0图像处理
numpy>= 1.24数值计算
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

pip install torch-npu transformers accelerate Pillow numpy

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(推荐,需配置镜像)

export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download TianheWu/VisualQuality-R1-7B --local-dir ./VisualQuality-R1-7B

方式二:AtomGit 镜像(HuggingFace 下载慢时使用)

huggingface-cli download https://ai.gitcode.com/hf_mirrors/TianheWu/VisualQuality-R1-7B --local-dir ./VisualQuality-R1-7B

3.3 运行推理

# 使用 inference.py 运行推理
python3 inference.py --model-path ./VisualQuality-R1-7B

# 指定输入图像和问题
python3 inference.py --model-path ./VisualQuality-R1-7B --image test.jpg --question "Rate the quality of this image on a scale of 1-10."

# 指定 NPU 设备和生成长度
python3 inference.py --model-path ./VisualQuality-R1-7B --device 0 --max-new-tokens 512

3.4 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--imagestrNone输入图像路径(None 则使用随机测试图)
--questionstr"Rate the quality..."关于图像的问题
--max-new-tokensint512最大生成长度
--deviceint0NPU 设备编号

4. 推理成功日志

4.1 单条推理日志

[模型] TianheWu/VisualQuality-R1-7B
[设备] NPU:0 (Ascend910_9362)
[输入] 使用随机测试图像 (224x224)
[输出] The quality of the image is very poor, with a score of 1 out of 10...
[耗时] 56.61s
[状态] SUCCESS

5. 测试样例及输出结果

样例 1:默认推理(随机测试图像)

运行命令:

python3 inference.py --model-path /tmp/adapt_tianhewu_visualquality-r1-7b/weights

输出:

[设备] NPU:0 (Ascend910_9362)
[加载] 加载模型: /tmp/adapt_tianhewu_visualquality-r1-7b/weights
[输入] 使用随机测试图像 (224x224)
[推理] 生成中 (max_new_tokens=512)...
[输出] The quality of the image is very poor, with a score of 1 out of 10. The image appears to be heavily pixelated and lacks any discernible content or clarity. It is not possible to make out any details or features in the image due to the extreme pixelation.
[耗时] 56.61s
[状态] SUCCESS

6. Agent适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

测试数据: 随机生成的 224x224 测试图像

评测指标:

指标结果说明
模型加载时间~93s (729 shards)首次加载权重
单次推理耗时56.61s含模型加载+预处理+生成
生成质量SUCCESS模型正常输出评估文本

评测命令:

python3 inference.py --model-path /tmp/adapt_tianhewu_visualquality-r1-7b/weights

8. NPU 配置说明

  • NPU 型号: Ascend 910_9362
  • NPU 数量: 2 卡
  • 单卡显存: 61.27 GiB
  • Tensor Parallel: device_map="auto"(自动拆分至 2 卡)
  • CANN 版本: 8.5.1
  • 数据类型: bfloat16

9. 已知问题

无