Skip to content
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

ENH: ndonnx device() support; TST: better ndonnx test coverage #232

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

crusaderky
Copy link
Contributor

@crusaderky crusaderky commented Jan 8, 2025

@crusaderky
Copy link
Contributor Author

crusaderky commented Jan 8, 2025

This is now ready for review

@crusaderky crusaderky force-pushed the ndonnx branch 3 times, most recently from 48ed46c to 8cac708 Compare January 16, 2025 13:31
@crusaderky crusaderky force-pushed the ndonnx branch 2 times, most recently from 08d5270 to fc4079f Compare January 24, 2025 11:26
Copy link
Contributor

@ev-br ev-br left a comment

Choose a reason for hiding this comment

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

What concerns me here is a sort of conceptual question: What is the scope of a test run here in array-api-compat?

Basically, there are two kinds of array libraries: those which are array API compatible and those which need some wrapping. array-api-compat does the latter, for those libraries which need it.

Than why are we testing the libraries which we do not wrap?

There's no question that we need some better ergonomics for running tests across array libraries. I'm just not convinced it's a good idea to sort of sneak this testing here. Let's discuss a structural solution instead.

@@ -772,7 +772,7 @@ def to_device(x: Array, device: Device, /, *, stream: Optional[Union[int, Any]]
device : Hardware device the array data resides on.

"""
if is_numpy_array(x):
if is_numpy_array(x) or is_ndonnx_array(x):
Copy link
Contributor

Choose a reason for hiding this comment

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

What I don't quite understand is this: https://github.com/data-apis/array-api-compat/pull/232/files#diff-d5d8fa69860e03769cc235a54027efad4376a8c48eeab71aaa11365ea308123bR141 states that the array API support is internal to ndonnx, which seems to imply there's no need to special-case it here?

The note reads "Similar to JAX, ndonnx Array API support is contained directly in ndonnx." --- and indeed, there are no workarounds for jax in the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because they support the standard imperfectly. The array-api-tests for .device and .to_device are XFAILed:
https://github.com/Quantco/ndonnx/actions/workflows/array-api.yml

api-coverage-tests/array_api_tests/test_has_names.py::test_has_names[array_method-to_device] 
[gw1] [ 13%] XFAIL api-coverage-tests/array_api_tests/test_has_names.py::test_has_names[array_method-to_device] 
api-coverage-tests/array_api_tests/test_has_names.py::test_has_names[array_attribute-T] 
[gw1] [ 14%] PASSED api-coverage-tests/array_api_tests/test_has_names.py::test_has_names[array_attribute-T] 
api-coverage-tests/array_api_tests/test_has_names.py::test_has_names[array_attribute-device] 
[gw1] [ 14%] XFAIL api-coverage-tests/array_api_tests/test_has_names.py::test_has_names[array_attribute-device] 

Adding .device and .to_device won't break any library's backwards compatibility, so it would be best if each library just fixed it on their side. And yet here we have a function that works around the quirks of every library - last but not least to support least-than-newest versions of it.

Copy link
Contributor

@adityagoel4512 adityagoel4512 Jan 24, 2025

Choose a reason for hiding this comment

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

I will address this upstream. I should say that it might be deceptive to allow this to work with "cpu".

A serialized ONNX graph from ndonnx could later be executed on many different hardware targets or runtimes. ONNX is one level removed from the execution target by design.

Based on a quick read of the device page of the specification, we may do something similar to what you're doing with Dask.

all_libraries = wrapped_libraries + ["array_api_strict", "jax.numpy", "sparse"]

all_libraries = wrapped_libraries + [
"array_api_strict", "jax.numpy", "ndonnx", "sparse"
Copy link
Contributor

Choose a reason for hiding this comment

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

This too. Why are we testing here libraries which we don't wrap?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because _helpers.py is chock full of special cases and exceptions for them.

@crusaderky
Copy link
Contributor Author

Then why are we testing the libraries which we do not wrap?

because the libraries that we do not wrap still need the functions defined in _helpers to work around their quirks.

@crusaderky
Copy link
Contributor Author

and indeed, there are no workarounds for jax in the codebase.

There are 66 references to JAX in _helpers.py alone, with PRs such as #238 that work around breaking incompatibilities with the Array API.

@crusaderky
Copy link
Contributor Author

CC @adityagoel4512

@ev-br
Copy link
Contributor

ev-br commented Jan 27, 2025

There are 66 references to JAX in _helpers.py alone, with PRs such as #238 that work around breaking incompatibilities with the Array API.

Yes, most of which are is_jax_array and its cross-references. Essentially everything else is from gh-238 and your other recent PRs. Which is itself fine. What I'm concerned about is the scope of testing here. Suppose a test starts failing after a release of pydata.sparse or jax or ndonnx or anything else that array-api-compat does not wrap. What is an action array-api-compat can take?

@adityagoel4512
Copy link
Contributor

adityagoel4512 commented Jan 31, 2025

@crusaderky we added device support in Quantco/ndonnx@039264d. It should be possible to remove the device support here once we make a release. Is it urgent that we land this PR soon?

@crusaderky
Copy link
Contributor Author

@crusaderky we added device support in Quantco/ndonnx@039264d. It should be possible to remove the device support here once we make a release. Is it urgent that we land this PR soon?

No, this PR can wait.

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

Successfully merging this pull request may close these issues.

3 participants