Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Composite of SVD #390

Merged
merged 10 commits into from
Mar 25, 2021
Merged

Fix Composite of SVD #390

merged 10 commits into from
Mar 25, 2021

Conversation

mzgubic
Copy link
Member

@mzgubic mzgubic commented Mar 23, 2021

Closes #389 , closes #106

Copy link
Member

@sethaxen sethaxen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just minor comments. Feel free to merge when ready.

test/rulesets/LinearAlgebra/factorization.jl Outdated Show resolved Hide resolved
test/rulesets/LinearAlgebra/factorization.jl Outdated Show resolved Hide resolved
@mzgubic
Copy link
Member Author

mzgubic commented Mar 24, 2021

I've modernised the tests from the manual finite differences tests to the new test_rrule interface. Would you like to take another look?

Copy link
Member

@sethaxen sethaxen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. It's nice that it uses test_rrule now as well. Feel free to merge if all non-nightly tests pass.

@codecov-io
Copy link

codecov-io commented Mar 24, 2021

Codecov Report

Merging #390 (285977b) into master (76ef95c) will decrease coverage by 10.69%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master     #390       +/-   ##
===========================================
- Coverage   98.45%   87.76%   -10.70%     
===========================================
  Files          20       20               
  Lines        1745     1291      -454     
===========================================
- Hits         1718     1133      -585     
- Misses         27      158      +131     
Impacted Files Coverage Δ
src/rulesets/LinearAlgebra/factorization.jl 95.52% <100.00%> (-2.31%) ⬇️
src/rulesets/Base/evalpoly.jl 0.00% <0.00%> (-97.81%) ⬇️
src/rulesets/Base/utils.jl 0.00% <0.00%> (-80.00%) ⬇️
src/ChainRules.jl 66.66% <0.00%> (-33.34%) ⬇️
src/rulesets/Statistics/statistics.jl 66.66% <0.00%> (-24.25%) ⬇️
src/rulesets/LinearAlgebra/utils.jl 66.66% <0.00%> (-21.57%) ⬇️
src/rulesets/LinearAlgebra/symmetric.jl 84.15% <0.00%> (-15.47%) ⬇️
src/rulesets/LinearAlgebra/structured.jl 92.04% <0.00%> (-7.96%) ⬇️
src/rulesets/LinearAlgebra/norm.jl 98.26% <0.00%> (-1.74%) ⬇️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 76ef95c...285977b. Read the comment docs.

@mzgubic mzgubic merged commit 67c106f into master Mar 25, 2021
@mzgubic mzgubic deleted the mz/svd2 branch March 25, 2021 09:32
bors bot added a commit to FluxML/Zygote.jl that referenced this pull request Mar 25, 2021
926: Canonicalize the Composite before changing it to a NamedTuple r=oxinabox a=mzgubic

Closes #922.

The issue occurs when the following are all true:
1) We have a struct with two differentiable fields
2) We need to accumulate the gradients with respect to both fields
3) The gradients that need to be accumulated both originate from an rrule

In that case, the two gradients that originate from an rrule are `Composite`s with disjoint fields. When they are transformed to a `NamedTuple`, the Zygote internal representation of derivatives w.r.t. structs, these two `NamedTuple`s have disjoint sets of keys, and are not `accum`ulated correctly.

By adding `canonicalize(x)`, the `Composite` gets explicit `Zero()` fields, which means the resulting `NamedTuple`s have the complete set of fields. 

~~- blocked by JuliaDiff/ChainRules.jl#390 (tests only)~~
~~- need to change compat once the above is merged~~

Co-authored-by: Miha Zgubic <[email protected]>
Co-authored-by: Miha Zgubic <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Canonicalize Composite{SVD} Define rrule for SVD.Vt
3 participants