tensorflow / tensorflow/probability
Memory leak when drawing many tfd.GaussianProcess samples?
Nobody has claimed this yet.
- Dominant language
- Jupyter Notebook
- Stars
- 4.4k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
When instantiating many 2-dimensional GPs with exponentiated quadratic kernels and sampling over several thousand points, I'm getting memory errors: ResourceExhaustedError: failed to allocate memory [Op:Mul]
I am able to produce a minimal working example in Google Colab: https://colab.research.google.com/drive/1yOzrWbyyia3zLirXQ6Z76scf20iryP4W#scrollTo=wNzD5JdxqgOX
Just ensure you have Runtime -> Change runtime type -> Hardware accelerator = GPU so that GPUs are used.
I provide the code here as well, for convenience:
import numpy as np
import tensorflow_probability as tfp
tfd = tfp.distributions
tfk = tfp.math.psd_kernels
from tqdm import tqdm
# This raises ResourceExhaustedError after 626 iterations
for i in tqdm(range(1000)):
foo = tfd.GaussianProcess(
kernel=tfk.ExponentiatedQuadratic(np.float64(1.), np.float64(1.)),
index_points=np.random.randn(6_500, 2).astype(np.float64),
observation_noise_variance=.05**2,
).sample(seed=i).numpy()
I thought I could avoid this error by reusing the same GaussianProcess object when drawing samples, but this also ended up raising a ResourceExhaustedError. I guess this suggests the issue is from running sample() many times, rather than instantiating the GP objects. Does this hint at a memory leak occurring?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Google Colab minimal example and the repeated tfd.GaussianProcess.sample() loop, using the GPU runtime as described. Compare repeated sampling with repeated object construction and determine whether memory remains allocated until ResourceExhaustedError; done means the cause and reproducible behavior are identified and the memory failure is resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python, tensorflow
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100