Open
【11月贡献大赛-Bug修复】fix(image-processor-config-auditor): 拦截负 image_std 归一化标准差(Fixes #4171) #7338
【11月贡献大赛-Bug修复】fix(image-processor-config-auditor): 拦截负 image_std 归一化标准差(Fixes #4171) #7338
Open
W8FXN182FAdd on 19 hours ago
W8FXN182F
W8FXN182F
19 hours ago

一句话

preprocessor_config.json 审计器只拦截 image_std 恰为 0 的情况,负标准差(如 [-0.5, 0.5, 0.5])仍被判为 READY;本 PR 将负 image_std 作为独立 BLOCK finding 拦截,并保留原有零标准差规则。

复现(命令 + 修复前输出)

import sys
sys.path.insert(0, "skills/verification/ascend-image-processor-config-auditor/scripts")
import audit_image_processor_config as auditor

config = {
    "image_processor_type": "CLIPImageProcessor",
    "do_normalize": True,
    "image_mean": [0.5, 0.5, 0.5],
    "image_std": [-0.5, 0.5, 0.5],
}
print(auditor.audit(config, {"num_channels": 3}))

修复前输出(决策 READY、无 finding):

{'decision': 'READY', 'findings': []}

对比:把 image_std 中的 -0.5 换成 0.0 时原逻辑能返回 BLOCK,说明负值绕过了 ZERO_NORMALIZATION_STD 检查。负标准差会反转对应通道的归一化方向,与预处理契约不一致。

方案

在 scripts/audit_image_processor_config.py 的归一化向量校验处:

  • 保留 ZERO_NORMALIZATION_STD(含 0 即 BLOCK);
  • 新增 NEGATIVE_NORMALIZATION_STD(BLOCK),拦截 image_std 中任一负值。

代码改动仅此 1 个脚本;另新增回归测试 tests/test_negative_std.py,并按赛制合规补齐 readme.md(原目录仅含 SKILL.md,缺 readme.md)。

证据(unittest 原始输出)

修复前基线(tests/test_audit_image_processor_config.py):Ran 27 tests in 0.123s ... OK

修复后:

  • 新增 tests/test_negative_std.py:Ran 4 tests in 0.066s ... OK
    (负值 BLOCK、正值向量 READY、零值仍 BLOCK、CLI 退出码 2)
  • 原有 tests/test_audit_image_processor_config.py:Ran 27 tests in 0.123s ... OK

复现对象验证:

  • 负 image_std -> {'decision': 'BLOCK', 'findings': [{'level': 'BLOCK', 'code': 'NEGATIVE_NORMALIZATION_STD', ...}]}
  • 正 image_std -> {'decision': 'READY', 'findings': []}

说明:本修复为纯 Python 标准库确定性复现,无 NPU 环境,未声称真机验证。


影响面分析

本 Skill 是推理前离线审计门禁(退出码 0=READY / 1=REVIEW / 2=BLOCK / 3=INPUT_ERROR,可直接挂 CI)。负 image_std 的实际危害:归一化公式为 (x - mean) / std,std 为负时对应通道的归一化方向反转,等于对模型输入做了一个"与训练预处理契约相反"的变换——推理精度会静默劣化,且这种劣化在无真机对比时极难归因。原逻辑 any(value == 0 ...) 只拦截恰为 0 的标准差,-0.5 这类负值直接绕过审计拿到 READY,属"门禁形同虚设"级别缺陷。

设计说明(为什么是独立 finding 而非扩宽零值检查)

修复采用新增 NEGATIVE_NORMALIZATION_STD 独立 finding,而非把原 ZERO 检查改成 value <= 0:

  1. 保持 finding 语义正交:std=0(除零)与 std<0(方向反转)是两类不同的配置错误,独立的 code 让维护者与使用者在审计报告里能直接区分根因;
  2. 退出码语义不变:两者都归入 BLOCK(退出码 2),原有按退出码做门禁的流水线无需任何改动;
  3. 顺序无关:配置同时含零与负值时会报两条 finding,与逐项校验的报告风格一致。

兼容性说明

  • 只增加 finding,不修改任何已有 finding 的判定条件与文案;全量 READY 配置的输出逐字节不变;
  • image_mean / 其他归一化向量的校验路径未触碰;
  • readme.md 为本次赛制合规补齐(原目录仅 SKILL.md),其中"判定/边界"两节按脚本实际行为撰写,未承诺未实现的能力。

边界矩阵(tests/test_negative_std.py 覆盖)

场景 修复前 修复后
image_std 含负值(如 [-0.5, 0.5, 0.5]) READY,无 finding BLOCK + NEGATIVE_NORMALIZATION_STD
image_std 含 0 BLOCK(原有) BLOCK(回归保护)
全正值合法 std READY READY(回归保护)
std 为标量或列表两种形态 沿用原向量校验 沿用原向量校验
likedislike
Merge blocked
ascend-robotascend-robotCollaborators
19 hours ago Added label: ascend-cla/no
ascend-robot
ascend-robotCollaborators
19 hours ago Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.


PR Approval Progress

⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)

Module Approval Details

module lgtm status approve status
sig-model-agent ❌ (0/2)(You can also ask: starmountain, 花新宇, cookieyyds, 陈少宏, 胡晓曼) ❌ (0/1)(You can also ask: 王岩, 张玉橙, 陈少宏, 胡晓曼, 顾梦沁)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

W8FXN182F, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
W8FXN182F
W8FXN182F
19 hours ago Comments:

/check-cla

likedislike
ascend-robot
ascend-robotCollaborators
19 hours ago Comments:

CLA检查未通过,详情可参考这里

likedislike
W8FXN182FW8FXN182F
19 hours ago Force-pushed 1 commits:8a17c0a6-fix(ascend-image-processor-config-auditor): 拦截负 image_std 归一化标准差(Fixes #4171)
W8FXN182F
W8FXN182F
19 hours ago Comments:

/check-cla

likedislike
ascend-robotascend-robotCollaborators
19 hours ago Removed label: ascend-cla/no
ascend-robotascend-robotCollaborators
19 hours ago Added label: ascend-cla/yes
ascend-robot
ascend-robotCollaborators
19 hours ago Comments:

CLA检查已通过,详情可参考这里

likedislike
W8FXN182FW8FXN182F
10 hours ago Modify description of pull request