JuliaDiff / JuliaDiff/ChainRulesTestUtils.jl

Check for repeated unthunking

Open
#262 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Julia
Stars
50
Forks
18
PR merge metrics
No merged PRs in 30d

Description

test_rrule checks that the rule accepts thunks.

Should it also check that these aren't accidentally un-thunked more than once, by some passing in some @thunk (COUNT[+=1]; val) thing? That's a mistake although not a wrong-answers one, just slow. As seen in https://github.com/JuliaDiff/ChainRules.jl/pull/670

julia> using ChainRulesCore, ChainRulesTestUtils

julia> plus(x,y) = x+y;

julia> unplus(z) = (NoTangent(), z, z);

julia> unplus(::AbstractThunk) = error("fails");

julia> ChainRulesCore.rrule(::typeof(plus), x, y) = x+y, unplus;

julia> test_rrule(plus, [1.0], [2.0])
test_rrule: plus on Vector{Float64},Vector{Float64}: Error During Test at /Users/me/.julia/packages/ChainRulesTestUtils/YbVdW/src/testers.jl:193
  Got exception outside of a @test
  fails

julia> unplus(z::AbstractThunk) = (NoTangent(), unthunk(@show z), @show unthunk(z))

julia> test_rrule(plus, [1.0], [2.0]);
z = Thunk(ChainRulesTestUtils.var"#61#65"{Vector{Float64}}([1.73]))
unthunk(z) = [1.73]
z = Thunk(ChainRulesTestUtils.var"#62#66"{Vector{Float64}}([1.73]))
unthunk(z) = [1.73]
Test Summary:                                       | Pass  Total  Time
test_rrule: plus on Vector{Float64},Vector{Float64} |    9      9  0.0s

Going further, should it also reject (or warn about) unplus(z::AbstractThunk) = (NoTangent(), z, z);? If what's returned contains exactly the same thunk it got, in more than one place, then it's likely that further steps will unthunk twice.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with test_rrule in testers.jl around the reported failure at line 193, and review ChainRules.jl pull request 670 for the repeated-unthunking behavior. Define expected handling for thunks that are unthunked more than once and for the same thunk returned in multiple places, then add regression coverage showing the chosen behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.