-
Notifications
You must be signed in to change notification settings - Fork 146
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
Compiletime for tensor very slow #278
Comments
I have the same issue and I'm wondering if there is any solution for this. |
ref #266 Playing around with It might be worth it to try removing all of ForwardDiff's |
Is this still an issue? There's no MWE given to test it. #266 does much better on v1.0 though. |
using ForwardDiff
function speelpenning(x)
res = [1.0]
for i in x
res = res*i
end
return res
end
dim = parse(Int,ARGS[1])
println("Speelpenning with dim = ", dim)
@time fjac = x0 -> ForwardDiff.jacobian(speelpenning, x0)
@time fhes = x0 -> ForwardDiff.jacobian(fhes_jac, x0)
@time ften = x0 -> ForwardDiff.jacobian(ften_hes, x0)
x1 = ones(dim)
@time fjac(x1)
@time fhes(x1)
@time ften(x1) No it's not resolved. With dim=10 this code takes forever. That's weird for speelpenning which is a classic example in AD. |
Here's a corrected version of the code as an MWE: using ForwardDiff
function speelpenning(x)
res = [one(eltype(x))]
for i in x
res .= res.*i
end
return res
end
dim = 10
println("Speelpenning with dim = ", dim)
fjac = x0 -> ForwardDiff.jacobian(speelpenning, x0)
fhes_jac = x0 -> ForwardDiff.jacobian(speelpenning, x0)
fhes = x0 -> ForwardDiff.jacobian(fhes_jac, x0)
ften_hes = x0 -> ForwardDiff.jacobian(fhes_jac, x0)
ften = x0 -> ForwardDiff.jacobian(ften_hes, x0)
x1 = ones(dim)
println("Jac with compile")
@time fjac(x1)
println("Jac without compile")
@time fjac(x1)
println("Hes with compile")
@time fhes(x1)
println("Hes without compile")
@time fhes(x1)
println("Ten with compile")
@time ften(x1)
println("Ten without compile")
@time ften(x1) Which outputs: Speelpenning with dim = 10
Jac with compile
0.676379 seconds (1.86 M allocations: 96.334 MiB, 3.62% gc time)
Jac without compile
0.000071 seconds (8 allocations: 2.344 KiB)
Hes with compile
1.022722 seconds (1.72 M allocations: 81.470 MiB, 1.85% gc time)
Hes without compile
0.000103 seconds (11 allocations: 23.250 KiB)
Ten with compile
22.808301 seconds (9.07 M allocations: 347.316 MiB, 0.78% gc time)
Ten without compile
0.000317 seconds (15 allocations: 255.906 KiB) With -O0: Speelpenning with dim = 10
Jac with compile
0.553653 seconds (1.86 M allocations: 96.355 MiB, 5.27% gc time)
Jac without compile
0.000026 seconds (38 allocations: 4.063 KiB)
Hes with compile
0.444710 seconds (1.72 M allocations: 81.481 MiB, 5.49% gc time)
Hes without compile
0.000078 seconds (41 allocations: 33.719 KiB)
Ten with compile
1.802644 seconds (9.07 M allocations: 347.459 MiB, 8.56% gc time)
Ten without compile
0.000361 seconds (45 allocations: 361.531 KiB) |
We do prototyping of a time integration using a handwritten residual function (50 lines) and Jacobian (100 lines):
Computing the Jacobian, Hessian and tensor of one timestep with
results in the following runtime:
I already profiled and typed the code as much as possible I could. This is run with Julia -O0. With these JIT compilation times I would be happy to sacrifice a bit of runtime for a faster JIT.
Is there any way to reduce the time for the tensor?
The text was updated successfully, but these errors were encountered: