-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,13 +128,14 @@ function split_bc_pullbacks(cfg::RCR, f::F, args::Vararg{Any,N}) where {F,N} | |
rrule_via_ad(cfg, f, a...) | ||
end | ||
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 | ||
end | ||
|
@@ -318,7 +319,7 @@ rrule(::typeof(broadcasted), ::typeof(complex), x::Number) = rrule(complex, x) | | |
|
||
function unbroadcast(x::Base.AbstractArrayOrBroadcasted, dx_raw) | ||
dx = unthunk(dx_raw) | ||
N = ndims(dx) | ||
N = _ndims(dx) | ||
Comment on lines
320
to
+322
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one has a test, lazy broadcasting of |
||
if length(x) == length(dx) | ||
ProjectTo(x)(dx) # handles trivial reshapes, offsets, structured matrices, row vectors | ||
else | ||
|
@@ -328,6 +329,9 @@ function unbroadcast(x::Base.AbstractArrayOrBroadcasted, dx_raw) | |
end | ||
unbroadcast(x::Base.AbstractArrayOrBroadcasted, dx::AbstractZero) = dx | ||
|
||
_ndims(x) = ndims(x) | ||
_ndims(::Tuple) = 1 | ||
|
||
function unbroadcast(x::T, dx_raw) where {T<:Tuple{Vararg{Any,N}}} where {N} | ||
dx = unthunk(dx_raw) | ||
val = if N == length(dx) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -477,6 +477,11 @@ end | |
@non_differentiable Broadcast.result_style(::Any) | ||
@non_differentiable Broadcast.result_style(::Any, ::Any) | ||
|
||
@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 commentThe reason will be displayed to describe this comment to others. Learn more. These fix this -- a second derivative notices
|
||
|
||
@non_differentiable Libc.free(::Any) | ||
@non_differentiable Libc.getpid() | ||
@non_differentiable Libc.strptime(::AbstractString) | ||
|
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.