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

Handle ChainRulesCore.NotImplemented #1205

Merged
merged 1 commit into from
Apr 13, 2022
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
2 changes: 1 addition & 1 deletion 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.37"
version = "0.6.38"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
1 change: 1 addition & 0 deletions src/compiler/chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Convert `x` from the differentials types ChainRules uses to the format Zygote us
# Zygote convention: even if many AbstractZero partials (i.e. multi-input function), make just 1 nothing.
@inline wrap_chainrules_output(x::Tuple{Vararg{ChainRules.AbstractZero}}) = nothing
@inline wrap_chainrules_output(x::ChainRules.AbstractZero) = nothing
@inline wrap_chainrules_output(x::ChainRulesCore.NotImplemented) = nothing
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
Expand Down
12 changes: 12 additions & 0 deletions test/chainrules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,18 @@ using Zygote: ZygoteRuleConfig
@test (1.0,) == Zygote.gradient(oout_id_outer, π)
@test oout_id_rrule_hitcount[] == 0
end

# issue #1204
@testset "NotImplemented" begin
f_notimplemented(x) = x
@scalar_rule f_notimplemented(x) @not_implemented("not implemented :(")
@test Zygote.gradient(f_notimplemented, 0.1) === (nothing,)
@test Zygote.gradient(x -> f_notimplemented(x[1]), 0.1) === (nothing,)
if isdefined(Base, :only)
@test Zygote.gradient(x -> f_notimplemented(only(x)), (0.1,)) === (nothing,)
@test Zygote.gradient(x -> f_notimplemented(only(x)), [0.1]) === (nothing,)
end
end
end

@testset "ChainRulesCore.rrule_via_ad" begin
Expand Down