Gan网络batchsize=8就报显存不足
来源:2-2 【讨论题】比较动态图与静态图推理框架

2227181
2023-11-02
老师,课堂的Gan网络,如果我把batchsize=8或更大,刚运行起来就会报:
torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 32.00 MiB. GPU 0 has a total capacty of 15.99 GiB of which 0 bytes is free. Of the allocated memory 14.53 GiB is allocated by PyTorch, and 626.79 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF.
batchsize=4/2没有问题,可以执行下去。
这个错误提示确实是显存不足吗?被分配的15.99G远大于要申请的32M啊。还是代码中存在什么Bug?上面的错误是刚执行就报了,不是执行了一段时间才报的。
在这个提示前有一些警告信息:
d:\imooc\pytorch\09\train.py:83: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
real_A = torch.tensor(input_A.copy_(batch[‘A’]), dtype=torch.float).to(device)
d:\imooc\pytorch\09\train.py:84: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
real_B = torch.tensor(input_B.copy_(batch[‘B’]), dtype=torch.float).to(device)
D:\Programs\anaconda3\envs\imooc_ai\Lib\site-packages\torch\nn\modules\instancenorm.py:80: UserWarning: input’s size at dim=1 does not match num_features. You can silence this warning by not passing in num_features, which is not used because affine=False
warnings.warn(f"input’s size at dim={feature_dim} does not match num_features. "
torch.Size([1, 1, 15, 15])
D:\Programs\anaconda3\envs\imooc_ai\Lib\site-packages\torch\nn\modules\loss.py:535: UserWarning: Using a target size (torch.Size([1])) that is different to the input size (torch.Size([1, 1])). This will likely lead to incorrect results due to broadcasting. Please ensure they have the same size.
1回答
-
会写代码的好厨师
2023-11-09
不是有bug 应该就是显存不够了。这个要么减小网络的参数,或者调小分辨率。
00
相似问题