Skip to content

Commit 522f66a

Browse files
committed
eager accumulation
1 parent 5e5d5db commit 522f66a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/interface.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ subtract!(x, x̄) = maywrite(x) ? (x .= x .- x̄) : eltype(x).(x .- x̄)
6060

6161
grads!(dict::IdDict, ℓ::Leaf, x, ::Zero) = nothing
6262
function grads!(dict::IdDict, ℓ::Leaf, x, x̄)
63-
x̄₀ = get(dict, ℓ, false)
64-
dict[ℓ] = Broadcast.broadcasted(+, x̄, x̄₀)
63+
x̄₀ = get(dict, ℓ, ZeroTangent())
64+
dict[ℓ] = + x̄₀ # adding Zero should be free. Lazy accumulation broadcasted(+, x̄, x̄₀) also possible.
6565
nothing
6666
end
6767
grads!(dict::IdDict, t, x, ::Zero) = nothing

0 commit comments

Comments
 (0)