def test_builder_to_backend_stress(
        self, compute_unit, backend, nbits, block_sizes, vector_size, sparse_ratio, lut_dtype
    ):
        """Use constexpr_lut_to_sparse op's value inference to check backends outputs."""
        indices_shape = (4, 8, 16, 8)
        indices_mask = np.random.choice(
            [0, 1], size=indices_shape, p=[sparse_ratio, 1.0 - sparse_ratio]
        ).astype(types.np_uint1_dtype)
        indices_nonzero_element_num = np.sum(indices_mask)
        indices_np_dtype = types.nptype_from_builtin(types.string_to_builtin(f"uint{nbits}"))
        indices_nonzero_data = np.random.randint(
            low=0, high=2**nbits, size=indices_nonzero_element_num
        ).astype(indices_np_dtype)

        lut_np_dtype = types.nptype_from_builtin(types.string_to_builtin(lut_dtype))
        lut_shape = _infer_lut_shape(indices_shape, block_sizes, nbits, vector_size)
        lut = np.random.rand(*lut_shape).astype(lut_np_dtype)
        vector_axis = 0 if vector_size > 1 else None

        def build(x):
            output_mask, output_nonzero_data = mb.constexpr_lut_to_sparse(
                indices_mask=indices_mask,
                indices_nonzero_data=indices_nonzero_data,
                lut=lut,
                vector_axis=vector_axis,
            )
            x, output_nonzero_data = promote_input_dtypes([x, output_nonzero_data])
            return mb.add(x=x, y=output_nonzero_data)

        output_shape = int(indices_nonzero_element_num * vector_size)
        x_val = np.ones(output_shape).astype(np.float32)
        input_placeholders = {"x": mb.placeholder(shape=x_val.shape)}
        expected_output = (
            constexpr_lut_to_sparse.decompress(
                indices_mask, indices_nonzero_data, lut, vector_axis
            )[1]
            + 1
        )

        run_compare_builder(
            build,
            input_placeholders,
            input_values={"x": x_val},
            expected_output_types=expected_output.shape + (types.fp32,),
            expected_outputs=expected_output,
            compute_unit=compute_unit,
            backend=backend,
        )
Use constexpr_lut_to_sparse op's value inference to check backends outputs.
coremltools/converters/mil/mil/ops/tests/iOS18/test_compression.py