你好, 我有11GB的GPU内存,我遇到了CUDA内存问题,并进行了预训练
我使用了以下代码:
snlp = stanza.Pipeline(lang="en", use_gpu=True) # tried different batch_size/ lemma_batch_size - did not help
nlp = StanzaLanguage(snlp)
def tokenize(text):
tokens = nlp(text)
doc_l = [token.lemma_ for token in doc]
lower_tokens = [t.lower() for t in doc_l]
alpha_only = [t for t in lower_tokens if t.isalpha()]
no_stops = [t for t in alpha_only if t not in stopwords]
#torch.cuda.empty_cache() # Tried this - did not work
return no_stops
tfidf = TfidfVectorizer(tokenizer=tokenize, min_df=0.1, max_df=0.9)
# Construct the TF-IDF matrix
tfidf_matrix = tfidf.fit_transform(texts)
RuntimeError: CUDA out of memory. Tried to allocate 978.00 MiB (GPU 0;11.00 GiB total capacity; 6.40 GiB already allocated; 439.75 MiB free; 6.53 GiB reserved in total by PyTorch).
我试过了
[(tokenize(t) for t in test]
它只持续了12个文本。平均每人200字。根据错误消息-“尝试分配978.00 MiB”和此数据-SNLP每一步使用1GB的GPU内存
它在CPU上工作,但分配所有可用内存(32G RAM)。它的CPU速度要慢得多。我需要它来让CUDA工作
如果检查完整堆栈跟踪,可能会提示哪个处理器遇到内存问题。例如,我最近在堆栈跟踪方面遇到了类似的问题:
这让我意识到,在调用
stanza.Pipeline(...)
时,我需要设置depparse_batch_size
。还有其他设置,如您提到的batch_size
和lemma_batch_size
,以及pos_batch_size
和ner_batch_size
等。这些设置确实有助于解决此问题相关问题 更多 >
编程相关推荐