报错信息:

return Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 308.00 MiB. GPU 0 has a total capacity of 23.64 GiB of which 291.69 MiB is free. Including non-PyTorch memory, this process has 23.12 GiB memory in use. Of the allocated memory 19.94 GiB is allocated by PyTorch, and 2.73 GiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation.  See documentation for Memory Management  (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)

发现unallocated的空间远大于需要的空间。

解决:

export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐