Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use Cython BLAS API and remove bundled BLAS #11638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rth opened this issue Jul 20, 2018 · 11 comments
Closed

Use Cython BLAS API and remove bundled BLAS #11638

rth opened this issue Jul 20, 2018 · 11 comments
Milestone

Comments

@rth
Copy link
Member

rth commented Jul 20, 2018

As far as I understand, Scikit-learn currently tries to link against the system (or possibly numpy) BLAS, and if it is not found falls back to the bundled CBLAS. The latter case results in degraded performance, and can lead to packaging issues (e.g. #10105).

In the future, once support for scipy <0.16 is dropped it might be worthwhile to use the Scipy BLAS API in all cases and remove the bundled CBLAS. At the time of writing, the minimal supported scipy version is 0.13.2.

@ogrisel
Copy link
Member

ogrisel commented Sep 14, 2018

#11950 has started to do it for a refactoring of K-Means and early benchmarks are promising.

@jakirkham
Copy link
Contributor

Saw the discussion in PR ( #12184 ) seems to be forming a consensus around using a newer version of SciPy on master making this feasible. Does that mean PRs in this direction be welcome?

@rth
Copy link
Member Author

rth commented Sep 29, 2018

I think we would want to wait for the minor 0.20.1 bugfix release first (cf #12184), to reduce potential backporting issues. After which PRs would be definitely very welcome :)

BTW, are you aware of projects that have been doing this reliably for a while for a range scipy versions and OSs (e.g. on conda forge)? For instance, do we know if scipy 0.17 - 1.1+ does maintain a backward compatible ABI for the BLAS functions exposed in Cython ? There is a discussion implying it in scipy/scipy#6440 (comment) but nothing too official.

@jakirkham
Copy link
Contributor

Sounds like a good question for SciPy devs (though I guess you did that already 😄). Maybe worth drawing their attention to this issue again?

@jeremiedbb
Copy link
Member

There is a small(?) obstacle to this. We don't make calls to BLAS only from cython but also from C++, in sklearn/svm/src/liblinear/tron.cpp to be precise. There we can't use scipy cython bindings of BLAS functions.

One solution would be to port tron.cpp to cython. The file is not too big. Would you consider it worth ?

I don't know if there's an other way. Do you have any idea ?

@rth
Copy link
Member Author

rth commented Feb 4, 2019

Could it be possible to call Cython BLAS functions from C (and I guess C++) ? https://cython.readthedocs.io/en/latest/src/userguide/external_C_code.html#using-cython-declarations-from-c

@jeremiedbb
Copy link
Member

I saw that but to do that you have to embed python into c, which would cause a huge overhead I guess.

@rth
Copy link
Member Author

rth commented Feb 4, 2019

which would cause a huge overhead I guess.

Yeah, taking time python -c "import numpy" as a benchmark, I would guess 100-200 ms (possibly less) to get the interpreter started. Doesn't sound great indeed.

@jnothman
Copy link
Member

jnothman commented Feb 4, 2019 via email

@NicolasHug
Copy link
Member

Stupid question, why are we vendoring liblinear in sklearn/svm?

@rth
Copy link
Member Author

rth commented Feb 13, 2019

Stupid question, why are we vendoring liblinear in sklearn/svm?

LinearSVC uses liblinear,

Linear Support Vector Classification.
Similar to SVC with parameter kernel='linear', but implemented in terms of
liblinear rather than libsvm, so it has more flexibility in the choice of
penalties and loss functions and should scale better to large numbers of
samples.

If you question is why in svm instead of linear_module I don't know, maybe putting it alongside libsvm made more sense with repect to vendored code...

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

No branches or pull requests

6 participants