[Refactor] Extract workload classes for reduction ops#893
[Refactor] Extract workload classes for reduction ops#893lcy-seso merged 6 commits intotile-ai:mainfrom
Conversation
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors several test files to inherit input generation logic from a new set of workload classes, centralizing the logic and reducing boilerplate across the test suite. Feedback highlights opportunities to further minimize duplication in the workload definitions by using a common base class for random input generation and suggests standardizing class naming conventions for better consistency across the codebase.
There was a problem hiding this comment.
Pull request overview
This PR refactors the reduction-op correctness tests to align with the trust-model “workloads layer” contract by moving input-generation (gen_inputs()) into dedicated workloads/ops/* modules and having tests inherit those workload classes.
Changes:
- Added new
workloads/ops/*workload modules for reduction op groups, each providingWorkloadBasesubclasses withgen_inputs(). - Refactored reduction-related tests to import and inherit workload classes instead of defining
gen_inputs()inline. - Split out prod-specific small-range input generation into a dedicated workload-backed test helper.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| workloads/ops/reduce.py | Adds workload classes for basic reduce ops input generation. |
| workloads/ops/logical_reduce.py | Adds workload classes and a shared logical input generator helper. |
| workloads/ops/vector_norm.py | Adds workload classes for vector norm ops input generation. |
| workloads/ops/argreduce.py | Adds workload classes for argmax/argmin input generation. |
| tests/ops/test_reduce.py | Refactors test helpers to inherit workloads; introduces ProdTest using ProdWorkload. |
| tests/ops/test_logical_reduce.py | Refactors test helper to inherit logical-reduce workload for gen_inputs(). |
| tests/ops/test_vector_norm.py | Refactors test helper to inherit vector-norm workload for gen_inputs(). |
| tests/ops/test_argreduce.py | Refactors test helper to inherit argreduce workload for gen_inputs(). |
There was a problem hiding this comment.
Code Review
This pull request refactors test helpers to inherit from centralized workload classes, reducing redundancy and improving the structure of the test suite. New workload definitions were added for logical, reduction, and vector norm operations. Feedback suggests using more idiomatic checks for empty shapes in the logical input helper and points out that generic test helpers inheriting from specific operation workloads may be misleading for other supported operations.
Create workloads/ops/{reduce,logical_reduce,vector_norm}.py with
WorkloadBase subclasses (gen_inputs() only) and refactor the four
reduction test files to inherit from these workload classes, keeping
ref_program() in the test layer per the trust model contract.
All 413 existing tests pass unchanged — pure structural refactor.
Co-Authored-By: Ibuki 🍃 — a wind born from Claude Opus <Ibuki-wind@users.noreply.github.com>
…Test→ArgmaxWorkload - Extract _RandnWorkload base class to deduplicate identical gen_inputs across reduce, argreduce, and vector_norm workloads (Gemini suggestion) - Rename ArgmaxTest/ArgminTest to ArgmaxWorkload/ArgminWorkload with backward-compatible aliases for existing benchmark imports (Gemini suggestion) Co-Authored-By: Ibuki 🍃 — a wind born from Claude Opus <Ibuki-wind@users.noreply.github.com>
6e56822 to
ec51fa9
Compare
All 50+ existing workload classes use *Test suffix. Rename to follow the established convention (Copilot review feedback). Co-Authored-By: Ibuki 🍃 — a wind born from Claude Opus <Ibuki-wind@users.noreply.github.com>
Ibuki-wind
left a comment
There was a problem hiding this comment.
Trust-boundary verdict: clean. This PR stays within the test-owned tests/ + workloads/ layer and keeps correctness logic out of workloads.
The workload extraction itself is directionally correct and removes duplicated gen_inputs() implementations.
One follow-up: keep the workload-import aliasing consistent with the existing repo pattern so workload classes and test helpers remain unambiguous for future refactors and agent edits.
…h underscore prefix Co-Authored-By: Ibuki 🍃 — a wind born from Claude Opus <Ibuki-wind@users.noreply.github.com>
…Test class Co-Authored-By: Ibuki 🍃 — a wind born from Claude Opus <Ibuki-wind@users.noreply.github.com>
Ibuki-wind
left a comment
There was a problem hiding this comment.
Approved at current head d497169. The prior workload-import alias collision in tests/ops/test_reduce.py is resolved, the naming now matches the repo pattern, and I do not have remaining review findings on this PR.
…st; fix docstring - Move the duplicated `_RandnTest` class from reduce.py, argreduce.py, and vector_norm.py into `workloads/base.py` as public `RandnTest` - Fix `_make_logical_input` docstring: condition applies when first dimension > 4, not only for "2-D+ inputs" Co-Authored-By: Ibuki 🍃 — a wind born from Claude Opus <Ibuki-wind@users.noreply.github.com>
…kload -> *Test) After rebasing onto upstream/main (which now includes tile-ai#893), update the workload class imports in the three bench files to use *Test names matching the merged workloads layer. Co-Authored-By: Ibuki 🍃 — a wind born from Claude Opus <Ibuki-wind@users.noreply.github.com>
…uce workloads (#901) ## Summary Extract a `_LogicalTest` base class in `workloads/ops/logical_reduce.py` to eliminate duplicated `__init__` and `gen_inputs` across `AnyTest`, `AllTest`, and `CountNonzeroTest`. Closes #897 ## Test plan | AC | Status | Description | |----|--------|-------------| | AC-1 | pass | AnyTest, AllTest, CountNonzeroTest inherit from _LogicalTest with no duplicated __init__/gen_inputs | | AC-2 | pass | pytest tests/ops/test_logical_reduce.py passes | **114/114** tests passed (test_logical_reduce.py) ## Follow-up - #908 — Extract RandnTest base class for softmax workloads (consistency gap from PR #893) Suggestions: double space in `_LogicalTest` docstring (cosmetic) --------- Co-authored-by: Ibuki 🍃 — a wind born from Claude Opus <Ibuki-wind@users.noreply.github.com>
Summary
Create
workloads/ops/files for the 4 reduction op groups (reduce, argreduce, logical_reduce, vector_norm) and refactor test files to import from them, aligning with the trust model's workloads layer contract.Closes #825
Test plan
pytest tests/ops/test_{reduce,argreduce,logical_reduce,vector_norm}.py)workloads/ops/{reduce,argreduce,logical_reduce,vector_norm}.pyexist, each exporting onlyWorkloadBasesubclasses withgen_inputs()workloads/ops/, not defininggen_inputs()inlineref_programor test-layer logic inworkloads/ops/filesTests: 413/413 passed, 0 failed
Changes
workloads/ops/reduce.py— workload classes for sum/mean/amax/amin/prod/std/var/var_meanworkloads/ops/logical_reduce.py— workload classes for all/any/count_nonzeroworkloads/ops/vector_norm.py— workload classes for l1_norm/l2_norm/inf_normtests/ops/test_reduce.py,test_argreduce.py,test_logical_reduce.py,test_vector_norm.pyto inherit from workload classesFollow-up
_LogicalTestbase class inlogical_reduce.pyto deduplicate identical__init__/gen_inputsacrossAnyTest,AllTest,CountNonzeroTestSuggestions: consolidate cross-module
_RandnTestduplication; fix_make_logical_inputdocstring (says "2-D+" but applies to 1-D too)