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

Add DifferentiationInterface test suite #1563

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gdalle
Copy link
Contributor

@gdalle gdalle commented Jun 24, 2024

Prompted by #1562, this PR adds some tests from DifferentiationInterfaceTest to the Enzyme test suite.
Our test suite has caught numerous bugs in the past, so it would be a great asset to check that new Enzyme releases don't jeopardize existing behavior.

@wsmoses
Copy link
Member

wsmoses commented Jun 24, 2024

This was the result of a bad jll uptake yesterday, already caught by our existing CI, and has been fixed on main (and being released today).

I'm not opposed to this in principle but the tests need to provide actionable feedback of Enzyme-specific MWE's.

In any case since the existing suite caught this already, I'm going to assume the need for is moot and close. Feel free to re-open if you'd like.

@wsmoses wsmoses closed this Jun 24, 2024
@gdalle
Copy link
Contributor Author

gdalle commented Jun 24, 2024

I can't reopen a PR you closed.

In any case since the existing suite caught this already, I'm going to assume the need for is moot and close.

This specific bug was caught by your CI, but others may not be, and others have not been in the past. For instance, by using our type stability checks, you would have been able to catch #1401 right away.

I'm not opposed to this in principle but the tests need to provide actionable feedback of Enzyme-specific MWE's.

What do you mean by this? Test failures in DifferentiationInterfaceTest are already fairly verbose and precise, take a look at the stack trace here for instance: https://github.com/gdalle/DifferentiationInterface.jl/actions/runs/9644116325/job/26595528876

@wsmoses wsmoses reopened this Jun 24, 2024
@wsmoses
Copy link
Member

wsmoses commented Jun 24, 2024

We do generally add tests for any failures caught (so as an example the test you showed earlier led to us adding some inferred tests that should check the same).

I guess the source of my hesitation here is that while adding these as integration tests is useful as a signal that everything is fine or not, the feedback isn't actionable to an enzyme dev.

For example looking at the posted log:

Cotangent value: Test Failed at /home/runner/work/DifferentiationInterface.jl/DifferentiationInterface.jl/DifferentiationInterfaceTest/src/tests/correctness.jl:197
  Expression: dx1 ≈ scen.res1
   Evaluated: 0.0 ≈ 9.020996451098895

Stacktrace:
 [1] macro expansion
   @ /opt/hostedtoolcache/julia/1.10.4/x64/share/julia/stdlib/v1.10/Test/src/Test.jl:672 [inlined]
 [2] macro expansion
   @ ~/work/DifferentiationInterface.jl/DifferentiationInterface.jl/DifferentiationInterfaceTest/src/tests/correctness.jl:197 [inlined]
 [3] macro expansion
   @ /opt/hostedtoolcache/julia/1.10.4/x64/share/julia/stdlib/v1.10/Test/src/Test.jl:1577 [inlined]
 [4] macro expansion
   @ ~/work/DifferentiationInterface.jl/DifferentiationInterface.jl/DifferentiationInterfaceTest/src/tests/correctness.jl:197 [inlined]
 [5] macro expansion
   @ /opt/hostedtoolcache/julia/1.10.4/x64/share/julia/stdlib/v1.10/Test/src/Test.jl:1669 [inlined]
 [6] test_correctness(ba::AutoEnzyme{Nothing}, scen::DifferentiationInterfaceTest.Scenario{:pullback, 1, :outofplace, typeof(DifferentiationInterfaceTest.num_to_arr_vector), Float64, Vector{Float64}, Vector{Float64}, Float64, Nothing}; isapprox::typeof(isapprox), atol::Int64, rtol::Float64)
   @ DifferentiationInterfaceTest ~/work/DifferentiationInterface.jl/DifferentiationInterface.jl/DifferentiationInterfaceTest/src/tests/correctness.jl:180

I have no idea what the isolated function is, or the corresponding Enzyme.autodiff call which would correspond to it (required to successfully debug). If you would be able to print out a corresponding MWE with corresponding Enzyme.autodiff call which triggers that would be immensely useful.

Also fwiw, adding this test suite here would not catch the bug before added, since, like mentioned this happened downstream in the jll.

@gdalle
Copy link
Contributor Author

gdalle commented Jun 24, 2024

I have no idea what the isolated function is, or the corresponding Enzyme.autodiff call which would correspond to it (required to successfully debug).

Yeah, the stack trace is not very useful here, what I meant was the test summary at the end.
The summary below tells you that the failure happened during tests of AutoEnzyme() (which is either forward or reverse mode), for the pullback operator, in a Scenario involving the function num_to_arr_vector, where the operator was applied out-of-place. The primal value is correct, but the cotangent value is wrong.
You can find the definitions of default scenarios in this file:
https://github.com/gdalle/DifferentiationInterface.jl/blob/main/DifferentiationInterfaceTest/src/scenarios/default.jl

image

@gdalle
Copy link
Contributor Author

gdalle commented Jun 24, 2024

If you would be able to print out a corresponding MWE with corresponding Enzyme.autodiff call which triggers that would be immensely useful.

The issue is that it would require storing the result of every test somehow, instead of just relying on the nested @testset macros to do their job. We've had a lot of discussions with @adrhill on how to do that, and decided it was best to leave it alone, see gdalle/DifferentiationInterface.jl#109. Otherwise we'd have to define our own custom test set types, and everything becomes infinitely more complicated.

@wsmoses
Copy link
Member

wsmoses commented Jun 24, 2024

Yeah I mean like I said before that's nice as an integration test, but that level of summary isn't sufficient to be able to debug -- which really requires an MWE of the fn and the autodiff.

My hesitation here is that if someone has a PR which causes that to fail, they'd also have to look through a separate repo and have to try to disect what the failing code is, and how to reproduce it (after of course confirming whether that is indeed a bug or intended).

Given that the bar to contribution is already relatively high, I'm hesitant to force devs to have to bear that burden (hence the ask for it to spit out an isolatable MWE). Otherwise it'll just get ignored, at which point there isn't much value in a check (like the present formatter) which is always assumed failing and never checked.

@gdalle
Copy link
Contributor Author

gdalle commented Jun 24, 2024

Would it be enough if the test displayed a custom error message that gives you an MWE in DifferentiationInterface syntax? Something like:


To reproduce this behavior, run the following Julia code and inspect the result:

import Enzyme
using DifferentiationInterface, DifferentiationInterfaceTest

backend = AutoEnzyme()
f = DifferentiationInterfaceTest.num_to_arr_vector
x = 1.0
dy = float.(1:6)
pullback(f, backend, x, dy)

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.

None yet

2 participants