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

Shared parameters and withgradient #167

Open
mcabbott opened this issue Mar 25, 2024 · 0 comments
Open

Shared parameters and withgradient #167

mcabbott opened this issue Mar 25, 2024 · 0 comments

Comments

@mcabbott
Copy link
Member

mcabbott commented Mar 25, 2024

Notice that Tracker does not behave like Zygote here:

julia> arr = [3.0, 4.0];

julia> Tracker.withgradient(nt -> sum(sum(x) for x in nt), (a=arr, b=arr, c=copy(arr)))
(val = 21.0 (tracked), grad = ((a = [2.0, 2.0], b = [2.0, 2.0], c = [1.0, 1.0]),))

julia> Zygote.gradient(nt -> sum(sum(x) for x in nt), (a=arr, b=arr, c=copy(arr)))
((a = Fill(1.0, 2), b = Fill(1.0, 2), c = Fill(1.0, 2)),)

julia> Enzyme.gradient(Reverse, nt -> sum(sum(x) for x in nt), (a=arr, b=arr, c=copy(arr)))
(a = [2.0, 2.0], b = [2.0, 2.0], c = [1.0, 1.0])

I believe this is likely to confuse Optimisers.jl, which is written with the Zygote convention in mind.

Some possible fixes are:

  • change Tracker to give an error on such cases, easy
  • change Tracker to replace all but the first duplicate with nothing, Optimisers.jl will like that
  • simplify Optimisers.jl to accept the Tracker (and Enzyme) convention, and add a Zygote compatibility layer somewhere (e.g. make Flux.withgradient handle this)
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

No branches or pull requests

1 participant