google / google/jaxopt

Possible memory leak when calling solver.run multiple times

Open
#380 17 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
1.1k
Forks
76
Avg merge
2d 21h
Merged PRs (30d)
1

Description

I am trying to solve a problem where `solver.run` is called multiple times to minimize a series of functions while varying a parameter. Using `memory_profiler` I can see that the allocated memory increases each time the function `solver.run` is called and never decreases.

Here is a minimal example to reproduce the issue:

import jax.numpy as jnp
import jaxopt
from memory_profiler import profile

@profile
def optimize(min):

def obj(x, min):
return jnp.square(x-min).sum()

x0 = jnp.zeros(1)
mm = jnp.array(min)

solver = jaxopt.LBFGS(obj, maxiter=100)
x = solver.run(x0, min=mm).params[0]
print(x)

for i in range(10):
optimize(i)

And here is the corresponding plot of the allocated memory:
![Figure_1](https://user-images.githubusercontent.com/14178111/213127811-fb3d7101-b7cb-4441-893c-7b73d5bd4065.png)

Can you please confirm the issue or provide a solution for that? Thanks. Alessandro

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.