gradient_accumulation_steps

gradient_accumulation_steps

如果显存不足,我们可以通过gradient_accumulation_steps梯度累计来解决。
假设原来的batch size=10,数据总量为1000,那么一共需要100train steps,同时一共进行100次梯度更新。
若是显存不够,我们需要减小batch size,我们设置gradient_accumulation_steps=2,那么我们新的batch size=10/2=5,我们需要运行两次,才能在内存中放入10条数据,梯度更新的次数不变为100次,那么我们的train steps=200

你可能感兴趣的:(基础知识)