unable to free gpu memory after loading spacy model

1.1k views Asked by At

Why does SpaCy keep GPU memory even after I delete the model? First I thought I'm facing same problem as this question but then I realized even Cupy doesn't mark the memory as being free.

import spacy
import cupy as cp
import time
import gc


def pool_stats(mempool):
    print('used:',mempool.used_bytes(),'bytes')
    print('total:',mempool.total_bytes(),'bytes\n')

pool = cp.cuda.MemoryPool(cp.cuda.memory.malloc_managed) # get unified pool
cp.cuda.set_allocator(pool.malloc) # set unified pool as default allocator

spacy.prefer_gpu()
nlp = spacy.load('/tmp/nlp')
pool_stats(pool)

# used: 2716626944 bytes
# total: 2719709696 bytes

del nlp
time.sleep(3)
gc.collect()
pool_stats(pool)

# used: 2700994560 bytes
# total: 2719709696 bytes
0

There are 0 answers