#9727·cupy

Possible missing synchronization in distributed arrays

Author: sebergCreated Feb 19, 2026Updated Sep 22, 2026
Labelscat:bugprio:medium

Description

Opening an issue, because I am not sure it is high priority and poking it for a bit, I couldn't tell where the issue may be.

The distributed_tests point to likely niche but possible missing synchronizations in the cupyx.distributed. It is possible that only the test itself have missing synchronizations, but it didn't really look like it to me.

To Reproduce

CUPY_TEST_GPU_LIMIT=2 pytest -n16 cupyx_tests/distributed_tests/

adding CUDA_LAUNCH_BLOCKING=1 makes these failures go away.

Example failures
========================================================================== test session starts ===========================================================================
platform linux -- Python 3.14.0, pytest-9.0.2, pluggy-1.6.0
rootdir: /home/sebastianb/forks/cupy
configfile: pyproject.toml
plugins: timeout-2.4.0, xdist-3.8.0, run-parallel-0.8.2, hypothesis-6.150.1
16 workers [522 items]    
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...................................................... [ 31%]
.........................................ssss.ssss..................................ss.sss..ss...sssss..ss...ssssssss.ssssssssssssss.ssss.ssssssssssssss.sss.sssss [ 62%]
s.s.sss.sss.s.s.sss.ssss.s.ss..s.s.s.ss...sssss.s.sssss.s.ss..sssss..ss.s.sss....s.sss.s.sssss...ss.sssss..ss.Fssssssssssss.s..sssss....s.sssssss..sssssss..ssssss [ 93%]
sss.sss..ssF..s.s.....F.F...........                                                                                                                               [100%]
================================================================================ FAILURES ================================================================================
____________________________________________ TestDistributedArray2Devices.test_mul_max_mul[shape2-index_map_a2-index_map_b2] _____________________________________________
[gw0] linux -- Python 3.14.0 /home/sebastianb/miniforge3/envs/cupy-dev/bin/python3.14

self = <test_array_nccl.TestDistributedArray2Devices object at 0x7df6e9e44190>, shape = (8, 8, 4), index_map_a = {1: [(slice(None, None, None),)]}
index_map_b = {0: [(slice(None, 4, None), slice(None, 4, None), slice(None, None, None)), (slice(None, 4, None), slice(4, None, None), slice(None, None, None))], 1: [(slice(4, None, None), slice(None, None, None), slice(None, None, None))]}

    @pytest.mark.parametrize(
        'shape, index_map_a, index_map_b',
        [(shape_dim2, _2d_mappings[0], _2d_mappings[1]),
         (shape_dim3, _3d_mappings[0], _3d_mappings[1]),
         (shape_dim3, index_map_only_1, _3d_mappings[1])])
    def test_mul_max_mul(self, shape, index_map_a, index_map_b):
>       super()._test_mul_max_mul(shape, index_map_a, index_map_b)

cupyx_tests/distributed_tests/test_array_nccl.py:439: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
cupyx_tests/distributed_tests/test_array_nccl.py:281: in _test_mul_max_mul
    testing.assert_array_equal(np_d, d_d)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

actual = array([[376298055, 564260580, 559640816, 304779020],
       [ 87132000, 300967201, 516718230, 621959100],
       [2239... 233018422],
       [ 12338649,  99858000,  85287744, 176320179],
       [ 25585560, 224305200, 156977760, 397278908]])
desired = array([[      376298055,       564260580,       559640816,
              304779020],
       [       87132000,       30...214400,
         34907291731305],
       [ 13091096383200, 110641961513200,  99188115264000,
        187520258540160]])
err_msg = '', verbose = True

    def assert_array_equal(
            actual, desired, err_msg='', verbose=True, *,
            strict=False, strides_check=False
    ):
        """Raises an AssertionError if two array_like objects are not equal.
    
        Args:
             x(numpy.ndarray or cupy.ndarray): The actual object to check.
             y(numpy.ndarray or cupy.ndarray): The desired, expected object.
             strides_check(bool): If ``True``, consistency of strides is also
                 checked.
             err_msg(str): The error message to be printed in case of failure.
             verbose(bool): If ``True``, the conflicting values
                 are appended to the error message.
             strict(bool): If ``True``, raise an AssertionError when either
                 the shape or the data type of the array_like objects does not
                 match. Requires NumPy version 1.24 or above.
    
        .. seealso:: :func:`numpy.testing.assert_array_equal`
        """
        if numpy.lib.NumpyVersion(numpy.__version__) >= '1.24.0':
>           numpy.testing.assert_array_equal(
                cupy.asnumpy(actual), cupy.asnumpy(desired), err_msg=err_msg,
                verbose=verbose, strict=strict,
            )
E           AssertionError: 
E           Arrays are not equal
E           
E           Mismatched elements: 16 / 32 (50%)
E           First 5 mismatches are at indices:
E            [4, 0]: 351503250 (ACTUAL), 75364941960000 (DESIRED)
E            [4, 1]: 321904044 (ACTUAL), 363551117239296 (DESIRED)
E            [4, 2]: 146984910 (ACTUAL), 93938996944000 (DESIRED)
E            [4, 3]: 364953903 (ACTUAL), 108196243069464 (DESIRED)
E            [5, 0]: 443632680 (ACTUAL), 343155313998000 (DESIRED)
E           Max absolute difference among violations: 363550795335252
E           Max relative difference among violations: 0.99999911
E            ACTUAL: array([[376298055, 564260580, 559640816, 304779020],
E                  [ 87132000, 300967201, 516718230, 621959100],
E                  [223974912, 423701136, 117039810, 595445760],...
E            DESIRED: array([[      376298055,       564260580,       559640816,
E                         304779020],
E                  [       87132000,       300967201,       516718230,...

../../../miniforge3/envs/cupy-dev/lib/python3.14/site-packages/cupy/testing/_array.py:123: AssertionError
_____________________________ TestDistributedArray2Devices.test_incompatible_chunk_shapes_resharded[mode1-shape2-index_map_a2-index_map_b2] ______________________________
[gw8] linux -- Python 3.14.0 /home/sebastianb/miniforge3/envs/cupy-dev/bin/python3.14

self = <test_array_nccl.TestDistributedArray2Devices object at 0x792d8474a120>, shape = (8, 8, 4), index_map_a = {1: [(slice(None, None, None),)]}
index_map_b = {0: [(slice(None, 4, None), slice(None, 4, None), slice(None, None, None)), (slice(None, 4, None), slice(4, None, None), slice(None, None, None))], 1: [(slice(4, None, None), slice(None, None, None), slice(None, None, None))]}
mode = <cupyx.distributed.array._modes._OpMode object at 0x792d84c8aad0>

    @pytest.mark.parametrize(
        'shape, index_map_a, index_map_b',
        [(shape_dim2, _2d_mappings[0], _2d_mappings[1]),
         (shape_dim3, _3d_mappings[0], _3d_mappings[1]),
         (shape_dim3, index_map_only_1, _3d_mappings[1])])
    @pytest.mark.parametrize('mode', [REPLICA, SUM, MAX])
    def test_incompatible_chunk_shapes_resharded(
            self, shape, index_map_a, index_map_b, mode):
>       super()._test_incompatible_chunk_shapes_resharded(
            shape, index_map_a, index_map_b, mode
        )

cupyx_tests/distributed_tests/test_array_nccl.py:395: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
cupyx_tests/distributed_tests/test_array_nccl.py:214: in _test_incompatible_chunk_shapes_resharded
    testing.assert_array_almost_equal(d_r, np_r)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

actual = array([[[ 1.        , -0.9899925 ,  0.96017029, -0.91113026],
        [ 0.84385396, -0.75968791,  0.66031671, -0.54772...  [-0.84860217,  0.76545285, -0.66698298,  0.55516345],
        [-0.43223231,  0.30065004, -0.16305026,  0.02218703]]])
desired = array([[[ 1.        , -0.9899925 ,  0.96017029, -0.91113026],
        [ 0.84385396, -0.75968791,  0.66031671, -0.54772...  [-0.84860217,  0.76545285, -0.66698298,  0.55516345],
        [-0.43223231,  0.30065004, -0.16305026,  0.02218703]]])
decimal = 6, err_msg = '', verbose = True

    def assert_array_almost_equal(
            actual, desired, decimal=6, err_msg='', verbose=True,
    ):
        """Raises an AssertionError if objects are not equal up to desired precision.
    
        Args:
             x(numpy.ndarray or cupy.ndarray): The actual object to check.
             y(numpy.ndarray or cupy.ndarray): The desired, expected object.
             decimal(int): Desired precision.
             err_msg(str): The error message to be printed in case of failure.
             verbose(bool): If ``True``, the conflicting
                 values are appended to the error message.
    
        .. seealso:: :func:`numpy.testing.assert_array_almost_equal`
        """  # NOQA
>       numpy.testing.assert_array_almost_equal(
            cupy.asnumpy(actual), cupy.asnumpy(desired), decimal=decimal,
            err_msg=err_msg, verbose=verbose,
        )
E       AssertionError: 
E       Arrays are not almost equal to 6 decimals
E       
E       Mismatched elements: 64 / 256 (25%)
E       First 5 mismatches are at indices:
E        [0, 4, 0]: -0.03979075993115771 (ACTUAL), -0.6401443394691997 (DESIRED)
E        [0, 4, 1]: 0.9251360931462582 (ACTUAL), 0.7421541968137826 (DESIRED)
E        [0, 4, 2]: -0.7301941571456378 (ACTUAL), -0.8293098328631502 (DESIRED)
E        [0, 4, 3]: -0.3174001160235298 (ACTUAL), 0.8998668269691937 (DESIRED)
E        [0, 5, 0]: 0.9943642655514137 (ACTUAL), -0.9524129804151563 (DESIRED)
E       Max absolute difference among violations: 1.9830734
E       Max relative difference among violations: 62.74688297
E        ACTUAL: array([[[ 1.      , -0.989992,  0.96017 , -0.91113 ],
E               [ 0.843854, -0.759688,  0.660317, -0.547729],
E               [ 0.424179, -0.292139,  0.154251, -0.013277],...
E        DESIRED: array([[[ 1.      , -0.989992,  0.96017 , -0.91113 ],
E               [ 0.843854, -0.759688,  0.660317, -0.547729],
E               [ 0.424179, -0.292139,  0.154251, -0.013277],...

../../../miniforge3/envs/cupy-dev/lib/python3.14/site-packages/cupy/testing/_array.py:66: AssertionError
------------------------------------------------------------------------- Captured stdout setup --------------------------------------------------------------------------
CUDA_VISIBLE_DEVICES=0,1
____________________________________________ TestDistributedArray2Devices.test_reshard[None-shape2-index_map_a2-index_map_b2] ____________________________________________
[gw6] linux -- Python 3.14.0 /home/sebastianb/miniforge3/envs/cupy-dev/bin/python3.14

self = <test_array_nccl.TestDistributedArray2Devices object at 0x74eeefb395e0>, shape = (8, 8, 4), index_map_a = {1: [(slice(None, None, None),)]}
index_map_b = {0: [(slice(None, 4, None), slice(None, 4, None), slice(None, None, None)), (slice(None, 4, None), slice(4, None, None), slice(None, None, None))], 1: [(slice(4, None, None), slice(None, None, None), slice(None, None, None))]}
mode = None

    @pytest.mark.parametrize(
        'shape, index_map_a, index_map_b',
        [(shape_dim2, _2d_mappings[0], _2d_mappings[1]),
         (shape_dim3, _3d_mappings[0], _3d_mappings[1]),
         (shape_dim3, index_map_only_1, _3d_mappings[1])])
    @pytest.mark.parametrize('mode', [REPLICA, SUM, MAX])
    def test_reshard(self, shape, index_map_a, index_map_b, mode):
>       super()._test_reshard(shape, index_map_a, index_map_b, mode)

cupyx_tests/distributed_tests/test_array_nccl.py:385: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
cupyx_tests/distributed_tests/test_array_nccl.py:193: in _test_reshard
    testing.assert_array_equal(d_b, np_a)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

actual = array([[[  0,   1,   2,   3],
        [  4,   5,   6,   7],
        [  8,   9,  10,  11],
        [ 12,  13,  14,  15]...41, 242, 243],
        [244, 245, 246, 247],
        [248, 249, 250, 251],
        [252, 253, 254, 255]]], dtype=int64)
desired = array([[[  0,   1,   2,   3],
        [  4,   5,   6,   7],
        [  8,   9,  10,  11],
        [ 12,  13,  14,  15]...41, 242, 243],
        [244, 245, 246, 247],
        [248, 249, 250, 251],
        [252, 253, 254, 255]]], dtype=int64)
err_msg = '', verbose = True

    def assert_array_equal(
            actual, desired, err_msg='', verbose=True, *,
            strict=False, strides_check=False
    ):
        """Raises an AssertionError if two array_like objects are not equal.
    
        Args:
             x(numpy.ndarray or cupy.ndarray): The actual object to check.
             y(numpy.ndarray or cupy.ndarray): The desired, expected object.
             strides_check(bool): If ``True``, consistency of strides is also
                 checked.
             err_msg(str): The error message to be printed in case of failure.
             verbose(bool): If ``True``, the conflicting values
                 are appended to the error message.
             strict(bool): If ``True``, raise an AssertionError when either
                 the shape or the data type of the array_like objects does not
                 match. Requires NumPy version 1.24 or above.
    
        .. seealso:: :func:`numpy.testing.assert_array_equal`
        """
        if numpy.lib.NumpyVersion(numpy.__version__) >= '1.24.0':
>           numpy.testing.assert_array_equal(
                cupy.asnumpy(actual), cupy.asnumpy(desired), err_msg=err_msg,
                verbose=verbose, strict=strict,
            )
E           AssertionError: 
E           Arrays are not equal
E           
E           Mismatched elements: 64 / 256 (25%)
E           First 5 mismatches are at indices:
E            [0, 4, 0]: 128 (ACTUAL), 16 (DESIRED)
E            [0, 4, 1]: 129 (ACTUAL), 17 (DESIRED)
E            [0, 4, 2]: 130 (ACTUAL), 18 (DESIRED)
E            [0, 4, 3]: 131 (ACTUAL), 19 (DESIRED)
E            [0, 5, 0]: 132 (ACTUAL), 20 (DESIRED)
E           Max absolute difference among violations: 112
E           Max relative difference among violations: 7.
E            ACTUAL: array([[[  0,   1,   2,   3],
E                   [  4,   5,   6,   7],
E                   [  8,   9,  10,  11],...
E            DESIRED: array([[[  0,   1,   2,   3],
E                   [  4,   5,   6,   7],
E                   [  8,   9,  10,  11],...

../../../miniforge3/envs/cupy-dev/lib/python3.14/site-packages/cupy/testing/_array.py:123: AssertionError
______________________________ TestDistributedArray2Devices.test_incompatible_chunk_shapes_resharded[None-shape2-index_map_a2-index_map_b2] ______________________________
[gw7] linux -- Python 3.14.0 /home/sebastianb/miniforge3/envs/cupy-dev/bin/python3.14

self = <test_array_nccl.TestDistributedArray2Devices object at 0x799890831e50>, shape = (8, 8, 4), index_map_a = {1: [(slice(None, None, None),)]}
index_map_b = {0: [(slice(None, 4, None), slice(None, 4, None), slice(None, None, None)), (slice(None, 4, None), slice(4, None, None), slice(None, None, None))], 1: [(slice(4, None, None), slice(None, None, None), slice(None, None, None))]}
mode = None

    @pytest.mark.parametrize(
        'shape, index_map_a, index_map_b',
        [(shape_dim2, _2d_mappings[0], _2d_mappings[1]),
         (shape_dim3, _3d_mappings[0], _3d_mappings[1]),
         (shape_dim3, index_map_only_1, _3d_mappings[1])])
    @pytest.mark.parametrize('mode', [REPLICA, SUM, MAX])
    def test_incompatible_chunk_shapes_resharded(
            self, shape, index_map_a, index_map_b, mode):
>       super()._test_incompatible_chunk_shapes_resharded(
            shape, index_map_a, index_map_b, mode
        )

cupyx_tests/distributed_tests/test_array_nccl.py:395: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
cupyx_tests/distributed_tests/test_array_nccl.py:214: in _test_incompatible_chunk_shapes_resharded
    testing.assert_array_almost_equal(d_r, np_r)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

actual = array([[[ 0.74803752, -0.83420674,  0.9036793 , -0.95506471],
        [ 0.9873345 , -0.99984277,  0.99233919, -0.96497...  [-0.84860217,  0.76545285, -0.66698298,  0.55516345],
        [-0.43223231,  0.30065004, -0.16305026,  0.02218703]]])
desired = array([[[ 1.        , -0.9899925 ,  0.96017029, -0.91113026],
        [ 0.84385396, -0.75968791,  0.66031671, -0.54772...  [-0.84860217,  0.76545285, -0.66698298,  0.55516345],
        [-0.43223231,  0.30065004, -0.16305026,  0.02218703]]])
decimal = 6, err_msg = '', verbose = True

    def assert_array_almost_equal(
            actual, desired, decimal=6, err_msg='', verbose=True,
    ):
        """Raises an AssertionError if objects are not equal up to desired precision.
    
        Args:
             x(numpy.ndarray or cupy.ndarray): The actual object to check.
             y(numpy.ndarray or cupy.ndarray): The desired, expected object.
             decimal(int): Desired precision.
             err_msg(str): The error message to be printed in case of failure.
             verbose(bool): If ``True``, the conflicting
                 values are appended to the error message.
    
        .. seealso:: :func:`numpy.testing.assert_array_almost_equal`
        """  # NOQA
>       numpy.testing.assert_array_almost_equal(
            cupy.asnumpy(actual), cupy.asnumpy(desired), decimal=decimal,
            err_msg=err_msg, verbose=verbose,
        )
E       AssertionError: 
E       Arrays are not almost equal to 6 decimals
E       
E       Mismatched elements: 64 / 256 (25%)
E       First 5 mismatches are at indices:
E        [0, 0, 0]: 0.7480375245348201 (ACTUAL), 1.0 (DESIRED)
E        [0, 0, 1]: -0.8342067377267572 (ACTUAL), -0.9899924966004454 (DESIRED)
E        [0, 0, 2]: 0.9036792973912307 (ACTUAL), 0.960170286650366 (DESIRED)
E        [0, 0, 3]: -0.9550647097742044 (ACTUAL), -0.9111302618846769 (DESIRED)
E        [0, 1, 0]: 0.9873344954974584 (ACTUAL), 0.8438539587324921 (DESIRED)
E       Max absolute difference among violations: 1.99385964
E       Max relative difference among violations: 49.73000433
E        ACTUAL: array([[[ 0.748038, -0.834207,  0.903679, -0.955065],
E               [ 0.987334, -0.999843,  0.992339, -0.964974],
E               [ 0.918295, -0.853236,  0.771099, -0.673529],...
E        DESIRED: array([[[ 1.      , -0.989992,  0.96017 , -0.91113 ],
E               [ 0.843854, -0.759688,  0.660317, -0.547729],
E               [ 0.424179, -0.292139,  0.154251, -0.013277],...

../../../miniforge3/envs/cupy-dev/lib/python3.14/site-packages/cupy/testing/_array.py:66: AssertionError
======================================================================== short test summary info =========================================================================
FAILED cupyx_tests/distributed_tests/test_array_no_nccl.py::TestDistributedArray2Devices::test_mul_max_mul[shape2-index_map_a2-index_map_b2] - AssertionError: 
FAILED cupyx_tests/distributed_tests/test_array_nccl.py::TestDistributedArray2Devices::test_incompatible_chunk_shapes_resharded[mode1-shape2-index_m