-
-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1358: Fix BPTT by overriding stateful broadcast adjoint r=DhairyaLGandhi a=DhairyaLGandhi Fixes #1209 In this PR, we replace the regular broadcasting adjoint with that of the `map` equivalent which is better tested in terms of stateful cases. We ultimately will revert back to the broadacasting adjoint via FluxML/Zygote.jl#807 but this specialises the case for recurrent layers @oxinabox @ToucheSir Comments? ### PR Checklist - [x] Tests are added - [ ] Entry in NEWS.md - [x] Documentation, if applicable - [ ] Final review from `@dhairyagandhi96` (for API changes). Co-authored-by: Dhairya Gandhi <dhairya@juliacopmuting.com>
- Loading branch information
Showing
3 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Ref FluxML/Flux.jl#1209 | ||
@testset "BPTT" begin | ||
seq = [rand(2) for i = 1:3] | ||
for r ∈ [RNN,] | ||
rnn = r(2,3) | ||
Flux.reset!(rnn) | ||
grads_seq = gradient(Flux.params(rnn)) do | ||
sum(rnn.(seq)[3]) | ||
end | ||
Flux.reset!(rnn); | ||
bptt = gradient(Wh->sum(tanh.(rnn.cell.Wi * seq[3] + Wh * | ||
tanh.(rnn.cell.Wi * seq[2] + Wh * | ||
tanh.(rnn.cell.Wi * seq[1] + | ||
Wh * rnn.init | ||
+ rnn.cell.b) | ||
+ rnn.cell.b) | ||
+ rnn.cell.b)), | ||
rnn.cell.Wh) | ||
@test grads_seq[rnn.cell.Wh] ≈ bptt[1] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters