[release/2.14] Distribution sampling/moment statistical assertion failures on XPU
- Dominant language
- Python
- Stars
- 113
- Forks
- 129
- Avg merge
- 5d 9h
- Merged PRs (30d)
- 112
Description
Cases:
op_ut,third_party.torch-xpu-ops.test.xpu.test_distributions_xpu.TestDistributionsXPU,test_cauchy_xpu
op_ut,third_party.torch-xpu-ops.test.xpu.test_distributions_xpu.TestDistributionsXPU,test_normal_xpu
op_ut,third_party.torch-xpu-ops.test.xpu.test_distributions_xpu.TestDistributionsXPU,test_logisticnormal_sample_xpu
op_ut,third_party.torch-xpu-ops.test.xpu.test_distributions_xpu.TestDistributionsXPU,test_multivariate_normal_moments_xpu
op_ut,third_party.torch-xpu-ops.test.xpu.test_distributions_xpu.TestDistributionsXPU,test_uniform_xpu
op_ut,third_party.torch-xpu-ops.test.xpu.test_distributions_xpu.TestDistributionsXPU,test_generalized_pareto_sample_xpu
op_ut,third_party.torch-xpu-ops.test.xpu.test_distributions_xpu.TestDistributionsXPU,test_studentT_sample_xpu
op_ut,third_party.torch-xpu-ops.test.xpu.test_distributions_xpu.TestDistributionsXPU,test_wishart_sample_xpu
op_ut,third_party.torch-xpu-ops.test.xpu.test_distributions_xpu.TestDistributionsXPU,test_exponential_xpu
op_ut,third_party.torch-xpu-ops.test.xpu.test_distributions_xpu.TestDistributionsXPU,test_halfcauchy_xpu
op_ut,third_party.torch-xpu-ops.test.xpu.test_distributions_xpu.TestDistributionsXPU,test_chi2_sample_xpu
op_ut,third_party.torch-xpu-ops.test.xpu.test_distributions_xpu.TestDistributionsXPU,test_wishart_moments_xpu
## Root Cause
Distribution sampling and moment-verification tests fail with `AssertionError` on XPU. The failures fall into two patterns:
1. **"Tensor-likes are not close"** — gradient or icdf/quantile comparisons show large absolute/relative differences (e.g., `scale.grad` mismatch of 64.5 in `test_cauchy_xpu`, moment mismatches in `test_wishart_moments_xpu`). All 25/25 elements mismatched in several tests, indicating a systematic numerical divergence rather than occasional precision loss.
2. **"sample() is biased"** — statistical hypothesis tests (Kolmogorov-Smirnov style) reject the null hypothesis that samples come from the expected distribution. Bias values narrowly exceed thresholds (e.g., `0.062 > 0.060` for GeneralizedPareto, `-0.059 > -0.061` for LogisticNormal), suggesting XPU's RNG or floating-point arithmetic produces sample statistics that deviate slightly from CPU/CUDA expectations.
Both patterns point to XPU numerical precision differences in distribution sampling operations and their gradients.
## Reproducer
For each affected test case, run individually:
```bash
source ~/.bashrc && cd third_party/torch-xpu-ops/test/xpu && python -m pytest -sxv test_distributions_xpu.py -k ""
```
## Representative Error
```
=================================== FAILURES ===================================
_____________________ TestDistributionsXPU.test_cauchy_xpu _____________________
Traceback (most recent call last):
File "/usr/lib/python3.12/unittest/case.py", line 58, in testPartExecutor
yield
File "/usr/lib/python3.12/unittest/case.py", line 634, in run
self._callTestMethod(testMethod)
File "/usr/lib/python3.12/unittest/case.py", line 589, in _callTestMethod
if method() is not None:
File "/home/gta/Projects/pytorch/torch/testing/_internal/common_utils.py", line 3591, in wrapper
method(*args, **kwargs)
File "/home/gta/Projects/pytorch/torch/testing/_internal/common_device_type.py", line 551, in instantiated_test
result = test(self, **param_kwargs)
File "/home/gta/Projects/pytorch/torch/testing/_internal/common_device_type.py", line 1637, in efail_fn
return fn(slf, *args, **kwargs)
File "/home/gta/Projects/pytorch/torch/testing/_internal/common_utils.py", line 2753, in wrapper
return fn(test_self, *args, **kwargs)
File "test/distributions/test_distributions.py", line 2363, in test_cauchy
self.assertEqual(scale.grad, eps)
File "/home/gta/Projects/pytorch/torch/testing/_internal/common_utils.py", line 4609, in assertEqual
raise error_metas.pop()[0].to_error(
AssertionError: Tensor-likes are not close!
Mismatched elements: 25 / 25 (100.0%)
Greatest absolute difference: 64.50811796602322 at index (3, 4) (up to 1e-07 allowed)
Greatest relative difference: 33.2504545757245 at index (3, 4) (up to 1e-07 allowed)
```
Contributor guide
Assessment
This issue has not been assessed yet.