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

Fixup more than simple jacobian #1712

Merged
merged 10 commits into from
Aug 8, 2024
Merged

Fixup more than simple jacobian #1712

merged 10 commits into from
Aug 8, 2024

Conversation

wsmoses
Copy link
Member

@wsmoses wsmoses commented Aug 8, 2024

No description provided.

@wsmoses
Copy link
Member Author

wsmoses commented Aug 8, 2024

@swilliamson7 does this fix your jacobian case?

Copy link
Contributor

github-actions bot commented Aug 8, 2024

Benchmark Results

main ad01cc5... main/ad01cc558b5d4f...
basics/overhead 4.03 ± 0.001 ns 4.03 ± 0.01 ns 1
time_to_load 0.456 ± 0.00077 s 0.454 ± 0.0092 s 1.01

Benchmark Plots

A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.
Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).

@swilliamson7
Copy link
Collaborator

swilliamson7 commented Aug 8, 2024

@swilliamson7 does this fix your jacobian case?

What does the variable n_out_val mean exactly? It looks like I need to provide it.

julia> grad = jacobian(Reverse, compute_jacobian, S)
ERROR: MethodError: no method matching jacobian(::ReverseMode{false, FFIABI, false, false}, ::typeof(compute_jacobian), ::ShallowWaters.ModelSetup{Float32, Float32})

Closest candidates are:
  jacobian(::ReverseMode{ReturnPrimal, RABI, ErrIfFuncWritten}, ::F, ::X, ::Val{n_out_val}, ::Val{1}) where {F, X, n_out_val, ReturnPrimal, RABI<:EnzymeCore.ABI, ErrIfFuncWritten}
   @ Enzyme ~/.julia/packages/Enzyme/afdHl/src/Enzyme.jl:1302
  jacobian(::ReverseMode{ReturnPrimal, RABI, ErrIfFuncWritten}, ::F, ::X, ::Val{n_out_val}) where {F, X, n_out_val, ReturnPrimal, RABI<:EnzymeCore.ABI, ErrIfFuncWritten}
   @ Enzyme ~/.julia/packages/Enzyme/afdHl/src/Enzyme.jl:1302
  jacobian(::ReverseMode{ReturnPrimal, RABI, ErrIfFuncWritten}, ::F, ::X, ::Val{n_out_val}, ::Val{chunk}) where {F, X, chunk, n_out_val, ReturnPrimal, RABI<:EnzymeCore.ABI, ErrIfFuncWritten}
   @ Enzyme ~/.julia/packages/Enzyme/afdHl/src/Enzyme.jl:1253
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[8]:1

@wsmoses
Copy link
Member Author

wsmoses commented Aug 8, 2024

it's the number of outputs

@swilliamson7
Copy link
Collaborator

If f doesn't necessarily return an array but rather a structure, what would I put? Or should I define f to return an array (say my state variable)?

@wsmoses
Copy link
Member Author

wsmoses commented Aug 8, 2024

@swilliamson7 just pushed a version which computes n_outs for you.

Currently reverse mode jacobian allows any input type, but requires an array output type.
Currently forward mode jacobian allows any output type, but requires an array or scalar input type.

@swilliamson7
Copy link
Collaborator

@swilliamson7 just pushed a version which computes n_outs for you.

Currently reverse mode jacobian allows any input type, but requires an array output type. Currently forward mode jacobian allows any output type, but requires an array or scalar input type.

I saw! That was speedy lol, it doesn't seem like I can test it yet, or at least updating Enzyme doesn't bring any changes. I'm guessing I need to wait for the checks to pass or something?

@wsmoses wsmoses merged commit 2b681d5 into main Aug 8, 2024
33 of 56 checks passed
@wsmoses wsmoses deleted the jacfx branch August 8, 2024 19:44
@wsmoses
Copy link
Member Author

wsmoses commented Aug 8, 2024

@swilliamson7 it was just merged to main, so you now should be able to just do add Enzyme#main

@swilliamson7
Copy link
Collaborator

I got a fun blank-ish error,

julia> grad = jacobian(Reverse, compute_jacobian, S)
ERROR: MethodError: no method matching (ReverseMode{false, FFIABI, false})()
Stacktrace:
 [1] jacobian(::ReverseMode{false, FFIABI, false, false}, f::typeof(compute_jacobian), x::ShallowWaters.ModelSetup{Float32, Float32})
   @ Enzyme ~/.julia/packages/Enzyme/BkuKz/src/Enzyme.jl:1500
 [2] top-level scope
   @ REPL[13]:1

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