Skip to content

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

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

N0AHZACH wants to merge 6 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!

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

Labels

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

2 participants