-
Notifications
You must be signed in to change notification settings - Fork 68
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
Computing third order derivatives #1707
Comments
This is likely the same as #1173, the goal is that JuliaGPU/GPUCompiler.jl#599 will fix this. |
Closing in favor of JuliaGPU/GPUCompiler.jl#629 |
This will now work nicely automatically once #2161 lands! using Enzyme
using StaticArrays
function g(x) # Some function to be differentiated
x[1]^4 + x[1]^7 + x[2]^4 + x[1]^2 * x[2]^2
end
# Enzyme.jl derivatives
dg(x, dx) = autodiff(Forward, g, Duplicated, Duplicated(x, dx))
ddg(x, dx, ddx) = autodiff(Forward, dg, Duplicated, Duplicated(x, dx), Duplicated(dx, ddx))
dddg(x, dx, ddx, dddx) = autodiff(Forward, ddg, Duplicated, Duplicated(x, dx),
Duplicated(dx, ddx), Duplicated(ddx, dddx))
# Get random inputs for x and some directions for the directional derivatives
x = SVector{2}(rand(2)); dx = SVector{2}(rand(2)); ddx = SVector{2}(rand(2)); dddx = SVector{2}(rand(2))
# Call the functions with inputs
dg(x, dx) # Works
ddg(x, dx, ddx) # Works
dddg(x, dx, ddx, dddx) # Works now |
using Enzyme
function d(f)
return x -> (autodiff(Forward, Const(f), Duplicated(x, 1.0))[1])
end
@show sin(2.0)
@show d(sin)(2.0)
@show d(d(sin))(2.0)
@show d(d(d(sin)))(2.0)
@show d(d(d(d(sin))))(2.0)
@show d(d(d(d(d(sin)))))(2.0)
@show d(d(d(d(d(d(sin))))))(2.0) |
Finally fixed by #2161 |
Thanks for all your effort. I tested it for my application involving third derivatives, and it works exactly as I would like it to! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am able to go up to second order derivatives with Enzyme. However, when I use the same approach to go for the third derivative, I get an error. Here is a minimal working example to show that. The last function call (supposed to compute the third order derivative) gives the error.
The error message is below.
Error message
I am using Enzyme v0.12.27.
versioninfo()
Julia Version 1.10.3
Commit 0b4590a5507 (2024-04-30 10:59 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 80 × Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, skylake-avx512)
Threads: 1 default, 0 interactive, 1 GC (on 80 virtual cores)
Environment:
JULIA_EDITOR =
JULIA_NUM_THREADS = 1
The text was updated successfully, but these errors were encountered: