The message points to a small chunk of free memory (~6MB), which is not sufficient for your use case.
This could happen e.g. due to memory fragmentation.
Try to lower your batch size and run the code again. Alternatively you could also have a look at torch.utils.checkpoint 19 to trade compute for memory.