【发布时间】:2020-12-06 00:37:13
【问题描述】:
我正在尝试在 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 仅使用 8*12GB 中的 12GB GPU 之一。
没有得到任何地方来完成这个训练,即使在本地尝试使用 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")
P.S.:我能够在具有 4GB GTX 1650 DDR5 内存的本地 GPU 机器上用更小的数据集训练相同的架构,而且速度非常快。
【问题讨论】:
-
我猜重点是:“一个较小的数据集”。
-
是的,我也是这么想的,但是记录差在1000条左右,仅此而已..
-
不,重点是“相似的架构”。微小的变化可能会产生很大的影响。
-
对不起,我误导了,它实际上是相同的架构模型。只是不同的是数据集也有 4000 对 5000 条记录。重点是,我认为问题在于 Sagemaker 培训,在本地同样可以使用不错的 GPU 运行,只是我没有那种基础设施。你能帮我解决这个问题,以便在 Sagemaker 中训练模型吗?
标签: python pytorch torch amazon-sagemaker torchvision