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

Allow NotImplemented tangents for things that have a correct tangent of NoTangent #218

Merged
merged 8 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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 = "ChainRulesTestUtils"
uuid = "cdddcdb0-9152-4a09-a978-84456f9df70a"
version = "1.2.2"
version = "1.2.3"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
9 changes: 8 additions & 1 deletion src/testers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,14 @@ function test_rrule(
"The pullback in the rrule should use NoTangent()" *
" rather than ZeroTangent() for non-perturbable arguments.",
)
@test ad_cotangent isa NoTangent # we said it wasn't differentiable.
if ad_cotangent isa ChainRulesCore.NotImplemented
# this situation can occur if a cotangent is not implemented and
# the default `rand_tangent` is `NoTangent`:
devmotion marked this conversation as resolved.
Show resolved Hide resolved
# https://github.com/JuliaDiff/ChainRulesTestUtils.jl/issues/217
@test_broken ad_cotangent isa NoTangent
else
@test ad_cotangent isa NoTangent # we said it wasn't differentiable.
end
else
ad_cotangent isa AbstractThunk && check_inferred && _test_inferred(unthunk, ad_cotangent)

Expand Down
10 changes: 10 additions & 0 deletions test/testers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,16 @@ struct MySpecialConfig <: RuleConfig{Union{MySpecialTrait}} end
@scalar_rule f_notimplemented(x, y) (@not_implemented(""), 1) (1, -1)
test_frule(f_notimplemented, randn(), randn())
test_rrule(f_notimplemented, randn(), randn())

f_notimplemented2(f, x) = 2 * f(x)
function ChainRulesCore.rrule(::typeof(f_notimplemented2), f::typeof(identity), x)
Ω = f_notimplemented2(f, x)
function f_notimplemented2_pullback(Ω̄)
return NoTangent(), @not_implemented("TODO: implement this!"), 2 * Ω̄
end
return Ω, f_notimplemented2_pullback
end
test_rrule(f_notimplemented2, identity, randn())
end

@testset "custom rrule_f" begin
Expand Down