I am using something like this for getting the model’s state dict (for saving):
try:
    model_state_dict = model.module.state_dict()
except AttributeError:
    model_state_dict = model.state_dict()

It essentially checks if the model has an attribute module, which is created by nn.DataParallel. I don’t know if there is a cleaner way introduced in more recent versions.
P.S: you have written DataLoader in your post title, you might attract more readers / helpers by correcting that