atlasleong/visualquality-r1-7b-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

VisualQuality-R1-7B — Ascend NPU inference candidate

This directory is a complete, reproducible Ascend NPU inference candidate for the pinned upstream model TianheWu/VisualQuality-R1-7B.

  • Pinned source revision: 12852ce5718dac0d1bd32845d462a6027374ceec
  • Pinned real checkpoint: four safetensors shards (model-00001..00004-of-00004.safetensors) + tokenizer.json, sizes and SHA256 recorded in logs/npu_result.json (checkpoint_sha256) and verified 5/5 before load.
  • Architecture route: transformers Qwen2_5_VLForConditionalGeneration (Qwen2.5-VL image-quality reward / reasoning, non-thinking mode).
  • Inference engine: torch_npu (torch 2.9.0+cpu + torch_npu 2.9.0, CANN-matched).
  • Target device: physical npu:3 (Ascend910B4-1).
  • Deterministic test: synthetic 224×224 RGB image + non-thinking reward prompt → <answer>1.00</answer> (score 1.0).

The model forward runs wholly on npu:3. The CPU only orchestrates Python, hashes the pinned artifacts, deserializes the checkpoint, and preprocesses the image/text. There is no CPU offload and no CPU fallback; any NPU initialization, placement mismatch, or execution error makes the process exit nonzero.

Model introduction / 模型简介与来源

FieldValue
Model IDTianheWu/VisualQuality-R1-7B
Sourcehttps://huggingface.co/TianheWu/VisualQuality-R1-7B
Pinned revision12852ce5718dac0d1bd32845d462a6027374ceec
pipeline_tagreinforcement-learning
library_nametransformers
NPU tagsascend, npu, torch_npu, hardware: NPU
ArchitectureQwen2_5_VLForConditionalGeneration (base Qwen/Qwen2.5-VL-7B-Instruct)
Parameter count8,292,166,656 (bf16)
TaskNR-IQA image quality rating / reasoning (reward model, RL2R)
Deterministic output<answer>1.00</answer> (score 1.0)

License (without guessing)

The upstream model card front matter declares license: mit (verified directly from the pinned local model card README.md). This delivery reproduces that metadata verbatim as license: mit. The exact source revision and the original card tags (IQA, Reasoning, VLM, Pytorch, R1, GRPO, RL2R) are preserved. We do not relabel or extend the license beyond what the upstream card states.

Environment dependencies / 环境依赖清单

Tested in this container (delivery root /work/pipeline/jobs/rl26/visualquality-r1-7b/visualquality-r1-7b-npu):

ComponentVersion / value
OSLinux 5.10.0 .oe2203sp4.aarch64 (openEuler, aarch64)
Python3.11.14
CANN8.5.1 (Ascend910B4-1)
torch2.9.0+cpu (image-provided, CANN-matched — do not replace)
torch_npu2.9.0 (image-provided, CANN-matched — do not replace)
transformers5.15.1
huggingface_hub1.28.0
torchvision0.24.0
numpy1.26.4
Pillow12.3.0
safetensors0.8.0
npu-smi25.5.1
HardwareAscend910B4-1 (8 devices; this candidate uses physical npu:3)

The interpreter is the pre-provisioned model venv /work/pipeline/runtime/model-venvs/transformers-5.15.1/bin/python; its venv-local Transformers is 5.15.1 and its system-site packages provide the CANN-matched torch 2.9.0+cpu / torch_npu 2.9.0 and torchvision 0.24.0.

Installation (Aliyun mirror only)

The pinned venv already contains every package above; no additional package was installed for this delivery. If you must recreate an isolated model-specific venv, install only non-torch runtime dependencies and fetch only from the Aliyun PyPI mirror:

# 1. Create the model-specific venv (inherits system-site CANN-matched torch/torch_npu).
python -m venv --system-site-packages /work/pipeline/runtime/model-venvs/transformers-5.15.1

# 2. Install the non-torch runtime dependencies from Aliyun only.
pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/

Equivalently, pin the mirror for the whole shell:

export PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
pip install -r requirements.txt

⚠️ Never install torch or torch_npu from PyPI. They are provided by the image as a CANN-matched pair (torch 2.9.0+cpu + torch_npu 2.9.0) and must stay untouched. The requirements.txt comment header records this policy.

Inference steps / 分步推理操作

# 1. Load the CANN environment (required for NPU runtime).
source /usr/local/Ascend/ascend-toolkit/set_env.sh

# 2. Sanity-check the NPU devices.
npu-smi info

# 3. Run the deterministic NPU inference (device npu:3; a hold window keeps the process
#    alive so npu-smi can capture the live PID on device 3).
cd /work/pipeline/jobs/rl26/visualquality-r1-7b/visualquality-r1-7b-npu
/work/pipeline/runtime/model-venvs/transformers-5.15.1/bin/python inference.py \
    --run-id 1 --output logs/npu_result.json --log logs/npu_inference.log \
    --smi-capture logs/npu_smi_capture.txt --hold 20 --max-new-tokens 64

# 4. Inspect the structured result.
cat logs/npu_result.json

Complete test case and output / 完整测试用例与输出

Command (two consecutive fresh processes, same venv + same input):

cd /work/pipeline/jobs/rl26/visualquality-r1-7b/visualquality-r1-7b-npu

/work/pipeline/runtime/model-venvs/transformers-5.15.1/bin/python inference.py \
    --run-id 1 --output logs/npu_result.json --log logs/npu_inference.log \
    --smi-capture logs/npu_smi_capture.txt --hold 20 --max-new-tokens 64

/work/pipeline/runtime/model-venvs/transformers-5.15.1/bin/python inference.py \
    --run-id 2 --output logs/npu_result_run2.json --log logs/npu_inference_run2.log \
    --smi-capture logs/npu_smi_capture_run2.txt --hold 15 --max-new-tokens 64

Exit code: 0 for both. Run 1 PID 891779, run 2 PID 895572 — both correlated live with npu-smi on physical npu:3 (16432 MB). Both runs produced byte-identical output.

Actual output (logs/npu_inference.log):

[2026-08-22 13:04:29] VisualQuality-R1-7B  -  Ascend NPU reward/reasoning inference
[2026-08-22 13:04:29] sys.executable   : /work/pipeline/runtime/model-venvs/transformers-5.15.1/bin/python
[2026-08-22 13:04:29] version transformers    : 5.15.1
[2026-08-22 13:04:29] version torch           : 2.9.0+cpu
[2026-08-22 13:04:29] version torch_npu       : 2.9.0
[2026-08-22 13:04:29] source revision  : 12852ce5718dac0d1bd32845d462a6027374ceec
[2026-08-22 13:04:29] npu device       : npu:3  name=Ascend910B4-1
[2026-08-22 13:04:44] pinned artifacts verified: 5/5
[2026-08-22 13:04:46] processor         : Qwen2_5_VLProcessor  image=Qwen2VLImageProcessor  video=Qwen2VLVideoProcessor  tok=Qwen2Tokenizer
[2026-08-22 13:04:46] input device      : npu:3 (all tensor inputs)
[2026-08-22 13:04:47] strict load       : 729/729 tensors, missing=0 unexpected=0
[2026-08-22 13:04:47] spot-check        : 5 tensors byte-equal to raw safetensors
[2026-08-22 13:04:50] model device      : npu:3  params=8292166656 dtype=torch.bfloat16
[2026-08-22 13:04:51] logits device     : npu:3  shape=(1, 168, 152064) dtype=torch.bfloat16
[2026-08-22 13:04:52] generated text    : '<answer>1.00</answer>'
[2026-08-22 13:04:52] parsed score      : 1.0
[2026-08-22 13:04:52] output sha256     : d4a6e25a1a45bbde35f865352cfacbb29cb3bfc6d3c8cbb848200ace237e19f4
[2026-08-22 13:04:53] [NPU-SMI] match: | 3       0                 | 891779        | python                   | 16432                   |
[2026-08-22 13:05:14] npu-smi pid match : True
[2026-08-22 13:05:14] INFERENCE OK (exit_code=0)

Key result values (all on npu:3):

OutputValueNotes
generated_text<answer>1.00</answer>on npu:3, greedy decode
score1.0parsed from the answer
output sha256d4a6e25a…19f4identical across both runs
logits(1, 168, 152064) bf16on npu:3
strict_load729/729, missing 0, unexpected 05 tensors spot-checked byte-equal

Placement evidence in logs/npu_result.json (top level): engine: torch_npu, npu_available: true, npu_device_name: Ascend910B4-1, source_revision: 12852ce5…, input_device: npu:3, model_device: npu:3, output_device: npu:3, exit_code: 0.

Determinism (two consecutive fresh processes, same venv + same input):

RunPIDexitgenerated_textoutput sha256
18917790<answer>1.00</answer>d4a6e25a…19f4
28955720<answer>1.00</answer>d4a6e25a…19f4

Evidence screenshots

Rendered from the real final transcript / sanitized log / result JSON (no fabricated values):

  • assets/agent_workflow.png — agent workflow: read-only upstream routing, pinned-revision checkpoint verification, NPU init, official Qwen2.5-VL processor, strict load, NPU forward, and result JSON.
  • assets/npu_device_call.png — live npu-smi device / process call on physical npu:3 (PID correlation during the hold window).
  • assets/model_result.png — final model result: <answer>1.00</answer>, score, shapes, devices, versions, timing and PID.
  • assets/modelagent_live_session.png — sanitized excerpts from the real ModelAgent requirement/repair conversation, followed by the independently rerun final PID and acceptance result.

Limitations

  • Determinism is bounded to the pinned environment. The two fresh runs reproduced the identical <answer>1.00</answer> output only under the pinned venv (transformers 5.15.1, torch 2.9.0+cpu, torch_npu 2.9.0). Outside this exact stack the numerical output is not guaranteed.
  • Synthetic test input. The scoring image is a deterministic 224×224 synthetic gradient (bright square + dark bar) that the model rates low (1.00). It is a reproducible probe, not a real photograph; it does not benchmark real-world IQA accuracy.
  • Non-thinking reward mode only. Per the upstream card, the reward/evaluation path uses non-thinking inference producing a single score in <answer> tags. Thinking-style chain of thought is not exercised.
  • Versioned processor remap. The pinned checkpoint uses 4.49-era tensor names (model.*, visual.*); transformers 5.15.1 nests them as model.language_model.* / model.visual.*. from_pretrained performs this remap internally and this delivery's strict-load check applies the same mapping, so counts are exact (729/729).
  • Device mapping. This candidate is validated for physical npu:3. On another host with a different ASCEND_RT_VISIBLE_DEVICES mapping, verify npu:3 still selects the intended physical device.
  • Checkpoint not shipped. The immutable checkpoint is referenced at its source path (/work/pipeline/models/rl26/visualquality-r1-7b); it is not copied into this delivery.