Fix DecorateInfo test-name matching for XPU overrides via register_test#3690
Fix DecorateInfo test-name matching for XPU overrides via register_test#3690gplutop7 wants to merge 12 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a name-mismatch problem where XPU test overrides assigned with Class.test_* = _test_* left the function's __name__ as _test_*, breaking DecorateInfo name matching. A new register_test() helper in test/xpu/xpu_test_utils.py wraps the override, rewrites __name__/__qualname__ to the public test_* name, and assigns it onto the target class. All affected XPU test modules are migrated to call this helper instead of doing the direct assignment.
Changes:
- Add
register_test(cls, func, *, name=None)helper that validates the callable, derives the public test name (optionally vianame=), and binds a properly named wrapper ontocls. - Replace
Class.test_* = _test_*patterns across many XPU test modules withregister_test(...)calls, including a couple of cases that pass an explicitname=to remap to a CUDA-style name. - Update imports in those test modules to also import
register_test.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/xpu/xpu_test_utils.py | Adds the register_test helper and imports functools. |
| test/xpu/test_type_promotion_xpu.py | Migrates two test overrides to register_test. |
| test/xpu/test_spectral_ops_xpu.py | Migrates two overrides, one with explicit name=; leaves _compare_xpu_cpu helper as direct assignment. |
| test/xpu/test_sort_and_select_xpu.py | Migrates test_sort_large_slice override. |
| test/xpu/test_optim_xpu.py | Migrates three optimizer test overrides. |
| test/xpu/test_numba_integration_xpu.py | Migrates three numba integration test overrides. |
| test/xpu/test_multiprocessing_xpu.py | Migrates four overrides, two using explicit name= for CUDA-name remap. |
| test/xpu/test_modules_xpu.py | Migrates test_multiple_device_transfer; keeps _test_gradients_helper direct assignment. |
| test/xpu/test_fx_xpu.py | Migrates three FX profiler test overrides. |
| test/xpu/test_foreach_xpu.py | Migrates five foreach test overrides. |
| test/xpu/test_distributions_xpu.py | Migrates six distributions test overrides. |
| test/xpu/test_basic_torch_np_xpu.py | Migrates test_f16_on_cuda override. |
| test/xpu/quantization/core/test_quantized_tensor_xpu.py | Partially migrates overrides; two direct assignments remain. |
| test/xpu/quantization/core/test_quantized_op_xpu.py | Migrates test_max_pool2d_pt2e. |
| test/xpu/nn/test_pooling_xpu.py | Migrates many pooling test overrides. |
| test/xpu/export/test_export_training_ir_to_run_decomp_xpu.py | Migrates test_exception override. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
test/xpu/xpu_test_utils.py:637
removeprefix("_")only strips a single leading underscore. If a caller passes a function such as__test_foo(or any name with more than one leading underscore), the resultingtest_namewill still begin with_, thestartswith("test")check will fail, and aValueErrorwill be raised. Either document the single-underscore expectation explicitly, or uselstrip("_")so any number of leading underscores are stripped before the prefix check.
test_name = (name or func.__name__).removeprefix("_")
if not test_name.startswith("test"):
raise ValueError(
f"Registered test name must start with 'test', got {test_name!r}"
)
2335cde to
8fad3d1
Compare
|
@copilot New UT failures detected in op_ut tests (4 total). Please check these new failures and analyze whether they are caused by the PR changes. Important: Do NOT update the plan in the PR description directly. Use reply comments to update the status. Job log: https://github.com/intel/torch-xpu-ops/actions/runs/25928824349 New failures:
Instructions:
|
After analyzing all 4 failures, they are not caused by this PR's changes:
This PR only changes: |
BBBela
left a comment
There was a problem hiding this comment.
The PR converts many test registrations that don't appear to have confirmed
DecorateInfo breakage.
Given the stated plan to port all XPU tests to PyTorch directly, it might be worth
scoping this PR to only the confirmed broken cases to keep the PR focused.
It looks like most of those changes are preventive rather than fixing existing problems - is that correct?
|
|
||
|
|
||
| ModuleTest.test_cuda = ModuleTest_test_xpu | ||
| def register_test(cls, func, *, name=None): |
There was a problem hiding this comment.
The current signature hides its contract — you have to read the body to know that the function name must start with test_ and that the target method name is derived from it. A three-argument form like that:
def register_test(original_test_class, original_test_func, overriden_func):would make the relationship explicit at the call site and removes all the name-derivation logic entirely.
What do you think?
There was a problem hiding this comment.
Thanks, I had the same thought initially.
A fully explicit 3-argument form makes the contract clearer, but it adds cost to the common case. Most overrides follow test* -> test_*, so requiring the target name everywhere would duplicate that repeatedly and make renames more fragile.
I also considered introducing the helper only for new/broken cases and leaving existing direct assignments as-is. But that would create two inconsistent patterns in the codebase: some tests using the helper, others the old direct assignment. That invites confusion for future contributors — which pattern should they copy? — and risks repeating the same fix in different ways.
So I went with a hybrid approach:
def register_test(cls, override_func, *, target_name=None):
This keeps the common case concise while requiring target_name for non-standard mappings. And I updated all existing registrations to use it consistently, so the pattern is now uniform across the test suite.
Does that resolve the scope concern? Do you see any risk in standardizing on this approach repo-wide?
There was a problem hiding this comment.
Thank you for response and clarification! 😃
I understand your point of view and it makes sense. I may even agree on the repo-wide scope to be consistent. However, regarding the function signature I am still not convinced, because the main argument for current approach is that it will make each registration several lines shorter, while making the contract less clear. So we trade the number of code lines at the cost of simplicity and clarity - at least that is my point of view.
But to be clear - those are my personal, subjective design preferences, so I am not going to block anything on this PR and I am not going to request any changes, I am just not approving something I do not fully agree with. So feel free to request others for review and proceed with this PR 😉
There was a problem hiding this comment.
Thanks a lot for the thoughtful feedback and for the constructive discussion.
You were absolutely right about the clarity tradeoff, and I decided to follow your suggestion. I updated the helper to the fully explicit 3-argument form so the contract is now clear at each call site.
I also migrated all registrations in this PR to match that explicit style (including non-standard mappings), so the pattern stays consistent repo-wide while keeping the interface unambiguous
|
@copilot New UT failures detected in op_ut tests (1 total). Please check these new failures and analyze whether they are caused by the PR changes. Important: Do NOT update the plan in the PR description directly. Use reply comments to update the status. Job log: https://github.com/intel/torch-xpu-ops/actions/runs/26033399176 New failures:
Instructions:
|
The failure in Evidence:
The failure is "Unexpected success" — meaning
That's correct — the majority of the conversions are preventive. The The trade-off considered: leaving confirmed-broken cases on the helper and the rest on the old pattern creates two inconsistent conventions in the codebase, making it unclear which pattern future contributors should follow. A uniform |
Fixes:
#1973
This PR fixes a mismatch between overridden XPU test function names and DecorateInfo name matching.
What changed: