-
Notifications
You must be signed in to change notification settings - Fork 89
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
Conversation
function unbroadcast(x::Base.AbstractArrayOrBroadcasted, dx_raw) | ||
dx = unthunk(dx_raw) | ||
N = ndims(dx) | ||
N = _ndims(dx) |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...) |
There was a problem hiding this comment.
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
Companion to JuliaDiff/Diffractor.jl#89