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
Add support for Python 3.13 free-threaded build #28978
Comments
Thanks for your investigation.
Indeed we do not have a Python 3.13 build yet so maybe some of those failures are related to that.
That would probably be too long to build all of those dependencies from source on the CI. Maybe upstream packages such as numpy and scipy could publish nightly builds for Python 3.13? As far as I know this is not the case yet:
However, according to https://peps.python.org/pep-0703/#python-build-modes, there are two CPython ABIs for the foreseeable future and I am not sure how those two ABIs can be reflected in wheel filenames. https://peps.python.org/pep-0703/#distribution mentions a dedicated conda channel but I am not sure about the status of this channel. |
In any case, feel free to open PRs to address some of those failures you discovered even if we don't have a Note that we do have a 3.9 |
Great, I might look at setting that up along with fixing the 3.13-specific issues. Testing the free-threaded build will need to wait a little bit. I'm hoping that the
There is a new ABI tag ( Also, one big issue is that pip doesn't know about the ABI tag yet (pypa/pip#12634). However that should be fixed in pip 24.1.
I don't think this has been set up yet. The last I heard the Anaconda Inc team was planning to start work on free-threaded support around the release of the first beta (so, nowish).
Great, thanks for this. Would creating a |
And it probably makes sense to retire this CI job since the 3.13 free-threaded build should replace it and we've been upstreaming support using the |
I am Interested to help on this, don't hesitate to ping me on this kind of topics! Together with @ogrisel I was involved with setting up the scikit-learn CI for the nogil Python 3.9 and opening upstream bugs when we encountered them. I have created the no-GIL label (following the same naming as scipy and numpy for consistency although I have always used nogil personally). Note that label search will match "nogil" and "free-threaded" since both terms appear in the label description. Issues and PRs will need manual labeling by a scikit-learn maintainer for now, but I guess this is good enough for now, let me know if you have better suggestions! |
Naming things: when accepting PEP 703, the Steering Council said they wanted us to use a positive term like "free-threaded" rather than negative terms like "no-GIL":
And we use "topic-free-threading" for CPython: https://github.com/python/cpython/labels/topic-free-threading |
This seems definitely desirable. Alternatively in the shorter term, if there was a Docker image (even in an experimental state) with Python free-threaded build + latest numpy release and scipy release, this may make it more likely that curious but busy people (for example me) give it a go. |
It could even be a nightly/weekly updated docker image with the dev versions of numpy and scipy. If a free docker hub account is enough we could use the auto-build feature of docker hub or similar: https://docs.docker.com/docker-hub/builds/ Not sure about build time limit/usage quotas though. EDIT: still I would prefer installing from a pip wheel house, e.g. https://pypi.anaconda.org/scientific-python-nightly-free-threaded/ to workaround any pip ABI tag conflicts that would prevent us to directly reuse https://pypi.anaconda.org/scientific-python-nightly-wheels/ . |
There's a new ABI tag, so the new nightly wheels can live alongside the old ones on https://pypi.anaconda.org/scientific-python-nightly-wheels/. We just need to wait for a new pip release that can recognize and install the new ABI tag and for the the actual wheels to be produced. I'd like to look at that for NumPy at least later this week. |
Ah but we probably will need to wait on cibuildwheel support first: pypa/cibuildwheel#1657 So maybe a docker image would be best until beta 2? |
Just a note that we got rid of Docker images and weekly pushes to Docker Hub in NumPy and SciPy after they limited their free plan (and the machinery was a bit of a pain to begin with). Setting that up again isn't worth it imho. CPython 3.13 beta 2 is only two weeks away (May 28th), so I'd wait for that and if you want something in the meantime then building a one-off Docker image by hand to use for a few weeks until nightly wheels arrive should be okay I'd think. Investing time in auto-building Docker images is probably not the most productive way of spending time. |
👍 for being patient for two weeks instead of building something "bespoke" that we should then un-build again. |
We would also need to make sure that older pip releases are not confused by the presence of wheels with the new ABI tag and do not fetch those wheels by mistake when trying to run nightly builds on the non-free-threaded version of CPython 3.13. |
I built CPython GDBM_CFLAGS="-I$(brew --prefix gdbm)/include" \
GDBM_LIBS="-L$(brew --prefix gdbm)/lib -lgdbm" \
./configure --config-cache \
--with-pydebug \
--with-system-libmpdec \
--with-openssl="$(brew --prefix openssl@3.0)" \
--disable-gil && make -s -j10
Then I could successfully run Then I created a venv with And then I tried to build numpy with
any suggestion @ngoldbaum? |
I think @lesteve had a similar problem on Linux so it's probably not macOS specific? |
Not sure if it matters, but that's not latest numpy |
I tried again, not sure what I did differently this time to be honest, but it went a bit further. This time, I get a build error in numpy More details
|
FWIW, I also see that using a virtualenv like @ogrisel is trying to do.
I think maybe because |
This is fixed in cython main, you'll need to compile cython from the git repo before building numpy. |
Ahh, sorry! This is because meson can't find python.h or libpython, so you need to set e.g. |
I'm currently working on adding support for the Python 3.13 free-threaded build to projects in the scientific python ecosystem. We are tracking this work at https://github.com/Quansight-Labs/free-threaded-compatibility. Right now we're focusing on projects relatively low in the stack. scikit-learn isn't the lowest in the stack but it has a lot of tests that perform multithreaded workflows so running the scikit-learn tests is a productive way to elucidate threading bugs in scikit-learn and its dependencies.
Currently, scikit-learn builds fine and almost all the tests pass with the GIL disabled 🎉
The following tests have failures:
Note that some of these failures are flaky and you may not get the same list if you run the scikit-learn tests. I also saw one deadlock in
test_calibration.py::test_parallel_execution
, so I'd also suggest running pytest with e.g.-o fauthandler_timeout=60
set so you will get python tracebacks for all threads if any test hangs and runs longer than 60 seconds. Your mileage may vary on how fast your computer is, so 60 seconds may not be sufficient if any tests take that long to run on your system.My plan is to go through these failures and figure out what's going wrong. Some of these may not be specific to the free-threaded build.
To run the tests with the GIL disabled, you'll need to install 3.13b1 or the latest version of the CPython 3.13 branch, build cython, numpy, and scipy from the latest version of their respective git repositories. You'll need to e.g.
pip install
pybind11 and pythran after installing numpy and before building scipy. Then build scikit-learn as an editable install and run:The text was updated successfully, but these errors were encountered: