Skip to content

Fix histc(out=) to reject mismatched out dtype instead of silent cast - #5380

Open
N0AHZACH wants to merge 12 commits into
intel:mainfrom
N0AHZACH:fix-5237-histc-out-dtype
Open

N0AHZACH wants to merge 12 commits into
intel:mainfrom
N0AHZACH:fix-5237-histc-out-dtype

Conversation

@N0AHZACH

Copy link
Copy Markdown

Fixes #5237.

_histc_out_xpu computed the histogram in the input dtype via _histc_xpu
and then did resize_output + result.copy_(ret). copy_ casts silently,
so a float64 histogram written into an int64 out= was truncated with no
error. CPU rejects the same call in histogramdd_prepare_out
(aten/src/ATen/native/Histogram.cpp:132), so this was a CPU-vs-XPU
argument-validation divergence.

Changes:

  • src/ATen/native/xpu/SummaryOps.cpp: add the CPU-matching TORCH_CHECK
    before resize_output so a rejected call leaves the caller tensor
    untouched. Message text matches CPU verbatim and matches upstream
    Fix histc(out=) dtype validation mismatch between CPU and CUDA pytorch/pytorch#196100 for CUDA.
  • test/xpu/xpu_test_utils.py: de-scope tuple device_type=("cuda", "xpu")
    xfails gated on _cuda_xfail_xpu_pass by dropping only xpu from the
    scope. Without this the fixed test reports an unexpected success.
  • test/xpu/skip_list_common.py: remove test_out_histc_xpu_float32.
  • test/regressions/test_histc.py: regression coverage for mismatched
    out= rejection and matching-dtype success.

This does not depend on pytorch/pytorch#196100 landing and does not
conflict with it.

@github-actions github-actions Bot added disable_e2e Disable all e2e test jobs for the PR disable_distributed Disable distributed UT test jobs for the PR labels Sep 15, 2026
_histc_out_xpu computed into a fresh tensor of the input dtype and then
did result.copy_(ret). copy_ converts, so a float64 histogram written
into an int64 out= was silently truncated. CPU rejects the same call in
histogramdd_prepare_out, which the XPU out variant does not go through.

Add the CPU-matching TORCH_CHECK before resize_output so a rejected
call leaves the caller tensor untouched. Remove test_out_histc from the
skip list. De-scope the tuple device_type xfail in align_db_decorators
so the now-passing test does not report an unexpected success.

Fixes intel#5237.

Test Plan:
```
python -m py_compile test/regressions/test_histc.py test/xpu/xpu_test_utils.py test/xpu/skip_list_common.py
git diff --check
```
@N0AHZACH
N0AHZACH force-pushed the fix-5237-histc-out-dtype branch from 164c184 to ea4c1d7 Compare September 15, 2026 16:53
@N0AHZACH

Copy link
Copy Markdown
Author

@laifenxiawucha could you check this out so that I can get the CI rolling

@N0AHZACH

Copy link
Copy Markdown
Author

@laifenxiawucha can we start the CI on this specific commit - I do see a CI workflow has been run but idk where it ran tho.......been searching for a good 15 mins. Could we start the CI on this specific commit. I'm super sorry if its something stupid from my end

@laifenxiawucha

laifenxiawucha commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Hi @N0AHZACH .No worries at all — this is likely not an issue on your side. Since the PR is from a fork, some CI jobs may need maintainer approval before they can start. That’s probably why you can see a workflow run but not the full CI for this specific commit.

@N0AHZACH

Copy link
Copy Markdown
Author

Thanks @laifenxiawucha. I traced the four failing checks and they are stale, not caused by this change.

The linux-build and windows-build jobs fail before compiling anything (run 35192511198, commit ee3cc7cf):

  • Linux: python: can't open file '.../pytorch/.ci/manywheel/build_env_setup.py': [Errno 2] No such file or directory
  • Windows: ModuleNotFoundError: No module named 'build_env_setup'

Both come from PyTorch main relocating the wheel build scripts to .ci/wheel/linux and .ci/wheel/windows (pytorch/pytorch#189275). That breakage was fixed on main by #5417 and #5420, and the current head d355f901 already merges them (main at e9e0bfe4), so .github/scripts/build.sh and build_windows.py now use the new paths.

The change itself is already validated on hardware. In run 35050000160 (272fcabb), where the UT actually ran:

  • op_regression passed, including both new cases in test/regressions/test_histc.py (test_histc_out_rejects_mismatched_dtype, test_histc_out_matching_dtype_still_works)
  • test_out_histc_xpu_float32 ran and passed in op_ut (it is no longer skipped, and no longer reports an unexpected success against the upstream ('cuda', 'xpu') xfail)
  • the remaining op_ut entries in that run are unrelated (dynamo / flex-attention / fx / libtorchbind / env), none of them touch histc

Could you approve/start CI on d355f901? The run for that commit (35302042384) is still waiting on maintainer approval. Thanks!

@N0AHZACH

Copy link
Copy Markdown
Author

can we get a CI running on this please

@BBBela BBBela left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR will make the test_histc_out_dtype test to fail with Unexpected success - that should be fixed by removing the expectedFailureXPU from the upstream test directly, after this PR is merged - like in this PR pytorch/pytorch#199126

Comment thread test/xpu/xpu_test_utils.py Outdated
Comment on lines +1068 to +1073
elif (
isinstance(wrapper.device_type, (list, tuple))
and "xpu" in wrapper.device_type
and unittest.expectedFailure in wrapper.decorators
and (op_name, wrapper.test_name) in _cuda_xfail_xpu_pass
):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This elif: branch is not needed anymore. I suggest to remove it. The upstream ("cuda", "xpu") tuple was removed, so it is now dead code for the failing test case we are talking about.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh okay - gotchu. will push an update shortly.

Comment thread test/regressions/test_histc.py Outdated

@BBBela BBBela Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct me if I am wrong, but it looks like the upstream test test_histc_out_dtype added by you in test_reductions.py file already covers this regression scope - am I right? torch-xpu-ops repo currently imports the upstream test file and launches it, so it also launched this test_histc_out_dtype test. If my understanding above is correct, then I suggest to remove this new regression test from torch-xpu-ops and remove expectedFailureXPU from the upstream test_histc_out_dtype as a follow up PR. Because it now looks like unnecessary code duplication.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okayyyy - I shall fix that then....

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the line:

("histc", "test_out"),

should be removed in this PR also from _cuda_xfail_xpu_pass.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup will do.

@N0AHZACH

N0AHZACH commented Oct 2, 2026

Copy link
Copy Markdown
Author

I'm actually still working on this - personal life caught up to me a lil. But I am still working on this !

@BBBela

BBBela commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

No problem @N0AHZACH 😉
Please jest let me know when to re-review. I will also launch CI then.

The upstream ("cuda", "xpu") xfail for (histc, test_out) was removed in
pytorch/pytorch#196100, so the tuple de-scope branch added to
align_db_decorators never matches a wrapper, and ("histc", "test_out")
in _cuda_xfail_xpu_pass no longer refers to any DecorateInfo. Remove
both, per review.

Delete test/regressions/test_histc.py: upstream test_histc_out_dtype in
test/test_reductions.py covers the same mismatched out= dtype regression
and torch-xpu-ops runs it through test_reductions_xpu.py.

The fix itself is unchanged: the CPU-matching TORCH_CHECK in
_histc_out_xpu before resize_output, plus dropping
test_out_histc_xpu_float32 from the op_ut skip list.

Test Plan:
  python -m py_compile test/xpu/xpu_test_utils.py
  python -m flake8 test/xpu/xpu_test_utils.py
  clang-format --dry-run --Werror src/ATen/native/xpu/SummaryOps.cpp
  git diff --check
@N0AHZACH

N0AHZACH commented Oct 3, 2026

Copy link
Copy Markdown
Author

@BBBela I pushed some new updates sooo please CI?

@N0AHZACH

N0AHZACH commented Oct 3, 2026

Copy link
Copy Markdown
Author

No problem @N0AHZACH 😉 Please jest let me know when to re-review. I will also launch CI then.

The job hunts just got real. I got that insane reality check the open-source aint gonna help me keep the lights on😂. 1000+ rejections and a gizzilion more to go.

@BBBela

BBBela commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

@BBBela I pushed some new updates sooo please CI?

@N0AHZACH CI launched. Don't bother if there are some failing test cases. They can be sometimes flaky.
On the first look, the PR looks good to me now, but I will double check on Monday morning and then approve if CI is okay 😉

One think to do - please update the PR description as it is outdated after recent changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disable_auto Disable auto label workflow for PR disable_distributed Disable distributed UT test jobs for the PR disable_e2e Disable all e2e test jobs for the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[xpu-alignment] histc(out=) on XPU silently casts instead of rejecting a mismatched out dtype

3 participants