During training nn.dataparallel() working perfectly but eval mode it is showing this bellow error,
RuntimeError: CUDA out of memory. Tried to allocate 29.21 GiB (GPU 0; 7.93 GiB total capacity; 361.73 MiB already allocated; 6.15 GiB free; 34.27 MiB cached)
Example:
device = torch.device(“cuda:0” if torch.cuda.is_available() else “cpu”)
if torch.cuda.is_available:
torch.cuda.manual_seed_all(1)
class model(nn.Module):
def init(self):
super(model, self).init()
    self.feature = nn.Sequential(
        nn.Linear(int(np.prod(img_shape)), 512),
        nn.LeakyReLU(0.2, inplace=True),
        nn.Linear(512, 10),
        nn.LeakyReLU(0.2, inplace=True))
    self.linear = nn.Sequential( nn.Linear(10, 1))


def forward(self, img):
    img_flat = img.view(img.shape[0], -1)
    img_flat = self.feature(img_flat)
    validity = self.linear(img_flat)
    #print("Discrimiantor model")
    #print("\tIn Model: input size", img.size(),
    #      "output size", validity.size())
    #print("#########################################################")
    return validity

if torch.cuda.device_count() > 1:
print(“Let’s use”, torch.cuda.device_count(), “GPUs!”)
dim = 0 [30, xxx] -> [10, …], [10, …], [10, …] on 3 GPUs
model = nn.DataParallel(model)
Training is perfectly working.
######################## Eval mode
model.eval()
input = torch.randn(10000000,784).to(device)
feature = model.module.feature(input)
print(feature)
I am currently using 4 GPUs with 8GB RAM.