Repository navigation
Open
Labels
Description
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
ogrisel commentedon Aug 7, 2024
This test might not be as platform agnostic as it intends to be. I suspect it could be improved by running:
for different values of
seed(e.g. inrange(10)) until a dataset is found such thatnot np.all(pred == np.argmax(dv, axis=1))whensvmis fit withbreak_ties=Falseand then check that the equality holds for this same dataset whensvmis refit withbreak_ties=True.And we would only raise
AssertionErrorif we cannot find such a dataset after trying with 10 different values forseed.ogrisel commentedon Aug 8, 2024
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:
People interested in fixing this issue should first check that they can reproduce the test failure after installing the
mainbranch of scikit-learn in that environment and then attempt to refactor the test as suggested in #29633 (comment).lesteve commentedon Sep 4, 2024
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:lesteve commentedon Sep 4, 2024
@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:
drew-parsons commentedon Sep 4, 2024
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).
lesteve commentedon Sep 4, 2024
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.