Fix arange error type for fractional step with integer output on XPU#3701
Fix arange error type for fractional step with integer output on XPU#3701AKloniecki wants to merge 4 commits into
Conversation
When torch.arange is called with a fractional step (e.g., 0.5) and an integer output tensor, the step truncates to 0. The CUDA backend correctly raises ValueError via TORCH_CHECK_VALUE, but XPU was raising RuntimeError via TORCH_CHECK. Replace inline bounds checks with arange_check_bounds() (from RangeUtils.h) and add TORCH_CHECK_VALUE in the int64_t branch to match CUDA behavior. Fixes #3699 Signed-off-by: Artur Kłoniecki <arturx.kloniecki@intel.com>
There was a problem hiding this comment.
Pull request overview
Skill files read: .github/skills/xpu-ops-pr-review/SKILL.md.
This PR updates the XPU arange_out_xpu argument validation to better match CUDA semantics by centralizing bound checks in arange_check_bounds(...) and ensuring the integer-output fractional-step-to-zero case raises ValueError.
Changes:
- Added
#include <ATen/native/RangeUtils.h>and switched toarange_check_bounds(start, end, step)for bounds/sign/finite validation. - Added an
int64_t-specificTORCH_CHECK_VALUE(xstep != 0, "step must be nonzero")to match CUDA’s error type for fractional steps truncating to zero.
BBBela
left a comment
There was a problem hiding this comment.
I have the same concern as @pbielak regarding putting the xstart, xend, and xstep into the constexpr body where they are used. I would personally do a step further and move also the using accscalar_t alias into the if constexpr as it is also used only for those three variables - but it is not blocking in any case.
Beside that everything looks good!
|
@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/26033231815 New failures:
Instructions:
|
Agent-Logs-Url: https://github.com/intel/torch-xpu-ops/sessions/b20c84de-bfc4-446e-b55f-028f700c7dea Co-authored-by: chuanqi129 <13608516+chuanqi129@users.noreply.github.com>
Addressed in 3e68faf: I moved
I checked run |
Performance outliers, please check!
|
BBBela
left a comment
There was a problem hiding this comment.
Looks good to me in current shape!
Thanks!
|
@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/26056824947 New failures:
Instructions:
|
I checked run |
Summary
Fix
arange_out_xputo raiseValueError(instead ofRuntimeError) when a fractional step truncates to zero for an integer output tensor, matching the CUDA implementation.Changes
<ATen/native/RangeUtils.h>forarange_check_bounds.TORCH_CHECKcalls witharange_check_bounds(start, end, step)for consistent double-precision validation.TORCH_CHECK_VALUE(xstep != 0, "step must be nonzero")in theint64_tcode path (mirrorsRangeFactories.cu).Test
python -m pytest -sxv test_ops_xpu.py -k test_errors_arange_xpunow passes.Fixes #3699