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

rename ChainRules differential types #974

Merged
merged 3 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.jl.mem
docs/build
Manifest.toml
dev/
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Zygote"
uuid = "e88e6eb3-aa80-5325-afca-941959d7151f"
version = "0.6.10"
version = "0.6.11"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand All @@ -24,7 +24,7 @@ ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444"
[compat]
AbstractFFTs = "0.5, 1.0"
ChainRules = "0.7.55"
ChainRulesCore = "0.9.32"
ChainRulesCore = "0.9.44"
DiffRules = "1.0"
FillArrays = "0.8, 0.9, 0.10, 0.11"
ForwardDiff = "0.10"
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ for T_outer in (:Tuple, :NamedTuple)
# we create separate methods rather than using a `Union` + an `if` so that we avoid a
# branch that changes output type, because nested AD on that kinda thing makes Zygote less
# than happy.
@eval @inline function wrap_chainrules_output(x::ChainRules.Composite{P, T}) where {P, T<:$T_outer}
@eval @inline function wrap_chainrules_output(x::ChainRules.Tangent{P, T}) where {P, T<:$T_outer}
xp = map(wrap_chainrules_output, canonicalize(x))
convert($T_outer, xp)
end
Expand All @@ -59,10 +59,10 @@ end
Convert `x` from the format Zygote uses internally to differentials types ChainRules uses.
"""
@inline wrap_chainrules_input(x) = x
@inline wrap_chainrules_input(::Nothing) = ChainRules.Zero()
@inline wrap_chainrules_input(::Nothing) = ChainRules.ZeroTangent()
@inline function wrap_chainrules_input(xs::Union{Tuple, NamedTuple})
xp = map(wrap_chainrules_input, xs)
ChainRules.Composite{Any, typeof(xp)}(xp)
ChainRules.Tangent{Any, typeof(xp)}(xp)
end

"""
Expand Down
4 changes: 2 additions & 2 deletions test/chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ using Zygote, Test, ChainRules
not_diff_eg(x, i) = [10, 20][i]
function ChainRules.rrule(::typeof(not_diff_eg), x, i)
function not_diff_eg_pullback(Δ)
return ChainRules.NO_FIELDS, ChainRules.Zero(), ChainRules.DoesNotExist()
return ChainRules.NO_FIELDS, ChainRules.ZeroTangent(), ChainRules.NoTangent()
end
return not_diff_eg(x, i), not_diff_eg_pullback
end
Expand Down Expand Up @@ -204,7 +204,7 @@ using Zygote, Test, ChainRules
not_diff_kw_eg(x, i; kw=1.0) = [10, 20][i]
function ChainRules.rrule(::typeof(not_diff_kw_eg), x, i; kwargs...)
function not_diff_kw_eg_pullback(Δ)
return ChainRules.NO_FIELDS, ChainRules.Zero(), ChainRules.DoesNotExist()
return ChainRules.NO_FIELDS, ChainRules.ZeroTangent(), ChainRules.NoTangent()
end
return not_diff_kw_eg(x, i; kwargs...), not_diff_kw_eg_pullback
end
Expand Down