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

Basic example doesn't work with Pluto notebooks #112

Open
VarLad opened this issue Jun 27, 2022 · 1 comment
Open

Basic example doesn't work with Pluto notebooks #112

VarLad opened this issue Jun 27, 2022 · 1 comment

Comments

@VarLad
Copy link

VarLad commented Jun 27, 2022

image

Whereas it works normally in the REPL

@dfdx
Copy link
Owner

dfdx commented Jun 29, 2022

Thanks for reporting this! It turns out, Pluto adds some magic to the call so it's traced differently from a normal REPL. In REPL:

julia> Yota.Umlaut.trace(x -> sum(x .+ 1), [1.0, 2.0, 3.0])
(9.0, Tape{BaseCtx}
  inp %1::var"#101#102"
  inp %2::Vector{Float64}
  %3 = broadcasted(+, %2, 1)::Broadcasted{}
  %4 = materialize(%3)::Vector{Float64}
  %5 = sum(%4)::Float64
)

In Pluto:

(9.0,
Tape{Umlaut.BaseCtx}
  inp %1::var"#3#4"{typeof(+), typeof(sum)}
  inp %2::Vector{Float64}
  %3 = getfield(%1, :sum)::typeof(sum)                # <---
  %4 = getfield(%1, :+)::typeof(+)                         # <---
  %5 = broadcasted(%4, %2, 1)::Broadcasted{}
  %6 = materialize(%5)::Vector{Float64}
  %7 = %3(%6)::Float64)

One workaround is to define the missing rrule:

using ChainRulesCore

ChainRulesCore.rrule(getfield, x, f::Symbol) = (getfield(x, f), dy -> (NoTangent(), NoTangent(), NoTangent()))

After this the example gives the correct result:

grad(x -> sum(x .+ 1), [1.0, 2.0, 3.0])
# ==> (9.0, (NoTangent(), [1.0, 1.0, 1.0]))

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

2 participants