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

Add axis and where arguments to loss functions. #912

Merged
merged 16 commits into from
Aug 28, 2024
Merged

Add axis and where arguments to loss functions. #912

merged 16 commits into from
Aug 28, 2024

Conversation

carlosgmartin
Copy link
Contributor

@carlosgmartin carlosgmartin commented Apr 8, 2024

@vroulet
Copy link
Collaborator

vroulet commented Apr 8, 2024

Thanks @carlosgmartin, could you add tests?
Also you will need to wait for #916 to pass.

@fabianp
Copy link
Member

fabianp commented Jun 10, 2024

@carlosgmartin , there are some conflicts with main, do you mind updating the pull request? thanks

@carlosgmartin
Copy link
Contributor Author

@vroulet @fabianp Let me know if you'd like me to make any other changes.

@fabianp
Copy link
Member

fabianp commented Aug 19, 2024

hey @carlosgmartin , thanks for the ping and apologies for the late reply, most of the team is on vacation 🏖️

The addition of the axis argument looks good to me, and the use of an axis kwarg if fairly common in numpy-like functions. ✅

Regarding the "where" argument however, I haven't seen it yet in other libraries. Do you know of any numpy/jax/flax/etc. functions that admit a "where" or a "mask" or similar kwarg? I just want to make sure that our API is as similar as possible to other libraries that have already implemented similar functionality.

@carlosgmartin
Copy link
Contributor Author

carlosgmartin commented Aug 19, 2024

Most reduction functions in numpy/jax take a where argument for masking. For example:

Conceptually, it makes sense that any reduction function should take both axis and where arguments.

@fabianp
Copy link
Member

fabianp commented Aug 20, 2024

excellent, thanks for the info!

@fabianp
Copy link
Member

fabianp commented Aug 20, 2024

one more thing: could you please add the tag .. versionchanged:: 0.2.4 to the docstrings of the functions you've changed explaining the change? See for example here for an example: https://github.com/google-deepmind/optax/blob/main/optax/schedules/_inject.py#L114

@fabianp
Copy link
Member

fabianp commented Aug 20, 2024

also, the new kwargs should be described in the function docstring (on top of adding the versionchanged tag)

@carlosgmartin
Copy link
Contributor Author

@fabianp Done.

@fabianp
Copy link
Member

fabianp commented Aug 21, 2024

thanks, we're almost there. Please add type annotations for these two new kwargs. These are likely

where: chex.Array | None = None,
axis: int | tuple[int, ...] | None = -1

@carlosgmartin
Copy link
Contributor Author

@fabianp Done.

Copy link
Member

@fabianp fabianp left a comment

Choose a reason for hiding this comment

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

thanks!

@copybara-service copybara-service bot merged commit eba3733 into google-deepmind:main Aug 28, 2024
8 checks passed
@carlosgmartin carlosgmartin deleted the loss_axis_where branch August 28, 2024 16:37
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