RuntimeError: CUDA out of memory. Tried to allocate 22.00 MiB (GPU 0; 10.76 GiB total capacity; 9.61

RuntimeError: CUDA out of memory. Tried to allocate 22.00 MiB (GPU 0; 10.76 GiB total capacity; 9.61 GiB already allocated; 4.50 MiB free; 332.12 MiB cached)

Sometimes in this situation, no matter how you change the batchsize, the memory overflow error will still be reported. When nVidia-smi finds that the gpu is too idle, the reason for this is most likely caused by the intermediate variable data. At this time, you can check loss, acc, pred Wait for the .item() to be added after the intermediate calculation data, if not, add it, and the error will be resolved.
,

Guess you like

Origin blog.csdn.net/snow_maple521/article/details/115427827