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

numpy backend requires jax? #18840

Closed
hmaarrfk opened this issue Nov 28, 2023 · 8 comments
Closed

numpy backend requires jax? #18840

hmaarrfk opened this issue Nov 28, 2023 · 8 comments
Assignees
Labels
keras-team-review-pending Pending review by a Keras team member. type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.

Comments

@hmaarrfk
Copy link
Contributor

It seems that the numpy backend imports jax

and seems to use it below:

    return np.array(
        jax.image.resize(image, size, method=interpolation, antialias=antialias)
    )

is that intention?

@SuryanarayanaY SuryanarayanaY added API design review API modifications. Needs discussion and approval from fchollet. type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited. and removed API design review API modifications. Needs discussion and approval from fchollet. labels Nov 29, 2023
@SuryanarayanaY
Copy link
Contributor

It seems numpy backend has Jax dependency. I can find it in backend/numpy/nn.py also.

@SuryanarayanaY SuryanarayanaY added the keras-team-review-pending Pending review by a Keras team member. label Nov 29, 2023
@fchollet
Copy link
Collaborator

fchollet commented Nov 29, 2023

Yes, that's intentional. We found that when implementing nn ops like conv or pooling, a low-level pure numpy implementation was vastly less performant than jax, so we just use jax for these ops.

Copy link

Are you satisfied with the resolution of your issue?
Yes
No

@hmaarrfk
Copy link
Contributor Author

I feel like this is seriously misleading. numpy and Jax offer drastically different compilation, testing, and integration challenges.

installing Jax and installing numpy can be quite different in resource limited environments.

I think that:

  1. users of the pure numpy backend should expect slower, albeit numerically equivalent/similar to that of other more accelerated backends.
  2. if you want, I think a hybrid approach if "trying to use Jax, but falling back to the much slower numpy operators" may be acceptable, but it may create surprising behavior.

for example, I would expect a backend of

  1. "numpy" not to depend on Jax at all.
  2. "numpy+Jax" to use Jax in select locations
  3. "jax" primarily use Jax

as is, users cannot use the numpy backend at all without Jax. in my mind, it just shouldn't be called "numpy backend"

I am not saying this in any hostile way, just as a packager that tried to test things with numpy only and was quite surprised that I needed a heavy dependency like Jax to get any operators to work.

If my tone is negative, it is because in my mind, you hastily closed this issue without giving the chance to respond.
would it be acceptable to reopen this issue and at least acknowledge to others that this is a present limitation of the 3.0.0 version? Closing this issue just seems wrong.

@mthiboust
Copy link

mthiboust commented Nov 6, 2024

I second the comment of @hmaarrfk. I think it would be useful to have the possibility of having a lightweight keras installation powered by the numpy backend in order to run small inference tasks in limited environments.

@fchollet
Copy link
Collaborator

fchollet commented Nov 6, 2024

That's a reasonable view. There's definitely a huge slowdown however.

If you'd like to open a PR to revert some ops to pure numpy implementation, we can consider it.

@mthiboust
Copy link

Thanks François for your answer. I see that the functions involved are jax.image.resize, jax.numpy.fft.* and jax.lax.conv_*. Don't know yet if I'll work on this PR.

@fchollet
Copy link
Collaborator

fchollet commented Nov 6, 2024

The fft ops should be a trivial change since they're already available in numpy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keras-team-review-pending Pending review by a Keras team member. type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.
Projects
None yet
Development

No branches or pull requests

4 participants