same error.  “RuntimeError: CUDA out of memory. Tried to allocate 29.21 GiB (GPU 0; 7.93 GiB total capacity; 361.89 MiB already allocated; 6.17 GiB free; 14.11 MiB cached)”
I have tried with the below approach,
model.eval()
with torch.no_grad():
input = torch.randn(10000000,784).to(device)
_, feature = model(input)
print(feature.size())
feature_data = feature.data.cpu().numpy()