Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Test against Enzyme #318
Test against Enzyme #318
Changes from 1 commit
175f382
89a3267
961aeb6
f33da48
28beac5
1239040
94023a1
7860701
3cf5e79
2163ec4
8654475
e43d71e
deec0a6
cd3000a
5ac4583
44bd739
976874b
f5fd835
41d643c
5124bd7
73711d6
04d98e9
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? Shouldn't Enzyme return the correct types automatically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In forward mode it returns tuples, and if the gradient is empty, the result is a
Tuple{}
. This resulted in comparing an emptyFloat64[]
to an emptyUnion{}[]
, which failed. See EnzymeAD/Enzyme.jl#1584There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the gradient should never be empty? Such a test would be quite useless, so I assume we don't run into this special case here? So maybe a simple
collect
(without specifying the element type) would be sufficient?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a corner case, but we ran into it here, when
d==1
:Bijectors.jl/test/bijectors/corr.jl
Line 5 in 8654475
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest not testing AD in the case
d = 1
- or just checking that the gradient is empty. We already handle this case in a special way in e.g.Bijectors.jl/test/bijectors/corr.jl
Lines 32 to 33 in 8654475
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It passes now though, and I don't really see a downside to testing it? Good to know for instance that nothing crashes even if you hit this corner case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I also would prefer to not remove the test completely (even though I think it's of very limited use)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what the current test is effectively doing, because when
d = 1
finitediff returns an empty array. Theeltype
thing just makes sure that the check becomesFloat64[] == Float64[]
, rather thanUnion{}[] == Float64[]
. We could put in a specific case ford == 1
in the test file, but this seems like more work to me, because you need to make it cater to different AD backends and specify manually that the result should be empty.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant something differently - removing the
eltype
/collect
completely and only add a special case to this weird test of theCorrBijector
since we already have special cases ford = 1
there anyway.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's how I understood you, but that would require something like adding another argument to
test_ad
calledexpect_empty
that would skip comparing to finitediff and instead check that the gradient has length 1 (for all AD backends) and setting that argument tod == 1
, which to me seems more complicated, with a bunch ofif
statements, compared adding the one-liner enforcingeltype
. I can do it if you prefer it, I just don't see the benefit.