Skip to content

Array API: integrating array-api-extra #30367

Closed

Description

@lucascolley

Following on from our discussion in the array API standard community meeting @betatim:

https://data-apis.org/array-api-extra/ is a library which I have authored, with the main purpose of giving a public API 'home' to array-agnostic functions which consumer libraries find themselves needing to write and store in private modules. Various functions in https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/utils/_array_api.py could find a home in array-api-extra.

SciPy has offloaded its functions of this sort to array-api-extra, which it now vendors via a git submodule. The main purpose of scikit-learn doing the same is to share the work which has been done with any other consumer library via a clear API Reference, rather than them having to dig through the source code and copy & paste (or reinvent the wheel). There are other benefits too, as the functions in array-api-extra get proper documentation, tests, and static type hints.

The question is then how to adopt array-api-extra in scikit-learn. From the discussion with @betatim we concluded that array-api-extra is not best suited as an optional dependency, as boilerplate would need to be added to catch the case that it isn't installed and either error or replicate the functions with NumPy.

Does scikit-learn have an established process for vendoring code from other repos? In gh-30340 I tried to wrangle CI to get a git submodule to work, but there may be alternatives to that.

cc @ogrisel @thomasjpfan @OmarManzoor


A sidenote is that scikit-learn may want to look into vendoring array-api-compat itself rather than having an optional dependency. In the meeting, it wasn't clear why it was done this way in the first place.

Activity

  1. added
    Needs Triage
    on Nov 28, 2024
  2. thomasjpfan commented on Nov 28, 2024

    @thomasjpfan
    Member

    A sidenote is that scikit-learn may want to look into vendoring array-api-compat itself rather than having an optional dependency. In the meeting, it wasn't clear why it was done this way in the first place.

    At the time, Array API support was experimental and array-api-compat was iterating quickly. Given that scikit-learn has a slower release cycle, we did not want to have users wait for a scikit-learn release to get any fixes from array-api-compat.

    Does scikit-learn have an established process for vendoring code from other repos?

    There is no set process. Historically, we just copy over the code with it's license. When I was looking to vendor lazy_loader, I added a script to do it:

    https://github.com/thomasjpfan/scikit-learn/blob/lazy_import/maint_tools/vendor_lazy_loader.sh

    It's basically git submodule without actually using it.

  3. betatim commented on Dec 2, 2024

    @betatim
    Member

    I think the question that we should answer first is: do we want to use array-api-extra? It has the advantages that Lucas listed. A downside is that when we need a new function we need to first add it to array-api-extra, then update the vendored code, then work on the feature. Or have a way to have functions in sklearn.utils._array_api as well as use functions from array-api-extra, which brings some complexity with it.

    I am a -0.5 on having to go through the three step process in order to have new functions available. Not because it is super complicated, but it adds a lot of extra steps and delays to the process. Which I think will make it significantly harder for "random people off the internet highway" to contribute to the array-api'fication of scikit-learn. So I think we need some way to have a mixture, that isn't too complex to maintain.

    What do y'all think?

    I am -1 on git submodules. They seem to mostly cause trouble and complexity. A script that helps update the code sounds better.

  4. lucascolley commented on Dec 2, 2024

    @lucascolley
    ContributorAuthor

    A downside is that when we need a new function we need to first add it to array-api-extra, then update the vendored code, then work on the feature. Or have a way to have functions in sklearn.utils._array_api as well as use functions from array-api-extra, which brings some complexity with it.

    See my answer to Omar in the PR:

    It doesn't have to be instead of utils. I would suggest you keep your current workflow the exact same - you can still put private helpers in utils to start off with. But in addition, every now and then, you can offload them to array-api-extra so that others can use them. That's what we're doing in SciPy.

    Making use of both does not seem to add significant complexity IMO.

  5. removed
    Needs Triage
    on Dec 5, 2024
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