Repository navigation
test: lock the diffusion reference-PSNR ranking regression - #375
Conversation
Record that a blurred frame can outrank a sharp shift on PSNR while Laplacian variance ranks them the other way. Noise that raises the variance is not a quality pass, and the still-image gate is unchanged. Agent-assisted-by: Cursor Grok 4.7 (author) Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Dong1017 <Dong1017@users.noreply.github.com>
|
@zengchuang-hw @amy-why-3459 Please review this CPU-only regression for #364. It locks the known case where a blurred frame outranks a sharp shift on reference PSNR, and where high-frequency noise raises Laplacian variance. It does not change |
There was a problem hiding this comment.
PR review verdict — DO NOT PASS
Reviewed base 9f61a83f030bfa2ffe3b54eac1781593309d6380 and head 4ceba274a9e4592fd949cd9404e9a301349fd5ee (full diff, first review). Prior reviews: none. Test-only change: tests/test_diffusion_reference_psnr.py.
Blockers
-
Shift-PSNR pin disagrees with this fixture (
tests/test_diffusion_reference_psnr.py:64).sharpis iiduint8fromdefault_rng(0)at 128×128, andshiftedisnp.roll(sharp, 3, axis=1). Every pair is two independent samples on{0..255}:Var = (256**2 - 1) / 12 = 5461.25E[MSE] = 2 * Var = 10922.5PSNR = 10 * log10(255**2 / 10922.5) ≈ 7.75 dB
Lag-3 overlap inflates the standard error to about 0.05 dB.assertAlmostEqual(..., 7.61, delta=0.05)accepts only[7.56, 7.66], which sits about 0.1 dB below that center. The pin fails unless this seed is a multi-sigma low outlier. Re-run this seed and replace 7.61 with the measured value (expect about 7.75). Re-measure the blurred pin on line 65 in that same run (11.01 ± 0.05was not recomputed here)._psnritself (float64, peak255**2,infat MSE 0) matches the usual 8-bit definition.
-
Laplacian ratio uses a false exact invariant (
tests/test_diffusion_reference_psnr.py:66)._laplacian_variancepads withmode="edge". A 3-column circular roll is not an exact symmetry of that operator: on 128×128, on the order of 5% of the taps (the padded border and the strip whose neighborhood crosses the roll) differ from a shifted interior response.places=3requires|ratio - 1| < 5e-4. That tolerance is tighter than the border mismatch, so the assertion is expected to fail for this fixture. If the claim is shift invariance, use a circular Laplacian. Otherwise set the tolerance from the same seed run that re-pins PSNR.
Failure path: ReferencePsnrRankingTest.test_blur_can_outrank_a_sharp_shift_on_psnr fails on the pin or the ratio before any production gate result is checked. Severity: the regression lock is wrong or unstable; production thresholds are unchanged.
Checked
- Diff adds one unittest module. It does not modify
ImageQualityGatethresholds or scoring. - Ranking direction in the docstring is consistent with the formulas: an 8-pass box blur of iid noise stays nearer the original than an independent roll (~7.75 dB), while edge-padded Laplacian energy drops.
_box_bluris a convex combination of rolls, so theuint8cast truncates and does not wrap.
Not verified here
- NumPy was not executed, so the seed-0 sample PSNR and the realized Laplacian ratio were not printed.
- The ordered
ImageQualityGate.__dataclass_fields__list at lines 74-84 was not compared toinferrsi/model/validators/image.py(class body is not in the review seed). A name or order mismatch failstest_high_frequency_noise_raises_laplacian_variance_without_a_pass.
Follow-up (non-blocking)
_psnr, _laplacian_variance, and _box_blur are local. This file never calls a production reference-PSNR scorer, so a regression in the diffusion validator stays green. The field equality also fails on any new dataclass field, including fields other than sharpness.
I will re-read after the author pushes. Dong-bot review under the InferRSI queue; this comment does not approve.
|
本次 review 范围:完整 diff(新 PR),base 阻塞项
关于数值钉住的复核 我在本地(NumPy 2.5.4)按本 PR 的函数和 seed 复算了一遍:shifted PSNR = 7.6121 dB,blurred PSNR = 11.0078 dB,shifted/sharp Laplacian 方差比 = 1.000445,blurred/sharp = 0.000236。所以第 64–65 行的 7.61 / 11.01 在这个版本下是对的,另一条 review 里“应为约 7.75 dB”的推算与实测不符。但有两点仍希望调整:
非阻塞建议
|
|
Independent check on I ran the exact module on NumPy 2.3.5 (3 passed). The shifted and blurred PSNR values were 7.612122 and 11.007766 dB, respectively. The shifted/sharp Laplacian variance ratio was 1.00044492. This independently confirms the sample values and the narrow tolerance margin. The ordering with a margin is the durable assertion for this source fixture. Test. I also checked the dependency question. The Draft, Ready, Merge and Nightly workflows have no explicit installation of the |
Run the blur-versus-shift ordering in dependency-free arithmetic, and repeat it with NumPy only when that extra is installed. Drop the tight seed pins so a Generator change cannot fail a still-valid ranking. Agent-assisted-by: Cursor Grok 4.7 (author) Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Dong1017 <Dong1017@users.noreply.github.com>
|
@zengchuang-hw @amy-why-3459 Please re-review head |
Keep the ordering assertion, and note the 7.612 dB and 11.008 dB sample so it is not confused with the 7.75 dB independent-pixel center. Agent-assisted-by: Cursor Grok 4.7 (author) Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Dong1017 <Dong1017@users.noreply.github.com>
|
@zengchuang-hw @amy-why-3459 Please re-review the current head |
|
本次 review 范围:增量 上次意见的处理情况
阻塞项
非阻塞建议
|
There was a problem hiding this comment.
LGTM
PR review verdict — PASS
Reviewed base 9f61a83f030bfa2ffe3b54eac1781593309d6380 and head 298f2cdeb41863c02f0bfbed3daf8cb99874664c (incremental 4ceba274a9e4592fd949cd9404e9a301349fd5ee..298f2cdeb41863c02f0bfbed3daf8cb99874664c).
Earlier findings
- Absolute shift/blur PSNR pins are removed.
tests/test_diffusion_reference_psnr.pynow uses a fixed 64×64 pattern and locks the ranking withblurred_psnr - shifted_psnr > 2. - The shifted Laplacian ratio is no longer required to equal 1.0 to 3 decimal places. The check is one-sided: shifted/detail > 0.95 and blurred/detail < 0.05, which fits an edge-padded 4-neighbor Laplacian after a circular shift.
Verified on this diff
_shift(..., 3)is a circular right rotate, the same index mapping asnp.roll(..., 3, axis=1)._bluris eight circular 5-point averages and truncates toward zero, matching the NumPy twin'sastype(np.uint8)path for nonnegative values._psnruses float MSE, peak255**2, and returnsinfwhen MSE is 0._laplacian_varianceis the edge-padded kernel[[0,1,0],[1,-4,1],[0,1,0]]with population variance (divide by N).test_blur_can_outrank_a_sharp_shift_without_numpyalways runs the ranking assertion.test_numpy_cpu_agrees_when_installedskips only onImportError.- The gate check walks
ImageQualityGate.__dataclass_fields__and rejects field names containing sharpness, laplacian, luma, or temporal.
Analytic check of the fixed pattern (phase 17x+31y, residue at most 12): one blur pass has gain about 0.855 on the sawtooth fundamental and kills harmonics k≥2 by pass 8, so blur-versus-sharp PSNR lands near 12 dB. A 3-pixel shift leaves MSE near 10^4 (row 0 SSE is 632256 over 64 pixels, about 8.2 dB). The gap stays above 2 dB. Blurred Laplacian power collapses onto that attenuated fundamental, so the ratio stays under 0.05. The 0.95 shift ratio is the edge-padding border term (252 border pixels) and should clear 0.95. This was derived from the operators in the diff, not from executing the test module.
Not verified here
Tests were not executed in this environment. CI on head 298f2cdeb41863c02f0bfbed3daf8cb99874664c was not rechecked.
Optional follow-ups
- The module comment cites NumPy 1.26.4 seed-0 figures of about 7.612 dB and 11.008 dB. Those figures sit outside the assertions. At 128×128, PSNR of the independent-pixel MSE center (~7.75 dB) is within about 0.01 dB of E[PSNR]; a 0.14 dB gap is sample fluctuation, which is why that pin was dropped.
- The NumPy test repeats the ranking inequalities on that runtime's shift and blur. Array equality with
_shift/_bluris unchecked.
|
@amy-why-3459 @zengchuang-hw — quick timeline note on #375 (comment). This is a race, not a claim that the review was wrong. That comment (23:18:13 UTC / 07:18:13 Asia/Shanghai) reviewed incremental
On Please continue from current head |
amy-why-3459
left a comment
There was a problem hiding this comment.
LGTM
PR review verdict — PASS
Reviewed base 9f61a83f030bfa2ffe3b54eac1781593309d6380 and head 298f2cdeb41863c02f0bfbed3daf8cb99874664c(增量 4be8581bd58855c4198650cf03674f4e02544128..298f2cdeb41863c02f0bfbed3daf8cb99874664c)。
- 增量只有 1 个提交,
tests/test_diffusion_reference_psnr.py第 125–126 行新增 2 行注释,不改断言。 - 上次评论的阻塞项均已解决:当前 head 上
pr-references、full-check (3.10/3.11)、installed-package (3.10/3.11)、declarations、lint-and-smoke全部 success;PR 描述里的head_sha与当前 head 一致。上次第 3 点是我读到旧 head 造成的时序问题,感谢 @Dong1017 指出,这一点撤回。 - 之前确认过的修复保持不变:无顶层 NumPy import、只断言排序和间隔、
ImageQualityGate阈值未改。
可选(非阻塞):_assert_blur_outranks_shift(第 95–97 行)仍是裸 assert,python -O 下会被去掉,后续可改为由测试方法用 self.assertGreater / self.assertLess 断言。
|
LGTM PR review verdict — PASS Prior DO NOT PASS on
Verified by inspection:
Not verified here: the tests were not executed, and NumPy was not imported. Optional: bare |
zengchuang-hw
left a comment
There was a problem hiding this comment.
LGTM
PR review verdict — PASS
Incremental review 4ceba274a9e4592fd949cd9404e9a301349fd5ee..298f2cdeb41863c02f0bfbed3daf8cb99874664c. Reviewed target main, PR base 9f61a83f030bfa2ffe3b54eac1781593309d6380, and current head 298f2cdeb41863c02f0bfbed3daf8cb99874664c. My previous review. The regression-test slice is ready.
本轮已解决
- The dependency-free fixture collects and runs with NumPy unavailable. It asserts the inverted PSNR ranking and a margin, and the optional NumPy path repeats the same fixture. The seed-0 values are explanatory comments. The diff changes one test file within #364.
- The current PR description uses
Refs #364and declares this head.pr-referencesandfull-checkon Python 3.10 and 3.11 passed on the current revision. The intervening main change from #376 touched the layout docs and import-gate test, with no overlap with this regression or its CI definitions. Ready CI · Knowledge policy.
批准前必做(Before I can approve)
None.
非阻塞问题或建议
Amy's suggestion to move the helper's bare assertions into unittest assertions would preserve the checks under python -O. Ready CI uses standard Python. Prior suggestion.
Independent verification on CPU with Python 3.12.1 and NumPy 2.3.5 passed all three targeted tests. With the NumPy import blocked, two passed and the optional twin skipped. Ruff and git diff --check passed. The review covers the synthetic CPU regression. Video quality on real media, model and device runs, and #364's remaining acceptance criteria were outside this review.
Direct delegation from zengchuang-hw. Acting independent reviewer: Codex, using the GitHub account zengchuang-hw. Scope: review the current #375 revision and its applicable evidence. Authorized review actions: post findings and submit a revision-bound Approve when the criteria are met.
Governing Issue and delivery slice
Refs #364
tests/test_diffusion_reference_psnr.pylocks the ordering: a blurred frame can have higher PSNR than a sharp shift, while Laplacian variance ranks the pair the other way. The dependency-free case always runs. A NumPy twin runs only when NumPy is installed.ImageQualityGate, no new PASS condition for sharpness, luma, or frame difference, no H3 evidence-validator change, and no GPU, NPU, or model run. Issue 364 remains open.Knowledge authorship declaration
Not applicable. This PR adds a CPU test only and does not change knowledge content.
Changed artifacts and evidence
.[dev]only, so that twin stays skipped thereImageQualityGatehas no sharpness, laplacian, luma, or temporal field.git diff --checkclean. Ruff 0.17.4 passed on this fileChecks and dependencies
PYTHONPATH=src python3 -m unittest tests.test_diffusion_reference_psnrwith NumPy 1.26.4: 3 passed. The same command with NumPy imports blocked: 2 passed, 1 skipped.python3 -m ruff check tests/test_diffusion_reference_psnr.py: passed.imageextra. This test does not add it to the default or dev extras.Remaining work and Issue closure
Handoff (only when an actual handoff or decision changed)
298f2cdeb41863c02f0bfbed3daf8cb99874664c.