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: Test tools for jax.jit and dask #115

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

crusaderky
Copy link
Contributor

@crusaderky crusaderky commented Jan 21, 2025

Porting of scipy/scipy#22308, with additional support for Dask.

@lucascolley lucascolley added the enhancement New feature or request label Jan 21, 2025
@lucascolley lucascolley changed the title ENH Test tools for jax.jit and dask ENH: Test tools for jax.jit and dask Jan 21, 2025

# some xp backends are untyped
# mypy: disable-error-code=no-untyped-usage

lazy_xp_function(atleast_nd, static_argnames=("ndim", "xp"))
lazy_xp_function(cov, static_argnames="xp")
# FIXME .device attribute https://github.com/data-apis/array-api-compat/pull/238
Copy link
Contributor Author

Choose a reason for hiding this comment

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

data-apis/array-api-compat#238

Evidence that the numpy-compat PR works: crusaderky@d27f75d

lazy_xp_function(kron, static_argnames="xp")
lazy_xp_function(nunique, static_argnames="xp")
lazy_xp_function(pad, static_argnames=("pad_width", "mode", "constant_values", "xp"))
# FIXME calls in1d which calls xp.unique_values without size
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is non-trivial to fix. Will look into it in a follow-up.

Comment on lines +70 to +87
allow_dask_compute : int, optional
Number of times `func` is allowed to internally materialize the Dask graph. This
is typically triggered by `bool()`, `float()`, or `np.asarray()`.

Set to 1 if you are aware that `func` converts the input parameters to numpy and
want to let it do so at least for the time being, knowing that it is going to be
extremely detrimental for performance.

If a test needs values higher than 1 to pass, it is a canary that the conversion
to numpy/bool/float is happening multiple times, which translates to multiple
computations of the whole graph. Short of making the function fully lazy, you
should at least add explicit calls to `np.asarray()` early in the function.
*Note:* the counter of `allow_dask_compute` resets after each call to `func`, so
a test function that invokes `func` multiple times should still work with this
parameter set to 1.

Default: 0, meaning that `func` must be fully lazy and never materialize the
graph.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In a previous version this was a all-or-nothing test. scipy/scipy#22240 (comment) prompted me to change it.

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

Successfully merging this pull request may close these issues.

2 participants