Amritesh
Amritesh

Reputation: 41

Spacy Transformer Model Not Able to Unload From GPU When Run in Loop

Why is the SpaCy model not able to unload from GPU when run in loop? I want to unload the model at different interval of time. Also their is CPU memory leak issue with this model. How to resolve this issue.

import spacy
import torch
import time
spacy.require_gpu()

for _ in range(10):
    print("The GPU occupied before model load: ", torch.cuda.memory_allocated())
    ner_model = spacy.load("en_core_web_trf", disable=["tagger", "parser", "attribute_ruler", "lemmatizer", "morphologizer", "senter", "textcat"])
    print("The GPU occupied after model load: ", torch.cuda.memory_allocated())
    time.sleep(10)
    del ner_model
    time.sleep(10)

I deleted the model object but still not able to unload the model. Why?

I want to unload the model periodically. I want the model should unload whenever i need.

Upvotes: 0

Views: 33

Answers (0)

Related Questions