ReverseDiff.jl
ReverseDiff.jl copied to clipboard
Time to compute gradient is too long
Hi,
I don't know if this is a real issue or more of a problem with my understanding of automatic differentiation. I was doing some simple benchmarking with ReverseDiff. From what I understand from the general theory of automatic differentiation the time it takes to compute the gradient of f(x) shouldn't be more than five times the time it takes to compute f(x) (using reverse mode). But it doesn't seem to be the case. I used the extension of the Rosenbrock function and the following tools to compare time:
function f(x)
n=1000;
return 100.0 * sum((x[i] - x[i - 1]^2)^2 for i=2:n) + (1.0 - x[1])^2
end
x = rand(n) #the right n to fit the function
t = @elapsed f(x)
t_g = @elapsed ReverseDiff.gradient(f, x)
Here are some of the results I got: n =100 t=2.224000e-06 t_g = 9.482440e-04 n = 500 t=2.054000e-06 t_g = 4.637314e-03 n =1000 t=3.007000e-06 t_g = 9.125266e-03
So t_g
should be such that t_g<5*t
but that is never the case. Is there a problem with what I am doing? Or my understanding of the theory is wrong?
Thanks for your help!
Duplicate of https://discourse.julialang.org/t/reversediff-resultst-do-not-fit-theory/11549
Solved can be closed!