Skip to content

Tune tolerance in matvec test and disable large dim in matmul test - #2912

Merged
antonwolfy merged 3 commits into
masterfrom
relax-tol-in-matvec-test
May 14, 2026
Merged

antonwolfy merged 3 commits into
masterfrom
relax-tol-in-matvec-test

Conversation

@antonwolfy

@antonwolfy antonwolfy commented May 12, 2026

Copy link
Copy Markdown
Contributor

Few tests are failing with the latest blas libs and numpy:

  FAILED test_product.py::TestMatmul::test_strided1[-2-float32] - AssertionError: 
  Not equal to tolerance rtol=1.6e-05, atol=1.6e-05
  
  Mismatched elements: 1 / 10000 (0.01%)
  Mismatch at index:
   [6, 5, 4, 8]: 0.13449859619140625 (ACTUAL), 0.13451732695102692 (DESIRED)
  Max absolute difference among violations: 1.873076e-05
  Max relative difference among violations: 0.00013924
   ACTUAL: array([[[[ 9.825830e+01,  8.411874e+01,  2.118525e+02, ...,
            -1.437696e+02, -1.788609e+00,  3.740148e+01],
           [ 8.804939e+01, -2.840893e+01, -1.463431e+02, ...,...
   DESIRED: array([[[[ 9.825830e+01,  8.411874e+01,  2.118525e+02, ...,
            -1.437696e+02, -1.788605e+00,  3.740148e+01],
           [ 8.804940e+01, -2.840893e+01, -1.463431e+02, ...,...
  FAILED test_product.py::TestMatvec::test_axes[axes0] - AssertionError: 
  Not equal to tolerance rtol=8e-15, atol=8e-15
  
  Mismatched elements: 1 / 96 (1.04%)
  Mismatch at index:
   [0, 0, 0, 1]: 0.36551382063033344 (ACTUAL), 0.36551382063031923 (DESIRED)
  Max absolute difference among violations: 1.42108547e-14
  Max relative difference among violations: 3.88791173e-14
   ACTUAL: array([[[[  17.130334,    0.365514,  -16.568001],
           [  52.87157 ,  -75.25945 , -105.961006]],
  ...
   DESIRED: array([[[[  17.130334,    0.365514,  -16.568001],
           [  52.87157 ,  -75.25945 , -105.961006]],
  ...
  FAILED test_product.py::TestMatvec::test_axes[axes1] - AssertionError: 
  Not equal to tolerance rtol=8e-15, atol=8e-15
  
  Mismatched elements: 1 / 96 (1.04%)
  Mismatch at index:
   [0, 0, 0, 1]: 0.36551382063033344 (ACTUAL), 0.36551382063031923 (DESIRED)
  Max absolute difference among violations: 1.42108547e-14
  Max relative difference among violations: 3.88791173e-14
   ACTUAL: array([[[[  17.130334,    0.365514,  -16.568001],
           [  52.87157 ,  -75.25945 , -105.961006]],
  ...
   DESIRED: array([[[[  17.130334,    0.365514,  -16.568001],
           [  52.87157 ,  -75.25945 , -105.961006]],

Disable the tests temporary, once the issue is identified and reported.

The issue is only visible when running tests through GH workflow, but passing locally within the same env and with OpenCL:CPU device.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

@antonwolfy antonwolfy added this to the 0.21.0 release milestone May 12, 2026
@antonwolfy antonwolfy self-assigned this May 12, 2026
@github-actions

github-actions Bot commented May 12, 2026

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/index.html

@coveralls

coveralls commented May 12, 2026

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 78.441% (-0.003%) from 78.444% — relax-tol-in-matvec-test into master

@github-actions

github-actions Bot commented May 12, 2026

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.21.0dev0=py313h509198e_20 ran successfully.
Passed: 1356
Failed: 4
Skipped: 16

@antonwolfy
antonwolfy force-pushed the relax-tol-in-matvec-test branch from 7244ba3 to cf5901c Compare May 12, 2026 02:37
@antonwolfy antonwolfy changed the title Tune tolerance in matvec test Tune tolerance in matvec test and disable large dim in matmul test May 13, 2026
@antonwolfy
antonwolfy marked this pull request as ready for review May 14, 2026 01:36
@ndgrigorian

Copy link
Copy Markdown
Collaborator

@antonwolfy
on replicating it locally, have you tried running with
CL_CONFIG_CPU_TARGET_ARCH=corei7-avx in local environments on CPU, or otherwise setting CL_CONFIG_CPU_TARGET_ARCH to other values?

This has worked for me in the past to replicate opencl:cpu issues I otherwise couldn't. I guess because the CPU architectures can be relevant to the implementations, and are different in the CI runners.

@ndgrigorian ndgrigorian left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

other than small point about investigating this LGTM

@antonwolfy

Copy link
Copy Markdown
Contributor Author

CL_CONFIG_CPU_TARGET_ARCH=corei7-avx

we have the tests passing with older BLAS, I'd assume it's more probably NumPy behavior changed..

@antonwolfy
antonwolfy merged commit 53dd6d1 into master May 14, 2026
74 of 75 checks passed
@antonwolfy
antonwolfy deleted the relax-tol-in-matvec-test branch May 14, 2026 21:55
github-actions Bot added a commit that referenced this pull request May 14, 2026
…2912)

Few tests are failing with the latest blas libs and numpy:
```bash
  FAILED test_product.py::TestMatmul::test_strided1[-2-float32] - AssertionError:
  Not equal to tolerance rtol=1.6e-05, atol=1.6e-05

  Mismatched elements: 1 / 10000 (0.01%)
  Mismatch at index:
   [6, 5, 4, 8]: 0.13449859619140625 (ACTUAL), 0.13451732695102692 (DESIRED)
  Max absolute difference among violations: 1.873076e-05
  Max relative difference among violations: 0.00013924
   ACTUAL: array([[[[ 9.825830e+01,  8.411874e+01,  2.118525e+02, ...,
            -1.437696e+02, -1.788609e+00,  3.740148e+01],
           [ 8.804939e+01, -2.840893e+01, -1.463431e+02, ...,...
   DESIRED: array([[[[ 9.825830e+01,  8.411874e+01,  2.118525e+02, ...,
            -1.437696e+02, -1.788605e+00,  3.740148e+01],
           [ 8.804940e+01, -2.840893e+01, -1.463431e+02, ...,...
  FAILED test_product.py::TestMatvec::test_axes[axes0] - AssertionError:
  Not equal to tolerance rtol=8e-15, atol=8e-15

  Mismatched elements: 1 / 96 (1.04%)
  Mismatch at index:
   [0, 0, 0, 1]: 0.36551382063033344 (ACTUAL), 0.36551382063031923 (DESIRED)
  Max absolute difference among violations: 1.42108547e-14
  Max relative difference among violations: 3.88791173e-14
   ACTUAL: array([[[[  17.130334,    0.365514,  -16.568001],
           [  52.87157 ,  -75.25945 , -105.961006]],
  ...
   DESIRED: array([[[[  17.130334,    0.365514,  -16.568001],
           [  52.87157 ,  -75.25945 , -105.961006]],
  ...
  FAILED test_product.py::TestMatvec::test_axes[axes1] - AssertionError:
  Not equal to tolerance rtol=8e-15, atol=8e-15

  Mismatched elements: 1 / 96 (1.04%)
  Mismatch at index:
   [0, 0, 0, 1]: 0.36551382063033344 (ACTUAL), 0.36551382063031923 (DESIRED)
  Max absolute difference among violations: 1.42108547e-14
  Max relative difference among violations: 3.88791173e-14
   ACTUAL: array([[[[  17.130334,    0.365514,  -16.568001],
           [  52.87157 ,  -75.25945 , -105.961006]],
  ...
   DESIRED: array([[[[  17.130334,    0.365514,  -16.568001],
           [  52.87157 ,  -75.25945 , -105.961006]],
```
Disable the tests temporary, once the issue is identified and reported.

The issue is only visible when running tests through GH workflow, but
passing locally within the same env and with OpenCL:CPU device. 53dd6d1
@ndgrigorian

ndgrigorian commented May 14, 2026

Copy link
Copy Markdown
Collaborator

CL_CONFIG_CPU_TARGET_ARCH=corei7-avx

we have the tests passing with older BLAS, I'd assume it's more probably NumPy behavior changed..

probably, but you said, it passes locally with the same env, no? It may be that it's only an issue on some CPUs/architectures (with correctness of the calls, that is)

antonwolfy added a commit that referenced this pull request Jul 15, 2026
github-actions Bot added a commit that referenced this pull request Jul 15, 2026
antonwolfy added a commit that referenced this pull request Jul 15, 2026
…test

The revert of gh-2912 removed the widened tolerance on
TestMatvec::test_axes, which reintroduced a CI failure on ubuntu-latest:
dpnp computes matvec via oneMKL gemm_batch while NumPy uses OpenBLAS
gemv, so the summation order differs and the float64 result deviates at
the noise floor (~1.4e-14), exceeding the default 8e-15 tolerance.

Restore factor=40 on test_axes (with an explanatory comment) while
keeping the rest of the revert, i.e. re-enabling dim=4 in
TestMatmul::test_strided1, whose factor=16 tolerance already absorbs any
cross-BLAS discrepancy.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
github-actions Bot added a commit that referenced this pull request Jul 15, 2026
antonwolfy added a commit that referenced this pull request Jul 16, 2026
Re-enabling dim=4 in TestMatmul::test_strided1 reintroduced the CI
failure gh-2912 had worked around by skipping it: for float32 the
strided matmul deviates by ~1.87e-5, just above the factor=16 bound
(~1.81e-5). The cause is benign cross-BLAS non-associativity -- dpnp
copies the strided input to c-contiguous and runs oneMKL gemm_batch,
while NumPy uses OpenBLAS, so the length-20 float32 contraction
accumulates in a different order.

Bump the tolerance to factor=24 (pass-bound ~2.27e-5) for float32 only;
integer input is compared exactly, so the factor does not affect it.
This keeps dim=4 covered without masking real regressions in the exact
path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
antonwolfy added a commit that referenced this pull request Jul 16, 2026
antonwolfy added a commit that referenced this pull request Jul 23, 2026
antonwolfy added a commit that referenced this pull request Jul 29, 2026
antonwolfy added a commit that referenced this pull request Jul 29, 2026
…ces (#2949)

## Summary

gh-2912 introduced two temporary test workarounds after a CI failure on
`ubuntu-latest`:
- widened the tolerance on `TestMatvec::test_axes` to `factor=40`;
- disabled the `dim=4` iteration in `TestMatmul::test_strided1`.

Both failures share the same benign root cause, so this PR re-enables
the disabled coverage and replaces the ad-hoc mitigations with
documented, dtype-aware tolerances:

- **`test_axes`** (matvec, float64) — keeps `factor=40`. dpnp computes
`matvec` via oneMKL `gemm_batch` while NumPy uses OpenBLAS `gemv`; the
summation order differs and the float64 result deviates at the noise
floor (~1.4e-14), which exceeds the default `8e-15` tolerance.
- **`test_strided1`** (matmul) — re-enables `dim=4`. dpnp copies the
strided input to c-contiguous and runs it through oneMKL `gemm_batch`,
again against NumPy's OpenBLAS. For float32, the length-20 contraction
deviates by ~1.87e-5, just above the old `factor=16` bound (~1.81e-5),
so the tolerance is bumped to `factor=24` **for float32 only**
(pass-bound ~2.27e-5). Integer input is compared exactly and is
unaffected.

## Root cause

Neither discrepancy is a dpnp correctness bug. Both are expected
floating-point non-associativity between two different BLAS backends
(oneMKL vs OpenBLAS), surfaced when the conda-forge NumPy in CI advanced
its bundled OpenBLAS. There is nothing to fix upstream, so documented
tolerances are the correct handling and let us keep full test coverage
(including `dim=4`).
github-actions Bot added a commit that referenced this pull request Jul 29, 2026
…ces (#2949)

## Summary

gh-2912 introduced two temporary test workarounds after a CI failure on
`ubuntu-latest`:
- widened the tolerance on `TestMatvec::test_axes` to `factor=40`;
- disabled the `dim=4` iteration in `TestMatmul::test_strided1`.

Both failures share the same benign root cause, so this PR re-enables
the disabled coverage and replaces the ad-hoc mitigations with
documented, dtype-aware tolerances:

- **`test_axes`** (matvec, float64) — keeps `factor=40`. dpnp computes
`matvec` via oneMKL `gemm_batch` while NumPy uses OpenBLAS `gemv`; the
summation order differs and the float64 result deviates at the noise
floor (~1.4e-14), which exceeds the default `8e-15` tolerance.
- **`test_strided1`** (matmul) — re-enables `dim=4`. dpnp copies the
strided input to c-contiguous and runs it through oneMKL `gemm_batch`,
again against NumPy's OpenBLAS. For float32, the length-20 contraction
deviates by ~1.87e-5, just above the old `factor=16` bound (~1.81e-5),
so the tolerance is bumped to `factor=24` **for float32 only**
(pass-bound ~2.27e-5). Integer input is compared exactly and is
unaffected.

## Root cause

Neither discrepancy is a dpnp correctness bug. Both are expected
floating-point non-associativity between two different BLAS backends
(oneMKL vs OpenBLAS), surfaced when the conda-forge NumPy in CI advanced
its bundled OpenBLAS. There is nothing to fix upstream, so documented
tolerances are the correct handling and let us keep full test coverage
(including `dim=4`). 9a16078
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants