Skip to content

Segfault in LinearSVR on master #11131

Closed
Closed

Description

@amueller

sklearn/tests/test_common.py::test_non_meta_estimators[LinearSVR-LinearSVR-check2214] Makefile:27: recipe for target 'test-code' failed

Linux-4.15.0-22-generic-x86_64-with-debian-buster-sid
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19)
[GCC 7.2.0]
NumPy 1.14.0
SciPy 1.0.0
Scikit-Learn 0.20.dev0
Cython version 0.27.3

Deterministic segfault :-/ I need to investigate
reproduce:

from sklearn.svm import LinearSVR
from sklearn.utils.estimator_checks import check_regressors_train

check_regressors_train("LinearSVR", LinearSVR(), readonly_memmap=True)

looks like that never worked.

Activity

  1. amueller commented on May 24, 2018

    @amueller
    MemberAuthor
    pytest sklearn/tests/test_common.py -v -k LinearSVR-LinearSVR-check2214   
    

    reproduces this. How can I find out which test that is? @rth @qinhanmin2014 ?

  2. amueller commented on May 24, 2018

    @amueller
    MemberAuthor

    Git bisect says #11063 is guilty

  3. amueller commented on May 24, 2018

    @amueller
    MemberAuthor

    svm/src/liblinear/linear.cpp
    2386├> model_->n_iter[0] =train_one(prob, param, &model_->w[0], 0, 0);

  4. amueller commented on May 24, 2018

    @amueller
    MemberAuthor

    It's LinearSVR-LinearSVR-check_regressors_train(readonly_memmap=True)

  5. amueller commented on May 24, 2018

    @amueller
    MemberAuthor

    lol git bisect is stupid on this... never mind...

  6. amueller commented on May 24, 2018

    @amueller
    MemberAuthor

    actual bisecting blames 9ea723f and
    @lesteve, which makes more sense....

  7. amueller commented on May 24, 2018

    @amueller
    MemberAuthor

    it's actually y being a memmap that's causing the problem....

  8. rth commented on May 24, 2018

    @rth
    Member

    Hmm, if LinearSVR segfaults with read-only memmaps it's strange that it does so only in this configuration but not in CI on master which should use a fairly similar version of dependencies. I'm almost using exactly those versions and it doesn't segfault..

  9. amueller commented on May 24, 2018

    @amueller
    MemberAuthor

    @glemaitre had the same issue.

  10. amueller commented on May 24, 2018

    @amueller
    MemberAuthor

    what cython and numpy are you using?

  11. glemaitre commented on May 24, 2018

    @glemaitre
    Member

    Hmm, if LinearSVR segfaults with read-only memmaps it's strange that it does so only in this configuration but not in CI on master which should use a fairly similar version of dependencies. I'm almost using exactly those versions and it doesn't segfault..

    Is it not a race condition on the same data or something like that which happen on faster computer.
    This cannot happen when running a single test actually.

  12. amueller commented on May 24, 2018

    @amueller
    MemberAuthor

    Actually, I don't entirely understand what happens with the memmap once it's converted to a C pointer. Can someone explain?

  13. glemaitre commented on May 24, 2018

    @glemaitre
    Member

    FYI: I have the same version than @amueller

  14. amueller commented on May 24, 2018

    @amueller
    MemberAuthor

    Also fails on

    ca-certificates           2018.03.07                    0  
    certifi                   2018.4.16                py36_0  
    cython                    0.26.1           py36h21c49d0_0  
    docutils                  0.14             py36hb0f60f5_0  
    intel-openmp              2018.0.0                      8  
    libedit                   3.1                  heed3624_0  
    libffi                    3.2.1                hd88cf55_4  
    libgcc-ng                 7.2.0                hdf63c60_3  
    libgfortran-ng            7.2.0                hdf63c60_3  
    libstdcxx-ng              7.2.0                hdf63c60_3  
    mkl                       2018.0.2                      1  
    mkl_fft                   1.0.1            py36h3010b51_0  
    mkl_random                1.0.1            py36h629b387_0  
    ncurses                   6.0                  h9df7e31_2  
    numpy                     1.14.2           py36hdbf6ddf_1  
    openssl                   1.0.2o               h20670df_0  
    pip                       10.0.1                   py36_0  
    python                    3.6.2               hca45abc_19  
    readline                  7.0                  ha6073c6_4  
    scipy                     1.0.0            py36hbf646e7_0  
    setuptools                39.1.0                   py36_0  
    sqlite                    3.23.1               he433501_0  
    tk                        8.6.7                hc745277_3  
    wheel                     0.31.1                   py36_0  
    xz                        5.2.4                h14c3975_4  
    zlib                      1.2.11               ha838bed_2  
    

    on my machine, which should be the same as travis?

  15. glemaitre commented on May 24, 2018

    @glemaitre
    Member

    on my machine, which should be the same as travis?

    DISTRIB="conda" PYTHON_VERSION="3.6.2" INSTALL_MKL="true"
    NUMPY_VERSION="1.14.2" SCIPY_VERSION="1.0.0" PANDAS_VERSION="0.20.3"
    CYTHON_VERSION="0.26.1" PYAMG_VERSION="3.3.2" PILLOW_VERSION="4.3.0"
    

    so yes. It is still really obscure to me what is happening.

  16. ogrisel commented on May 25, 2018

    @ogrisel
    Member

    I do not reproduce the segfault (current master, cython 0.28.2).

  17. ogrisel commented on May 25, 2018

    @ogrisel
    Member

    I cannot reproduce either with cython 0.26.1. We probably have to make a minimal reproduction case in a standalone python script and valgrind it.

  18. lesteve commented on May 25, 2018

    @lesteve
    Member

    This seems like a duplicate of #10667. As noted in
    #10667 (comment), I managed to get rid of this problem by installing gcc_linux-64, gxx_linux-64 with conda.

    @rth had the same issue and using the gcc/g++ from conda fixed it for him too.

  19. ogrisel commented on May 25, 2018

    @ogrisel
    Member

    I am using gcc (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609 (and cannot reproduce).

  20. glemaitre commented on May 25, 2018

    @glemaitre
    Member

    The GDB back trace for the segfault while running the test with pytest:

    Program received signal SIGSEGV, Segmentation fault.
    0x00007fffdabcce7a in train_one (prob=prob@entry=0x55555659f4f0, 
        param=param@entry=0x5555569d0180, w=w@entry=0x555556a38870, Cp=Cp@entry=0, 
        Cn=Cn@entry=0) at sklearn/svm/src/liblinear/linear.cpp:2255
    2255		for(int i=0;i<prob->l;i++)
    (gdb) bt
    #0  0x00007fffdabcce7a in train_one (prob=prob@entry=0x55555659f4f0, 
        param=param@entry=0x5555569d0180, w=w@entry=0x555556a38870, Cp=Cp@entry=0, 
        Cn=Cn@entry=0) at sklearn/svm/src/liblinear/linear.cpp:2255
    #1  0x00007fffdabd0279 in train (prob=prob@entry=0x55555659f4f0, 
        param=param@entry=0x5555569d0180) at sklearn/svm/src/liblinear/linear.cpp:2386
    #2  0x00007fffdabc1289 in __pyx_pf_7sklearn_3svm_9liblinear_train_wrap (
        __pyx_v_X=__pyx_v_X@entry=0x7ffff1af4350, 
        __pyx_v_Y=__pyx_v_Y@entry=0x7ffff1af43f0, 
        __pyx_v_is_sparse=__pyx_v_is_sparse@entry=0, 
        __pyx_v_solver_type=__pyx_v_solver_type@entry=13, 
        __pyx_v_eps=__pyx_v_eps@entry=0.0001, __pyx_v_bias=__pyx_v_bias@entry=1, 
        __pyx_v_C=__pyx_v_C@entry=1, 
        __pyx_v_class_weight=__pyx_v_class_weight@entry=0x7ffff1af4490, 
        __pyx_v_max_iter=__pyx_v_max_iter@entry=20, __pyx_v_random_seed=209652396, 
        __pyx_v_epsilon=0, __pyx_v_sample_weight=0x7ffff1af4120, 
        __pyx_self=<optimized out>) at sklearn/svm/liblinear.c:2200
    #3  0x00007fffdabc4e36 in __pyx_pw_7sklearn_3svm_9liblinear_1train_wrap (
        __pyx_self=<optimized out>, __pyx_args=<optimized out>, 
        __pyx_kwds=<optimized out>) at sklearn/svm/liblinear.c:1841
    

    I cannot reproduce the segfault when I am outside of pytest for instance the script of @albertcthomas : #10667 (comment)

  21. rth commented on May 25, 2018

    @rth
    Member

    This seems like a duplicate of #10667. @rth had the same issue and using the gcc/g++ from conda fixed it for him too.

    Yes, I have forgotten about it. Installing gcc from conda did fix it for me, but it's certainly not ideal...

  22. lesteve commented on May 25, 2018

    @lesteve
    Member

    Something I forgot to mention is that the problem was seen in master in #10667 well before #10663 was merged so I reckon #10663 is only highlighting an existing problem rather than being the culprit.

  23. glemaitre commented on May 25, 2018

    @glemaitre
    Member

    The hotfix in #11133 would solve the issue since it will trigger a copy of y in the read-only case.
    We try with @ogrisel to force y to be const but it did not solve the issue.

  24. ogrisel commented on May 25, 2018

    @ogrisel
    Member

    We try with @ogrisel to force y to be const but it did not solve the issue.

    More specifically we tried to edit the liblinear.cpp source code to use const double * y instead of double * in the problem struct but we could not make it work and that would imply rewriting a significant part of liblinear.

    +1 for making a writable copy of y as done in the hotfix.

  25. amueller commented on May 26, 2018

    @amueller
    MemberAuthor

    @lesteve yeah obviously #10663 didn't create the problem, only highlights it. I didn't realize you observed the bug in #10667.
    It's pretty strange (why would it write to y?!), but if you already spend some time investigating it I'm happy to call the hotfix a fix and close.
    @ogrisel can you maybe explain what casting a memory map to a float pointer means and why it might segfault? Though your idea of a fix sounds reasonable, it probably is not worth the effort.

  26. lesteve commented on May 28, 2018

    @lesteve
    Member

    As @amueller, I have to say I would be very happy to hear more about the root cause of the problem ...

  27. amueller commented on Jun 28, 2018

    @amueller
    MemberAuthor

    Closing this, I don't think it's worth spending time on investigating.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions