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

Fix _broadcast_in_dim_prim_grad when reduce_dims is empty #290

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

Conversation

rdspring1
Copy link
Collaborator

>>> import jax
>>> import numpy as np
>>> x = np.random.normal(size=(5,))
array([ 0.55060031, -0.03787608, -0.81081705,  0.26335944, -1.4178462 ])
>>> jax.lax.broadcast_in_dim(x, [5], [0])
Array([ 0.5506003 , -0.03787608, -0.81081706,  0.26335943, -1.4178462 ],      dtype=float32)

This ^^^ broadcast_in_dim is a no-op. In the gradient function, the reduce_dims tuple is empty, implying we do not want to remove any dimensions. However, when the dim tuple is empty, torch.sum reduces all dimensions. The solution is to skip the reduction.

@rdspring1 rdspring1 marked this pull request as ready for review May 1, 2024 01:00
@mruberry
Copy link
Collaborator

mruberry commented May 1, 2024

@IvanYashchuk and/or @nikitaved -- would you review this, please?

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.

None yet

2 participants