Try to use : torch.no_grad() & model.eval() if not using. 5
Most important : torch.no_grad() as it impacts the autograd engine and deactivate it. It will reduce memory usage and speed up computations in validation loop or test loop.