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

Zygote is broken for Stacked transformations #361

Closed
bgctw opened this issue Jan 13, 2025 · 3 comments · Fixed by #362
Closed

Zygote is broken for Stacked transformations #361

bgctw opened this issue Jan 13, 2025 · 3 comments · Fixed by #362
Assignees
Labels
bug Something isn't working

Comments

@bgctw
Copy link

bgctw commented Jan 13, 2025

The following MWE fails for Bijectors Bijectors v0.15.3

#]activate --temp
#add Bijectors, Zygote
using Bijectors
using Zygote
x = [-2, 3.0, 2.1, 2.2]
ranges = [1:1, 2:2, 3:4]
tr = Stacked((elementwise(identity), elementwise(exp), elementwise(exp)), ranges)
y = tr(x)
gr = Zygote.gradient(tr, x) # error: output length mismatch (4 != 3)

Environment

julia> Pkg.status()
Status `/tmp/jl_fDy5Lg/Project.toml`
  [76274a88] Bijectors v0.15.3
  [e88e6eb3] Zygote v0.7.1
@mhauru mhauru added the bug Something isn't working label Jan 13, 2025
@mhauru mhauru self-assigned this Jan 14, 2025
@mhauru
Copy link
Member

mhauru commented Jan 14, 2025

This should be fixed by #362 once it's merged. Thanks for spotting and reporting @bgctw!

Note that since tr in your example returns a vector, you need to call Zygote.jacobian rather than Zygote.gradient. With #362 this works:

julia> using Bijectors
       using Zygote
       x = [-2, 3.0, 2.1, 2.2]
       ranges = [1:1, 2:2, 3:4]
       tr = Stacked((elementwise(identity), elementwise(exp), elementwise(exp)), ranges)
       y = tr(x)
       Zygote.jacobian(tr, x)
([1.0 0.0 0.0 0.0; 0.0 20.085536923187668 0.0 0.0; 0.0 0.0 8.16616991256765 0.0; 0.0 0.0 0.0 9.025013499434122],)

@mhauru
Copy link
Member

mhauru commented Jan 16, 2025

Bijectors v0.15.4 should be out later today, and includes the fix for this.

@bgctw
Copy link
Author

bgctw commented Jan 17, 2025

Thanks for this quick fix and the quick release of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants