1

The following two loops will use memory until I run out, but I can't figure out why. I am deleting all of the created variables at the end of each iteration and it still leaks.

!pip3 install cupy-cuda101
import cupy as cp
import numpy as np
from sklearn.preprocessing import PolynomialFeatures

xtrain = cp.asnumpy(cp.random.uniform(-1,1,size = (150000,50)))

for i in range(0,1000):
   weights = cp.random.uniform(-1,1,size = (1275,1000))
   
   for chunk in range(0,xtrain.shape[0],5000):
      xchunk = xtrain[chunk:chunk+5000,:]
      poly=PolynomialFeatures(interaction_only = True, include_bias = False)
      xchunk = cp.array(poly.fit_transform(xchunk))
      ranks = cp.matmul(xchunk,weights)
      del ranks, xchunk, poly
   del weights

xtrain is just float data as well, between -1 and 1.

6
  • All your del statements are pointless, since those variables are re-assigned on each iteration anyway. Commented Jul 23, 2020 at 19:25
  • exactly, so how can it use more and more memory after each iteration? Commented Jul 23, 2020 at 19:26
  • No idea. You have to provide a minimal reproducible example to really expect anyone to be able to diagnose something like taht Commented Jul 23, 2020 at 19:31
  • ok there its reproducible now Commented Jul 23, 2020 at 19:42
  • 1
    Could you elaborate more on why you think there is a "leak"? Also note that CuPy uses the memory pool by default: docs.cupy.dev/en/latest/reference/memory.html Commented Jul 24, 2020 at 7:40

1 Answer 1

2

these lines insert at the end of each iteration fixed it:

    cp.get_default_memory_pool().free_all_blocks()
    cp.get_default_pinned_memory_pool().free_all_blocks()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.