Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors In PyTorch - Multi-GPU #5

Open
WilliamJudge94 opened this issue Oct 7, 2021 · 0 comments
Open

Errors In PyTorch - Multi-GPU #5

WilliamJudge94 opened this issue Oct 7, 2021 · 0 comments

Comments

@WilliamJudge94
Copy link

In order to get accurate training on the multi-GPU instance of PyTorch one must keep the batch size the same. Please see explanation here (https://discuss.pytorch.org/t/accuracy-difference-on-multi-gpu-with-nn-dataparallel/65481/12)

As for the model saving for the multi-GPU instance, one must chance the code to the following (see the following for more information https://discuss.pytorch.org/t/save-checkpoints-trained-on-multi-gpus-for-load-on-single-gpu/97881/9):

#Function to update saved model if validation loss is minimum
def update_saved_model(model, path):
    if not os.path.isdir(path):
        os.mkdir(path)
    for f in os.listdir(path):
        os.remove(os.path.join(path, f))
    if (NGPUS>1):    
        
        if isinstance(model, nn.DataParallel):
            torch.save(model.module.state_dict(), path+'best_model.pth')
        else:
            torch.save(model.state_dict(), path+'best_model.pth')
    else:
        torch.save(model, path+'best_model.pth')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant