Skip to content

Conversation

icfaust
Copy link
Contributor

@icfaust icfaust commented Dec 3, 2024

Description

Enables array API zero copy dispatching for EmpiricalCovariance and IncrementalEmpiricalCovariance, this required the following changes:

  • Added array API-enabled log_likelihood and pinvh functions (as they are unavailable in sklearn) to sklearnex.utils._array_api
  • fix sklearnex.preview.covariance.EmpiricalCovariance.mahalanobis.__doc__ which was a bug
  • Implement array API enabled mahalanobis, score, and error_norm methods. Likely to change due to the nature of how we support dpnp and dpctl.
  • Added array API enabling from [enhancement] simplify array_api enabling tags via wrapper #2566
  • Added check_is_fitted (which is even missing from sklearn)
  • Added get_namespace and swapped namespace support away from numpy
  • Create a get_precision function to use internal pinvh. This is important for array API conformance, where attributes will no longer only be numpy arrays
  • moved sklearn conformance of return values to sklearnex estimators instead of onedal
  • general fixes for array_api_strict inputs (ellipsis use)
  • Move validate_params before fit's dispatch (will be set as a design rule in a follow-up PR
  • Deal with an issue with pairwise_distances kwargs and support_input_format, which do not interact well. A follow up development ticket for fixing this issue will be made
  • set proper array API conformance for return types of oneDAL tables using return_type_constructor in IncrementalEmpiricalCovariance

PR should start as a draft, then move to ready for review state after CI is passed and all applicable checkboxes are closed.
This approach ensures that reviewers don't spend extra time asking for regular requirements.

You can remove a checkbox as not applicable only if it doesn't relate to this PR in any way.
For example, PR with docs update doesn't require checkboxes for performance while PR with any change in actual code should have checkboxes and justify how this code change is expected to affect performance (or justification should be self-evident).

Checklist to comply with before moving PR from draft:

PR completeness and readability

  • I have reviewed my changes thoroughly before submitting this pull request.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation to reflect the changes or created a separate PR with update and provided its number in the description, if necessary.
  • Git commit message contains an appropriate signed-off-by string (see CONTRIBUTING.md for details).
  • I have added a respective label(s) to PR if I have a permission for that.
  • I have resolved any merge conflicts that might occur with the base branch.

Testing

  • I have run it locally and tested the changes extensively.
  • All CI jobs are green or I have provided justification why they aren't.
  • I have extended testing suite if new functionality was introduced in this PR.

Performance

  • I have measured performance for affected algorithms using scikit-learn_bench and provided at least summary table with measured data, if performance change is expected.
  • I have provided justification why performance has changed or why changes are not expected.
  • I have provided justification why quality metrics have changed or why changes are not expected.
  • I have extended benchmarking suite and provided corresponding scikit-learn_bench PR if new measurable functionality was introduced in this PR.

@icfaust icfaust changed the title [Enhancement] WIP new finite checking in EmpericialCovariance [Enhancement] WIP new finite checking in EmpiricialCovariance Dec 3, 2024
@icfaust icfaust changed the title [Enhancement] WIP new finite checking in EmpiricialCovariance [Enhancement] WIP new finite checking in EmpiricialCovariance and IncrementalEmpiricalCovariance Dec 3, 2024
@icfaust
Copy link
Contributor Author

icfaust commented Dec 4, 2024

/intelci: run

@icfaust
Copy link
Contributor Author

icfaust commented Dec 4, 2024

/intelci: run

@icfaust
Copy link
Contributor Author

icfaust commented Dec 4, 2024

This PR is now dependent on the developments in #2096 (SPMD testing requires array_api bypassing on oneDAL offloading)

@icfaust
Copy link
Contributor Author

icfaust commented Aug 8, 2025

/intelci: run

@icfaust
Copy link
Contributor Author

icfaust commented Aug 10, 2025

/intelci: run

@icfaust
Copy link
Contributor Author

icfaust commented Aug 11, 2025

/intelci: run

@icfaust
Copy link
Contributor Author

icfaust commented Aug 11, 2025

/intelci: run

@icfaust
Copy link
Contributor Author

icfaust commented Aug 11, 2025

/intelci: run

@icfaust
Copy link
Contributor Author

icfaust commented Aug 11, 2025

/intelci: run

with config_context(array_api_dispatch=True):
est.fit(X_df)

with pytest.raises(TypeError, match="Multiple namespaces for array inputs: .*"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this work correctly if put under a config context with array_api_dispatch=True?

Copy link
Contributor Author

@icfaust icfaust Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used sklearn's Ridge + numpy and torch as an example of what to expect: (https://scikit-learn.org/stable/modules/array_api.html#input-and-output-array-type-handling)
image
When attempting to use any non-numpy input after fitting with array_api_dispatch=True will lead to some sort of error associated with the fitted framework, as get_namespace and validate_data will default force data to numpy (https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/utils/_array_api.py#L394) and then comparing numpy to the array api framework will fail.

If we were to use array_api_dispatch=True throughout, it will error at this point in an external package if get_namespace is used: https://github.com/data-apis/array-api-compat/blob/main/array_api_compat/common/_helpers.py#L665

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the idea with array API support in stock sklearn to make it work under such types of situations? (e.g. fitting on a torch array, then predicting on a different kind of array).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually no, I see that sklearn throws the same error.

@icfaust
Copy link
Contributor Author

icfaust commented Aug 12, 2025

/intelci: run

@icfaust
Copy link
Contributor Author

icfaust commented Aug 13, 2025

Private CI failure comes from an infrastructure timeout.

@icfaust icfaust merged commit b450725 into uxlfoundation:main Aug 13, 2025
29 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants