VisualQuality-R1-7B(原始权重:HuggingFace TianheWu/VisualQuality-R1-7B)是基于 Qwen2.5-VL-7B-Instruct(Qwen2_5_VLForConditionalGeneration)的图像质量评价(NR-IQA)推理模型,经 RL-to-Rank 强化学习训练,可对图像质量打 1–5 分。
本交付将其适配到华为昇腾 NPU,bf16 真实推理图像质量打分。
| 项 | 值 |
|---|---|
| NPU | Ascend 910 (Ascend910_9362) |
| CANN | 8.5.1 |
| torch / torch_npu | 2.9.0+cpu / 2.9.0.post1 |
| transformers | 4.57.6 |
| 精度 | bfloat16 |
见 requirements.txt:torch、torch_npu、transformers、pillow、numpy、safetensors、accelerate。
# 1. 下载权重(HuggingFace 镜像)
export HF_ENDPOINT=https://hf-mirror.com
python -c "from huggingface_hub import snapshot_download; snapshot_download('TianheWu/VisualQuality-R1-7B', local_dir='/tmp/bigw/VisualQuality-R1-7B')"
# 2. source CANN 环境
source /usr/local/Ascend/cann-8.5.1/set_env.sh
# 3. NPU 推理(官方 non-thinking IQA prompt + add_vision_id,采样 x8 取中位分;
# 测试图为官方 GitHub 仓库 images/realistic_scenario.png 及其降质派生)
export VQ_MODEL_DIR=/tmp/bigw/VisualQuality-R1-7B
python inference.py --device npuQwen2_5_VLForConditionalGeneration.from_pretrained(..., output_loading_info=True) → missing=0 / unexpected=0 / mismatched=0。测试图:官方仓库真实照片(512px)+ 3 种降质(高斯模糊 r=15 / r=30、高斯噪声 σ=100)。官方 non-thinking 打分 prompt,采样 8 次取中位分:
| 图像 | 中位分(NPU 真实输出) | 8 采样解析率 | 单轮耗时 |
|---|---|---|---|
| sharp(原图) | 4.0(scores=[4,5,4,5,5,4,4]) | 7/8 | 3.96 s |
| blur15(模糊 r=15) | 2.0 | 1/8 | 3.19 s |
| blur30(模糊 r=30) | 3.5(2.0/5.0) | 2/8 | 3.27 s |
| noise100(噪声 σ=100) | 2.0 | 1/8 | 3.20 s |
区分度:median(sharp) − median(blur15) = +2.0,清晰图显著高于模糊图,方向正确。
精度口径如实披露:该 RL checkpoint 在 transformers/vLLM 栈下生成文本普遍退化(CPU bf16 参考与 NPU 输出一致,属模型/加载栈行为而非 NPU 适配问题),多数采样不产出规范的 <answer>x.xx</answer>;sharp 场景解析率 7/8、降质场景解析率 1–2/8,降质场景中位分基于可解析子样本。分数方向性(sharp > blur)在多轮实验中稳定。
| 指标 | 值 |
|---|---|
| 预热 | 5 轮 |
| 正式迭代 | 20 轮(单图 8 并行采样 × 64 token) |
| p50 / p90 | 3214 ms / 3279 ms |
| avg / min / max | 3229 / 3181 / 3811 ms |
| 峰值 HBM | 15.86 GB / 64 GB |
assets/agent_workflow.png:模型上卡日志(设备初始化 / 分片加载 / 8.29B 参数 / gate1 0/0/0)assets/npu_device_call.png:npu-smi 实时占用 + torch_npu 设备断言assets/model_result.png:真机 NPU 推理输出(4 种质量等级打分)#NPU