Repository navigation
Description
Warning
This issue is not yet ready for a PR. If you are interested in contributing to scikit-learn, please have a look at our contributing guidelines, and in particular the sections for new contributors and the "Needs triage" label.
Our existing array API documentation would benefit from being complemented by a link to a running example that shows the benefits of using array API to hardware-accelerate the cross-validation (or even the hyper-parameter tuning) of a non-trivial pipeline.
I think we could include the following estimators:
OneHotEncoderor (TargetEncoderfollowed byMinMaxScaler) for categorical features and SplineTransformer for numerical features in columntransformer on CPU.FunctionTransformerto move the results to an automatically detected device using PyTorchNystroemtransformer (with an RBF or a polynomial kernel)RidgeCVorPoissonRegressor
For information, I demoed the usefulness of GPU acceleration via array API on google colab on a synthetic datasets here: https://colab.research.google.com/github/ogrisel/notebooks/blob/master/poly_reg_array_api.ipynb
But contrary to this colab notebook, I think our new usage example should:
- use a real regression dataset with a mix of categorical and numerical features. This would justify the need to run the first step of the pipeline on CPU because array API does not accept non-numerical columns.
- make the
FunctionTransformerimplement the logic to automatically detect the best hardware available on the host. This would make it easier to pickle and load this pipeline on a different host with different accelerators without changing its structure.
Objectives
- show a realistic yet educational array API usage scenario that works around array API fundamental limitations (e.g. categorical features), current limitations (e.g. lack of support of array API in
SplineTransformer) and current UX friction (selection of the fastest device on the hosts, picklability of pipelines accross hosts with different - help maintainers make more informed decisions for the design of
move_estimator_toand better assess the value/impacts of Store all fitted attributes as Numpy arrays #35053). - [optional] make it easy to assess the performance impact of hardware acceleration on a realistic pipeline. But maybe this point is better addressed by a more complex benchmark infrastructure such as https://github.com/probabl-ai/scikit-learn-benchmarks.
Challenge
The existing examples of the scikit-learn documentation are rendered on Circle CI with a CPU-only runner. Therefore, if we use our existing infra to render the example, parts of its educational value will not be visible in the rendered outputs and the example might be a bit confusing as a result.
Possible solutions
- a. render the example on the CPU as usual and assume that part of the example runs on the CPU rather than on GPU. Explain in the body of the text of example that to the user needs to run the notebook on a different host to see the benefits of using a GPU (e.g. on machine with a NVIDIA GPU using a CUDA device, Apple GPU via MPS or Intel GPU via XPU). The text of the example could include a Google Colab link to make it easy to test the first case.
- b. find a way to use our GitHub Actions CI to render this particular example with a CUDA GPU.
- c. migrate away from circle ci and render the full doc on a GPU accelerated machine.
- d. develop a sphinx-gallery extension to render a single notebook on a GPU machine (e.g. using modal or similar).
The problem with point b. is that we would need to coordinate two CI jobs running on different infrastructures to commit the rendered HTML doc on github pages. That sounds challenging to setup and painful to maintain.
Point c. would be easier to maintain but more expensive and maybe a waste of GPU resources.
I think that solution a. is enough in the short term and we can follow-up later with one of the others solutions.
I marked this issue as "Needs Decision" because I don't want to attract a flux of semi-automated PRs before we have a chance to roughly agree that such an example is needed, that the proposed contents is meaningful and how we plan to address the CI related challenge.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
github-actions commentedon Nov 16, 2026
Thanks for the work you've done so far. The goal of this comment is to set expectations.
Deciding on new features or substantial changes is a lengthy process. It frequently happens that no maintainer is available to take on this task right now.
Please do not create a Pull Request before a decision has been made regarding the proposed work. Making this decision can often take a significant amount of time and effort.
lesteve commentedon Nov 17, 2026
I would start with the lowest tech possible i.e. option a: the example use PyTorch-CPU and contains a Colab link. I think you could use the scikit-learn.github.io generated
.ipynbnotebook e.g.I thought it was possible to set the runtime to "T4 GPU" in the Colab link but I am not finding it right now, maybe I misremember it.
xref #32886 which was only about adding a realistic array API example to the gallery.
ogrisel commentedon Nov 17, 2026
Indeed. I close the older issue in favor of this one to avoid parallel discussions.
ogrisel commentedon Nov 17, 2026
Also xref #33564 that drafts several examples for different estimators.
lesteve commentedon Nov 18, 2026
One tiny thing is that the Colab notebook will likely need modifications on top of on our
.github.ionotebook e.g.!pip installcommands to install packages and control the scikit-learn version. I think the simplest solution would be to add a cell as commented out code with a comment saying "Uncomment if you are trying to run this inside Colab".