JuliaDiff / JuliaDiff/ChainRules.jl

`f/rrules` should support receiving `ZeroTangent()`

Open
#442 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

design needs-careful-thought
Dominant language
Julia
Stars
475
Forks
98
PR merge metrics
No merged PRs in 30d

Description

Similarly to https://github.com/JuliaDiff/ChainRules.jl/issues/408, ZeroTangent() is a valid input to the pullback, and we need to make sure it is supported.

Using https://github.com/JuliaDiff/ChainRulesTestUtils.jl/pull/176, there are at least three kinds of errors:

  1. Pullbacks are written such that they do not support taking in ZeroTangent(), e.g.
    MethodError: no method matching (::ChainRules.var"#transpose_pullback#1894")(::ZeroTangent). These just need to be fixed in ChainRules.jl
  2. Places where we (I think?) have to project the ZeroTangent():
    TypeError: in Hermitian, in S, expected S<:(AbstractArray{var"#s832", 2} where var"#s832"<:T), got Type{ZeroTangent}
    and
MethodError: Cannot `convert` an object of type 
    ZeroTangent to an object of type 
    Matrix{T} where T
  1. Errors which could be solved by projecting the ZeroTangent() e.g.
    MethodError: no method matching getindex(::ZeroTangent, ::Int64). The question is whether we actually want to project to an array, since that would allocate quite a bit. Alternatively, we could define Base.getindex(::ZeroTangent, args...) = ZeroTangent(). There might be quite a few of these functions to define, but it would be much faster.
    Some examples are:
  • MethodError: no method matching Complex(::ZeroTangent)
  • MethodError: no method matching mapfoldl(::typeof(identity), ::typeof(Base.add_sum), ::ZeroTangent; dims=Colon())
  • MethodError: no method matching tr(::ZeroTangent)
  • MethodError: no method matching mul!(::ZeroTangent, ::Matrix{Float64}, ::ZeroTangent, ::Bool, ::Bool)
  • MethodError: no method matching trsyl!(::Char, ::Char, ::Matrix{ComplexF64}, ::Matrix{ComplexF64}, ::ZeroTangent)
  • MethodError: no method matching size(::ZeroTangent, ::Int64)
  • MethodError: no method matching LowerTriangular(::ZeroTangent)
    and the list goes on

This is just a quick (incomplete) dump of observations and first thoughts. I may have missed kinds of errors, or said things which are untrue.

Alltogether:

Test Summary:     |  Pass  Error  Broken  Total
ChainRules          | 24330   429    4    24763

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 the failures gathered through ChainRulesTestUtils PR 176 and inspect the affected ChainRules.jl pullbacks and ZeroTangent handling. Reproduce the reported errors, determine which cases should project ZeroTangent versus support it directly, and consider the work done when the relevant test errors are resolved without unacceptable allocation tradeoffs.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
devtools
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.