尝试在 onnotes 上训练 AllenNLP 共指解析模型:使 CUDA 内存不足

时间:2021-04-16 09:31:53

标签: bert-language-model allennlp coreference-resolution

我正在尝试使用以下配置文件在 16GB GPU 上训练 AllenNLPs 共指模型:https://github.com/allenai/allennlp-models/blob/main/training_config/coref/coref_spanbert_large.jsonnet

我使用以下脚本创建了训练、测试和开发文件:https://github.com/allenai/allennlp/blob/master/scripts/compile_coref_data.sh

我几乎立即就让 CUDA 内存不足,所以我尝试将“spans_per_word”和“max_antecedents”更改为较低的值。将 spans_per_words 设置为 0.1 而不是 0.4,我可以运行更长的时间,但不会接近一个完整的 epoch。 16GB GPU 还不够吗?或者我可以尝试更改其他参数吗?

<块引用>

回溯(最近一次调用最后一次): 文件“/home/ubuntu/anaconda3/envs/allennlp/bin/allennlp”,第8行,在 sys.exit(运行()) 运行文件“/home/ubuntu/anaconda3/envs/allennlp/lib/python3.7/site-packages/allennlp/ma​​in.py”,第34行 主要(编=“allennlp”) 文件“/home/ubuntu/anaconda3/envs/allennlp/lib/python3.7/site-packages/allennlp/commands/init.py”,第119行,主目录 args.func(args) 文件“/home/ubuntu/anaconda3/envs/allennlp/lib/python3.7/site-packages/allennlp/commands/train.py”,第119行,train_model_from_args file_friendly_logging=args.file_friendly_logging, 文件“/home/ubuntu/anaconda3/envs/allennlp/lib/python3.7/site-packages/allennlp/commands/train.py”,第178行,train_model_from_file file_friendly_logging=file_friendly_logging, 文件“/home/ubuntu/anaconda3/envs/allennlp/lib/python3.7/site-packages/allennlp/commands/train.py”,第242行,train_model file_friendly_logging=file_friendly_logging, 文件“/home/ubuntu/anaconda3/envs/allennlp/lib/python3.7/site-packages/allennlp/commands/train.py”,第466行,在_train_worker 指标 = train_loop.run() 文件“/home/ubuntu/anaconda3/envs/allennlp/lib/python3.7/site-packages/allennlp/commands/train.py”,第528行,运行中 返回 self.trainer.train() 文件“/home/ubuntu/anaconda3/envs/allennlp/lib/python3.7/site-packages/allennlp/training/trainer.py”,第740行,火车 指标,纪元 = self._try_train() 文件“/home/ubuntu/anaconda3/envs/allennlp/lib/python3.7/site-packages/allennlp/training/trainer.py”,第772行,在_try_train train_metrics = self._train_epoch(epoch) 文件“/home/ubuntu/anaconda3/envs/allennlp/lib/python3.7/site-packages/allennlp/training/trainer.py”,第523行,在_train_epoch 损失.向后() 文件“/home/ubuntu/anaconda3/envs/allennlp/lib/python3.7/site-packages/torch/tensor.py”,第245行,向后 torch.autograd.backward(自我,渐变,retain_graph,create_graph,输入=输入) 文件“/home/ubuntu/anaconda3/envs/allennlp/lib/python3.7/site-packages/torch/autograd/init.py”,第147行,向后 allow_unreachable=True,accumulate_grad=True) # allow_unreachable 标志 运行时错误:CUDA 内存不足。尝试分配 1.33 GiB(GPU 0;14.76 GiB 总容量;11.69 GiB 已分配;639.75 MiB 空闲;PyTorch 总共预留 13.09 GiB)

1 个答案:

答案 0 :(得分:0)

16GB 是该型号的低端。

当这个模型接收到大量文本时,它会将文本分成多个较短的序列,每个序列为 512 个词段,并同时运行它们。这样一来,即使批大小为 1,您也会同时在内存中获得大量序列。

尝试将 max_sentence 设置为较低的值(默认为 110),看看是否有效。