I think I just fixed the problem after careful analyzing of the code. I had not inherited data.Dataset  from torch.utils into my custom dataset. I am unsure how this might cause a problem but it seems to fix my problem atleast for now. I didn’t see any random hangs in the middle.