Repository navigation
Add: scene-test hooks for per-case skip_golden and custom compare - #1470
Conversation
The framework compared every output against compute_golden with a fixed torch.allclose, and the only escape was the global --skip-golden flag. Outputs whose valid extent is decided by the device (a task that writes one slot per SPMD block only defines the prefix it actually ran) had no way to be checked, and merge_pipeline_barrier reached for a monkey-patch of the private _compare_outputs to drop its diagnostic tensor. - CASES[*]["skip_golden"], defaulting to the class attribute SKIP_GOLDEN, marks a case as having no host-computable golden; compute_golden is then never called for it. The CLI flag still forces it on everywhere. - compare_outputs() is overridable, so a case can compare a subset, use a per-tensor tolerance, or read the valid extent out of the output. _compare_outputs keeps its signature for the tests that import it. - merge_pipeline_barrier uses the override instead of patching module internals. Its 'timing' golden is all zeros while the run writes real counter values, so the case passing is itself proof the override runs.
📝 WalkthroughWalkthroughGolden validation now supports class-level and per-case skipping plus overridable output comparison. The merge-pipeline test adopts the hook for timing diagnostics, with documentation and unit tests covering precedence and mismatch behavior. ChangesGolden validation customization
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant SceneTestCase
participant GoldenGeneration
participant CompareOutputs
participant TestMergePipelineBarrier
SceneTestCase->>GoldenGeneration: compute golden outputs when checks are enabled
GoldenGeneration-->>SceneTestCase: golden_args
SceneTestCase->>CompareOutputs: compare test outputs with golden outputs
TestMergePipelineBarrier->>CompareOutputs: report timing gaps and omit timing
CompareOutputs-->>SceneTestCase: validate remaining outputs
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/ut/py/test_scene_test_golden_hooks.py (2)
34-35: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAnnotate framework configuration attributes as
ClassVar.Ruff reports RUF012 for these mutable class attributes. Keep them class-level, but add
ClassVarannotations to make the intended configuration contract explicit and clear the warnings.Also applies to: 106-107, 125-126
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/ut/py/test_scene_test_golden_hooks.py` around lines 34 - 35, Annotate the mutable class-level configuration attributes such as CALLABLE and CASES with typing.ClassVar in the affected test classes, including the additional occurrences noted in the review. Keep these values as class-level attributes and preserve their existing contents while resolving Ruff RUF012.Source: Linters/SAST tools
51-58: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftAdd an L3 regression test for the new hooks.
_drivealways exercises_run_and_validate_l2, so the separate L3 wiring forskip_goldenandcompare_outputsis untested. Add a focused stubbed L3 case covering both skip precedence and comparison dispatch.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/ut/py/test_scene_test_golden_hooks.py` around lines 51 - 58, Add a focused stubbed L3 regression test alongside _drive that exercises the L3 execution path, verifying skip_golden takes precedence and compare_outputs is dispatched correctly. Reuse the existing _build_chip_task_args and _build_config patches, configure the instance for level 3, and assert the relevant comparison behavior without touching device operations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/ut/py/test_scene_test_golden_hooks.py`:
- Around line 34-35: Annotate the mutable class-level configuration attributes
such as CALLABLE and CASES with typing.ClassVar in the affected test classes,
including the additional occurrences noted in the review. Keep these values as
class-level attributes and preserve their existing contents while resolving Ruff
RUF012.
- Around line 51-58: Add a focused stubbed L3 regression test alongside _drive
that exercises the L3 execution path, verifying skip_golden takes precedence and
compare_outputs is dispatched correctly. Reuse the existing
_build_chip_task_args and _build_config patches, configure the instance for
level 3, and assert the relevant comparison behavior without touching device
operations.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e742646e-7d29-4bac-970f-3000cc76c1b9
📒 Files selected for processing (4)
docs/testing.mdexamples/a2a3/tensormap_and_ringbuffer/merge_pipeline_barrier/test_merge_pipeline_barrier.pysimpler_setup/scene_test.pytests/ut/py/test_scene_test_golden_hooks.py
What
Scene tests compared every output against
compute_goldenwith a fixedtorch.allcloseat the classRTOL/ATOL. The only escape was the global--skip-goldenCLI flag, which is all-or-nothing across the whole run.Two shapes had no clean expression:
slot per SPMD block only defines the prefix it actually ran with — the host
cannot know that width up front.
merge_pipeline_barrierwanted todrop its
timingtensor from the comparison and resorted to monkey-patchingthe private
_compare_outputsthroughsys.modules.Change
CASES[*]["skip_golden"], defaulting to the new class attributeSKIP_GOLDEN(itselfFalse). True means the case has no host-computableexpected output;
compute_goldenis never called for it. The CLI flag stillforces it on for every case (benchmark mode). Applied on both the L2 and L3
run paths.
compare_outputs(self, test_args, golden_args, output_names, params)isnow the overridable comparison hook; the default delegates to the existing
_compare_outputs. Override it to compare a subset, apply a per-tensortolerance, or derive the valid extent from the output itself.
_compare_outputskeeps its signature — the fourprepared_callableteststhat import it directly are untouched.
merge_pipeline_barrieruses the override instead of patching moduleinternals.
docs/testing.mddocuments both hooks under a new "Output Validation"section, with the guidance to prefer an override to a skip (a self-describing
output still gets checked; a skipped case only proves the run didn't crash).
Why now
This is groundwork for making the SPMD grid width runtime-discovered rather
than pinned per case. Once a case no longer declares
block_dim, its goldeneither doesn't depend on the core count (paged attention, qwen — unchanged) or
must read the launch width out of the output. Both hooks are needed before that
rework can start, and they are independently useful today, so they land on
their own.
Verification
pytest tests/ut -m "not requires_hardware"test_scene_test_golden_hooks.pypytest examples tests/st --platform a2a3simpytest examples tests/st --platform a5simmerge_pipeline_barrieronboard a2a3 (task-submit)The migrated example doubles as end-to-end coverage of the override: its
timinggolden is all zeros while the run writes real counter values, so thedefault comparison would fail on that tensor. The case passing is proof the
override ran.