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

Minor broadcasting fixes #673

Merged
merged 5 commits into from
Sep 4, 2022
Merged

Minor broadcasting fixes #673

merged 5 commits into from
Sep 4, 2022

Conversation

mcabbott
Copy link
Member

@mcabbott mcabbott commented Sep 1, 2022

Comment on lines 323 to +325
function unbroadcast(x::Base.AbstractArrayOrBroadcasted, dx_raw)
dx = unthunk(dx_raw)
N = ndims(dx)
N = _ndims(dx)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one has a test, lazy broadcasting of - means this can be called with dx::Tuple

Comment on lines 133 to 143
function back_generic(dys)
deltas = unzip_broadcast(backs, unthunk(dys)) do back, dy # (could be map, sizes match)
deltas = unzip_broadcast(backs, dys) do back, dy # (could be map, sizes match)
map(unthunk, back(dy))
end
dargs = map(unbroadcast, args, Base.tail(deltas))
df = ProjectTo(f)(sum(first(deltas)))
return (NoTangent(), NoTangent(), df, dargs...)
end
back_generic(dys::AbstractThunk) = back_generic(unthunk(dys))
back_generic(z::AbstractZero) = (TRI_NO..., map(Returns(z), args)...)
return ys3, back_generic
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow Diffractor fed this pullback a thunk containing a ZeroTangent. And... well maybe I tried this with #671 which changes this to unzip_map, and that was not happy about the zero. So I changed them all to have 3 methods, not two.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now some removed, as this caused inference problems.

@non_differentiable Base.CoreLogging.current_logger_for_env(::Any...)
@non_differentiable Base.CoreLogging._invoked_shouldlog(::Any...)
@non_differentiable Base.CoreLogging.Base.fixup_stdlib_path(::Any)
@non_differentiable Base.CoreLogging.handle_message(::Any...)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fix this -- a second derivative notices @debug inside rules, and fails.

julia> gradient([1,2,3]) do x
         gradient(x) do y
           sum(y .* y)
         end[1] |> sum
       end
ERROR: (1, current_logger_for_env(std_level::Base.CoreLogging.LogLevel, group, _module) @ Base.CoreLogging logging.jl:500, :($(Expr(:meta, :noinline))))
Stacktrace:
  [1] error(s::Tuple{Int64, Method, Expr})
    @ Base ./error.jl:44
  [2] transform!(ci::Core.CodeInfo, meth::Method, nargs::Int64, sparams::Core.SimpleVector, N::Int64)
    @ Diffractor ~/.julia/dev/Diffractor/src/stage1/recurse.jl:621
  [3] perform_optic_transform(ff::Type{Diffractor.∂⃖recurse{1}}, args::Any)
    @ Diffractor ~/.julia/dev/Diffractor/src/stage1/generated.jl:25

@mcabbott mcabbott merged commit 5855c10 into JuliaDiff:main Sep 4, 2022
@mcabbott mcabbott deleted the broadcast3 branch September 4, 2022 20:28
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.

2 participants