使用bert时OOM问题的处理
一般原因:显存不够
解决办法:减小batch_size或max_len,注意改变batch_size要重新调learning_rate
https://github.com/google-research/bert/blob/master/README.md#out-of-memory-issues
按照推荐来设置max_len和batch_size,但仍然会报OOM,不过不同的地方在于,是在Cross Validation的后面某个fold才报错的,即前面几个fold不报OOM,后面某个fold在构建bert网络时又报了OOM。
原因:所以问题应该出现在前面几个epoch训练后没有及时回收GPU资源。
解决办法:
在CV的过程中加入如下代码:
import gcimport tensorflow.keras.backend as K# 删除keras模型的输入、输出、fit之后返回的history,以及整个modeldel train_inputs, train_outputs, valid_inputs, valid_outputs, tmp_test_inputs, history, modelK.clear_session()[gc.collect() for _ in range(15)]参考: https://forums.fast.ai/t/how-could-i-release-gpu-memory-of-keras/2023/7
CV过程的各种切分方法对比
https://www.kaggle.com/ratthachat/quest-cv-analysis-on-different-splitting-methods













