gcw_mXoV1I2Z/VisualQuality-R1-7B
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

VisualQuality-R1-7B · 昇腾 NPU 适配

VisualQuality-R1 是首个通过 RL2R (Reinforcement Learning to Rank) 增强的无参考图像质量评估 (NR-IQA) 模型,支持基于推理的质量描述与评分。本仓库为该模型在昇腾 Ascend910 平台的 torch-npu 适配版本。

  • 原始模型: TianheWu/VisualQuality-R1-7B(NeurIPS 2025 Spotlight)
  • 基座: Qwen/Qwen2.5-VL-7B-Instruct
  • 任务: 单图无参考图像质量评估,评分区间 1.0 – 5.0(两位小数)
  • 设备: 昇腾 Ascend910(npu:N),bf16,单卡推理
  • 论文: arXiv:2505.14460 | 代码: github.com/TianheWu/VisualQuality-R1

环境

组件版本
Python3.11
torch2.9.0
torch_npu2.9.0.post1
transformers4.57.6
CANN8.5.1

权重

权重缓存于 ./model_weights/VisualQuality-R1-7B/(约 16.6GB,4 个 safetensors 分片)。首次运行 inference.py 时会自动从 hf-mirror.com 下载并缓存;已缓存则直接复用,避免重复下载。

使用方法

CLI 单图推理

python inference.py --img test_input.png --device npu:1

输出 JSON(含 rating_text 与 score):

{
  "model": "VisualQuality-R1-7B",
  "score": 4.05,
  "rating_text": "<answer>4.05</answer>",
  "actual_device": "npu:1",
  "exit_status": 0
}

FastAPI 服务

python inference.py --serve --port 8000
curl -F "file=@test_input.png" http://127.0.0.1:8000/predict

推理 Prompt(非思考模式)

You are doing the image quality assessment task. Here is the question:
What is your overall rating on the quality of this picture? The rating should
be a float between 1 and 5, rounded to two decimal places, with 1 representing
very poor quality and 5 representing excellent quality.

问题模板:{Question} Please only output the final answer with only one score in <answer> </answer> tags.

适配说明

  • 全代码域删除 CUDA 调用,模型与输入 Tensor 迁移至 npu:N。
  • attn_implementation="eager",不依赖 flash-attn。
  • NPU 初始化含 try-except,失败即报错,不做 CPU/CUDA 回退。
  • 推理后 torch.npu.empty_cache() 释放显存(bf16 7B 约 14GB,单卡 64GB 足够)。