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 context cache incorrectly(?) persists between AD calls #69

Closed
marius311 opened this issue Jan 5, 2023 · 0 comments · Fixed by #77
Closed

Zygote context cache incorrectly(?) persists between AD calls #69

marius311 opened this issue Jan 5, 2023 · 0 comments · Fixed by #77

Comments

@marius311
Copy link

You can see below more objects accumulate into it every call. I'm not an expert but @oxinabox on Slack suggested this might be incorrect:

julia> let
           ad = AD.ZygoteBackend()
           AD.derivative(ad, exp, 1.)
           display(ad.ruleconfig.context.cache)
           AD.derivative(ad, exp, 1.)
           display(ad.ruleconfig.context.cache)
       end
IdDict{Any, Any} with 3 entries:
  Box(true)    => RefValue{Any}((contents = nothing,))
  Box(2.71828) => RefValue{Any}((contents = nothing,))
  Box(2.71828) => RefValue{Any}((contents = nothing,))
IdDict{Any, Any} with 6 entries:
  Box(2.71828) => RefValue{Any}((contents = nothing,))
  Box(2.71828) => RefValue{Any}((contents = nothing,))
  Box(true)    => RefValue{Any}((contents = nothing,))
  Box(2.71828) => RefValue{Any}((contents = nothing,))
  Box(true)    => RefValue{Any}((contents = nothing,))
  Box(2.71828) => RefValue{Any}((contents = nothing,))

I have a non-MWE where this seems to cause an error, but the error is gone if I manually wipe it. Not sure if it could also cause subtly wrong results. Perhaps it should be wiped before or after each pullback call?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment