我正在尝试在AWS Sagemaker中训练PyTorch FLAIR模型。 在此过程中,出现以下错误:
RuntimeError: CUDA out of memory. Tried to allocate 84.00 MiB (GPU 0; 11.17 GiB total capacity; 9.29 GiB already allocated; 7.31 MiB free; 10.80 GiB reserved in total by PyTorch)
我使用了sagemaker.pytorch.estimator.PyTorch类进行训练。
我尝试了不同类型的实例,从ml.m5、g4dn到p3(甚至是96GB内存的实例)。在ml.m5中,出现了CPUmemoryIssue错误,在g4dn中出现了GPUMemoryIssue错误,并且在P3中主要出现了GPUMemoryIssue错误,因为Pytorch只使用了12GB中的一块GPU(这里应该是指容量为8*12GB)。
即使在本地使用CPU机器进行了尝试,也无法完成此训练,并出现了以下错误:
RuntimeError: [enforce fail at ..\c10\core\CPUAllocator.cpp:72] data. DefaultCPUAllocator: not enough memory: you tried to allocate 67108864 bytes. Buy new RAM!
模型训练脚本:
corpus = ClassificationCorpus(data_folder, test_file='../data/exports/val.csv', train_file='../data/exports/train.csv')
print("finished loading corpus")
word_embeddings = [WordEmbeddings('glove'), FlairEmbeddings('news-forward-fast'), FlairEmbeddings('news-backward-fast')]
document_embeddings = DocumentLSTMEmbeddings(word_embeddings, hidden_size=512, reproject_words=True, reproject_words_dimension=256)
classifier = TextClassifier(document_embeddings, label_dictionary=corpus.make_label_dictionary(), multi_label=False)
trainer = ModelTrainer(classifier, corpus, optimizer=Adam)
trainer.train('../model_files', max_epochs=12,learning_rate=0.0001, train_with_dev=False, embeddings_storage_mode="none")
附言:我在本地GPU机器上使用了一台4GB GTX 1650 DDR5内存的机器以更小的数据集训练了同样的架构,速度非常快。