Skip to content

test_svm fails on i386 with scipy 1.13 #29633

Open

Description

@drew-parsons

Describe the bug

scipy 1.13 is triggering test failure in test_svc_ovr_tie_breaking[NuSVC] on i386 architecture.

The error can be seeing in debian CI tests, https://ci.debian.net/packages/s/scikit-learn/unstable/i386/
Full test log at https://ci.debian.net/packages/s/scikit-learn/unstable/i386/50043538/
or https://ci.debian.net/packages/s/scikit-learn/testing/i386/50043537/

Steps/Code to Reproduce

On an i386 system with scipy 1.13 installed

$ pytest-3 /usr/lib/python3/dist-packages/sklearn/svm/tests/test_svm.py -k test_svc_ovr_tie_breaking

Expected Results

test should pass

Actual Results

1333s _______________________ test_svc_ovr_tie_breaking[NuSVC] _______________________
1333s 
1333s SVCClass = <class 'sklearn.svm._classes.NuSVC'>
1333s 
1333s     @pytest.mark.parametrize("SVCClass", [svm.SVC, svm.NuSVC])
1333s     def test_svc_ovr_tie_breaking(SVCClass):
1333s         """Test if predict breaks ties in OVR mode.
1333s         Related issue: https://github.com/scikit-learn/scikit-learn/issues/8277
1333s         """
1333s         X, y = make_blobs(random_state=0, n_samples=20, n_features=2)
1333s     
1333s         xs = np.linspace(X[:, 0].min(), X[:, 0].max(), 100)
1333s         ys = np.linspace(X[:, 1].min(), X[:, 1].max(), 100)
1333s         xx, yy = np.meshgrid(xs, ys)
1333s     
1333s         common_params = dict(
1333s             kernel="rbf", gamma=1e6, random_state=42, decision_function_shape="ovr"
1333s         )
1333s         svm = SVCClass(
1333s             break_ties=False,
1333s             **common_params,
1333s         ).fit(X, y)
1333s         pred = svm.predict(np.c_[xx.ravel(), yy.ravel()])
1333s         dv = svm.decision_function(np.c_[xx.ravel(), yy.ravel()])
1333s >       assert not np.all(pred == np.argmax(dv, axis=1))
1333s E       assert not True
1333s E        +  where True = <function all at 0xf689d5e0>(array([1, 1, 1, ..., 1, 1, 1]) == array([1, 1, ..., dtype=int32)
1333s E        +    where <function all at 0xf689d5e0> = np.all
1333s E           
1333s E           Full diff:
1333s E           - array([1, 1, 1, ..., 1, 1, 1], dtype=int32)
1333s E           ?                              -------------
1333s E           + array([1, 1, 1, ..., 1, 1, 1]))
1333s 
1333s /usr/lib/python3/dist-packages/sklearn/svm/tests/test_svm.py:1225: AssertionError

Versions

$ python3 -c "import sklearn; sklearn.show_versions()"
# (on amd64, edited manually for i386)

System:
    python: 3.12.4 (main, Jul 15 2024, 12:17:32) [GCC 13.3.0]
executable: /usr/bin/python3
   machine: Linux-6.9.11-i386-i686-with-glibc2.39

Python dependencies:
      sklearn: 1.4.2
          pip: 24.1.1
   setuptools: 70.3.0
        numpy: 1.26.4
        scipy: 1.13.1
       Cython: 3.0.10
       pandas: 2.2.2+dfsg
   matplotlib: 3.8.3
       joblib: 1.3.2
threadpoolctl: 3.1.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
         prefix: libopenblas
       filepath: /usr/lib/i386-linux-gnu/openblas-pthread/libopenblasp-r0.3.27.so
        version: 0.3.27
threading_layer: pthreads
   architecture: Haswell
    num_threads: 8

       user_api: openmp
   internal_api: openmp
         prefix: libgomp
       filepath: /usr/lib/i386-linux-gnu/libgomp.so.1.0.0
        version: None

Activity

  1. added
    Needs Triage
    on Aug 6, 2024
  2. ogrisel commented on Aug 7, 2024

    @ogrisel
    Member

    This test might not be as platform agnostic as it intends to be. I suspect it could be improved by running:

        X, y = make_blobs(random_state=seed, n_samples=20, n_features=2)

    for different values of seed (e.g. in range(10)) until a dataset is found such that not np.all(pred == np.argmax(dv, axis=1)) when svm is fit with break_ties=False and then check that the equality holds for this same dataset when svm is refit with break_ties=True.

    And we would only raise AssertionError if we cannot find such a dataset after trying with 10 different values for seed.

  3. removed
    Needs Triage
    on Aug 7, 2024
  4. ogrisel commented on Aug 8, 2024

    @ogrisel
    Member

    For people interested in working on a fix, you should be able to reproduce the runtime environment that triggered the failure using docker and its builtin platform emulation:

    docker run --rm -ti -v `pwd`:/scikit-learn --platform linux/i386 debian
    

    People interested in fixing this issue should first check that they can reproduce the test failure after installing the main branch of scikit-learn in that environment and then attempt to refactor the test as suggested in #29633 (comment).

  5. lesteve commented on Sep 4, 2024

    @lesteve
    Member

    I can reproduce indeed with OpenBLAS in the 32bit Debian image. This was done as part of the debugging of an other 32bit OS issue, see #29771 (comment).

    When modifying the test to use global_random_seed, it fails for 37 out of 100 random seeds so it does appear like this test is not numerically stable (only for NuSVC).

    My sklearn.show_versions() for good measure:

    System:
        python: 3.12.5 (main, Aug 22 2024, 13:11:09) [GCC 14.2.0]
    executable: /venv/bin/python
       machine: Linux-6.10.7-arch1-1-x86_64-with-glibc2.40
    
    Python dependencies:
          sklearn: 1.6.dev0
              pip: 24.2
       setuptools: None
            numpy: 1.26.4
            scipy: 1.13.1
           Cython: 3.0.11
           pandas: 2.2.2+dfsg
       matplotlib: 3.8.3
           joblib: 1.4.2
    threadpoolctl: 3.5.0
    
    Built with OpenMP: True
    
    threadpoolctl info:
           user_api: blas
       internal_api: openblas
        num_threads: 12
             prefix: libopenblas
           filepath: /usr/lib/i386-linux-gnu/openblas-pthread/libopenblasp-r0.3.28.so
            version: 0.3.28
    threading_layer: pthreads
       architecture: Katmai
    
           user_api: openmp
       internal_api: openmp
        num_threads: 12
             prefix: libgomp
           filepath: /usr/lib/i386-linux-gnu/libgomp.so.1.0.0
            version: None
    
  6. lesteve commented on Sep 4, 2024

    @lesteve
    Member

    @drew-parsons you are probably a lot more familiar than us (scikit-learn maintainers) with the way Debian works, so my understanding of #29771 is that it is a Debian breaking change in 12.7. We starting seeing failing tests on 32bit OS and on CPU that have AVX512 (summary in #29771 (comment)) on August 31 which coincides with Debian 12.7 release.

    This seems like a breaking change in numpy but the Debian 12.7 changelog only mentions this which seems innocuous:

    numpy (1:1.24.2-1+deb12u1) bookworm; urgency=medium
     .
       * Declare conflict with python-numpy due to f2py (Closes: #1053649)
    
  7. drew-parsons commented on Sep 4, 2024

    @drew-parsons
    Author

    I could believe it if AVX512 is causing trouble on i386. It might not be directly related to the test_svm failure, but scipy uses pythran to build extensions with arch support, and pythran uses xsimd. I think the debian build daemons would be building i386 libraries without AVX512 support, and I could imagine that a discrepancy in AVX512 availability might give problems.

    In regards to BLAS support on debian, we build packages against generic BLAS (libblas-dev), and the common ABI means any optimised BLAS can be used at runtime. You noted in the PR#29771 that ATLAS is deprecated. I'd suggest OpenBLAS for standard BLAS use (there are multiple alternatives, with and without pthread or openmp threading).

  8. lesteve commented on Sep 4, 2024

    @lesteve
    Member

    Thanks @drew-parsons for your insights!

    My current understanding is that #29771 is a bit of a weird edge case, because we are testing inside a Docker 32bit image and the host CPU has AVX512 instructions. From what you are saying, I am guessing that it is very unlikely to have AVX512 instructions on a 32bit physical machine.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions