-
Notifications
You must be signed in to change notification settings - Fork 166
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
A possible memory issue? #160
Comments
I've encountered a memory leak in reverse auto-differentiation as well. My scalar function contains a dot-product of variables too, although there's plenty of other complexity too. I also run into OOM issues due to repeated evaluation. Compiling @sergeigribanov's program and running it through
I'm having trouble making heads or tails of this. Reducing the program to var f(const VectorXvar& x) { return x.dot(x); }
int main() {
VectorXvar x = VectorXvar::Ones(7);
var u = f(x);
VectorXd g;
MatrixXd H = hessian(u, x, g);
std::cout << "Finished!" << std::endl;
return 0;
} yields the following ctor/dtor counts, omitting
Most interestingly, the program does not leak if Any ideas what this could be @allanleal so I can look closer? |
Thanks for reporting this. Are you able to create a reproducible example that does not involve Eigen? This could simplify the memory leaking checking. |
I don't think I can. The Eigen-related functionality seems to be important for this. If I replace the I can try to run this through |
I whipped up a graphviz representation here and ran it against an even smaller variant to keep the graphs reasonably small: VectorXvar x = VectorXvar::Ones(3);
var u = x.dot(x);
std::ofstream dp("dp-pre.dot");
dp << graphviz(u.expr);
VectorXd g;
MatrixXd H = hessian(u, x, g);
std::ofstream dpo("dp-post.dot");
dpo << graphviz(u.expr); The resulting graphs are here as in svg form. The short summary is that forming the expression tree is unproblematic and looks okay, but running the gradients generates A fix might be as easy as clearing all of the |
There's two possible solutions to my eyes:
Personally, I'd advocate for 1 (it feels cleaner to me), but I think I've still not completely understood the relationships between |
I'm also trying to fix this here, but with no avail. I've managed to reduce the reproducible problem to its simplest form: #include <autodiff/reverse/var/var.hpp>
#include <autodiff/reverse/var/eigen.hpp>
using namespace autodiff;
var f(const var& x)
{
return x*x;
}
int main()
{
var x(1.0);
var u = f(x);
x.seedx();
u.expr->propagatex(detail::constant<double>(1.0));
return 0;
} We may need to use a mix of FYI, |
Wondering also if we could get rid of |
I thought about this too, but I was convinced that sometimes the
So the main purpose for storing them somewhere is to reuse them for higher-order derivatives? There's no inherent reason they need to be stored within the expression tree itself?
I don't see a good way to keep structural sharing between expression trees with this approach |
This issue has been fixed with PR #177 provided by @jargonzombies! Thanks a lot for this. |
I would like to use autodiff in my project. The project is related to the problem of nonlinear constrained optimization. In the case of my problem, the optimization is done not once, but hundreds of thousands or millions of times in a row. The maximum dimension of the parameter space can be on the order of several hundred. I want to use autodiff to calculate the gradient and hessian of an objective function in an optimization algorithm. Before using autodiff in my project, I decided to conduct a series of tests. In one of my tests, I came across a memory usage issue. The code of the test program is the following:
CMake file that I use to build this test program is the following:
The issue happens when the variable
numberOfEntries
is equal to 1M. In this case, memory usage gradually rises to 100%. Eventually, the process ends with the message: Killed.If the variable
numberOfEntries
is equal to 100K, then the program runs without issues.I have tested this program on my laptop (16 GB of RAM, CPU: intel core i7, OS: Arch Linux).
The text was updated successfully, but these errors were encountered: