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

Start testing reverse mode #254

Merged
merged 13 commits into from
Feb 8, 2024
Merged

Start testing reverse mode #254

merged 13 commits into from
Feb 8, 2024

Conversation

nmheim
Copy link
Contributor

@nmheim nmheim commented Jan 29, 2024

Adds tests for Base taken from Zygote. There will be quite a few more tests coming in, probably in a new PR (essentially planning to updated/split #73 into smaller MRs). Many of the added tests are currently broken (with the error message in the comment above the broken test).

Two main takeaways so far are: kwargs seem to break tests with one of two errors:

    # MethodError: no method matching copy(::Nothing)
    # Rewrite reached intrinsic function bitcast. Missing rule?

and then there are a few tests that return incorrect gradients.

Is there a good place to keep the main problems of the broken tests?

In #73 the pullback function from Zygote is kept, should we keep it or rewrite those tests in a different way?

Copy link

codecov bot commented Jan 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (6f1bdf0) 55.11% compared to head (6c9048c) 55.29%.
Report is 35 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #254      +/-   ##
==========================================
+ Coverage   55.11%   55.29%   +0.17%     
==========================================
  Files          28       28              
  Lines        2892     2917      +25     
==========================================
+ Hits         1594     1613      +19     
- Misses       1298     1304       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@oxinabox
Copy link
Member

In #73 the pullback function from Zygote is kept, should we keep it or rewrite those tests in a different way?

Let's rename it to value_and_pullback following the name it will get once we hook it up to AbstractDifferentiation.

FYI: he name "hobbit" for this is a reference to to

The Hobbit, or There and Back Again is a children's fantasy novel by English author J. R. R. Tolkien.

Hobbit == There and Back Again

@oxinabox
Copy link
Member

Is there a good place to keep the main problems of the broken tests?

I tend to do what you are doing
Comment above.
Plus I also will normally create an issue on the repo and link to it in the comment if we are going to merge with the tests still marked as broken

Comment on lines 322 to 323
BB = zero(a)
BB[inds...] = unthunk(Δ)
view(BB, inds...) .+= unthunk(Δ)
Copy link
Member

Choose a reason for hiding this comment

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

why is this different?
0 .+ Δ = Δ at least assuming they are the same size

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sorry, I should have added a comment here. this is for cases like

julia> gradient(sum  x -> x[:,[1,1,2]], rand(3,4))[1]
3×4 Matrix{Float64}:
 2.0  1.0  0.0  0.0
 2.0  1.0  0.0  0.0
 2.0  1.0  0.0  0.0

The view lets one add duplicate indices

julia> x = zeros(3,4)
3×4 Matrix{Float64}:
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

julia> view(x, :, [1,1,2]) .+= ones(3,3)
3×3 view(::Matrix{Float64}, :, [1, 1, 2]) with eltype Float64:
 2.0  2.0  1.0
 2.0  2.0  1.0
 2.0  2.0  1.0

julia> x
3×4 Matrix{Float64}:
 2.0  1.0  0.0  0.0
 2.0  1.0  0.0  0.0
 2.0  1.0  0.0  0.0

Copy link
Member

Choose a reason for hiding this comment

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

oh cool trick. I think last time i needed to handle that my solution was way more complicated.

@oxinabox
Copy link
Member

oxinabox commented Feb 7, 2024

I think we should merge this more or less as is and then can continue with follow up PRs to add more tests / fix existing broken ones.
What do you think?

@nmheim
Copy link
Contributor Author

nmheim commented Feb 7, 2024

I think we should merge this more or less as is and then can continue with follow up PRs to add more tests / fix existing broken ones. What do you think?

Yes, that sounds good! I can also open another PR with the view fix. its a little obscure (and stolen from zygote). maybe it would be better to have a non-mutating version of it?

@oxinabox
Copy link
Member

oxinabox commented Feb 8, 2024

maybe it would be better to have a non-mutating version of it?

It's fine for now.
Can do that later

@oxinabox oxinabox merged commit e702e32 into JuliaDiff:main Feb 8, 2024
8 checks passed
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.

2 participants