JuliaDiff / JuliaDiff/ChainRules.jl
Rule for `vect` unthunks many times
Open
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 475
- Forks
- 98
- PR merge metrics
- No merged PRs in 30d
Description
This:
using ChainRulesCore
myplus(x,y) = x + y
function ChainRulesCore.rrule(::typeof(myplus), x, y)
println("myplus rrule forward")
x+y, dz -> begin
println("myplus rrule reverse, dz isa ", typeof(dz))
NoTangent(), @thunk(unthunk(dz)), @thunk @show unthunk(dz)
end
end
using Yota
grad([1,2,3]) do x
prod(myplus(x, [4,5,6]))
end
prints this:
myplus rrule forward
myplus rrule reverse, dz isa InplaceableThunk{Thunk{ChainRules.var"#1675#1678"{Float64, Colon, Vector{Float64}, ProjectTo{AbstractArray, NamedTuple{(:element, :axes), Tuple{ProjectTo{Float64, NamedTuple{(), Tuple{}}}, Tuple{Base.OneTo{Int64}}}}}, Float64}}, ChainRules.var"#1674#1677"{Float64, Colon, Vector{Float64}, Float64}}
unthunk(dz) = [63.0, 45.0, 35.0]
unthunk(dz) = [63.0, 45.0, 35.0] # from @show dz inside the @thunk, runs 3 times
unthunk(dz) = [63.0, 45.0, 35.0]
(315.0, (ZeroTangent(), [63.0, 45.0, 35.0]))
Almost all rules should call unthunk exactly once on their input, maybe others make the same mistake, e.g. hvcat?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the ChainRulesCore and Yota example from the issue, then inspect the rules involved in the shown stack and suspected cases such as hvcat for repeated unthunk calls. Done means affected rules unthunk their inputs only once and the reproduction no longer prints repeated evaluations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100