RuntimeError: CUDA out of memory. Tried to allocate 2.00 MiB (GPU 0; 11.00 GiB total capacity; 8.53 GiB already allocate解决办法

在出现错误的地方加上:

with torch.no_grad():
test_loader = init_data_loader(X_test, y_test, torch.device('cpu'), batch_size, num_workers=0)

print("Starting inference ...")
result = []
model.eval()
valid_loss = 0

with torch.no_grad():
    for batch_x, batch_y in tqdm(test_loader):
        batch_x, batch_y = batch_x.to(device), batch_y.to(device)
        output = model(batch_x)
        result.extend(output[:, 0, 0])
        loss =  torch.sqrt(criterion(output, batch_y))
        valid_loss += loss

valid_loss /= len(train_loader)
print("Done!")

 

你可能感兴趣的:(RuntimeError: CUDA out of memory. Tried to allocate 2.00 MiB (GPU 0; 11.00 GiB total capacity; 8.53 GiB already allocate解决办法)