Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CUDA out of memory mesage with private pool info #124673

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions c10/cuda/CUDACachingAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,26 @@ class DeviceCachingAllocator {
.current;
auto observers_local = oom_observers_;

size_t allocated_in_private_pools = 0;
auto get_size_block = [](const BlockPool& pool) {
size_t res = 0;
for (const auto& block : pool.blocks) {
res += block->size;
}
return res;
};
for (const auto& p : graph_pools) {
allocated_in_private_pools += get_size_block(p.second->large_blocks);
allocated_in_private_pools += get_size_block(p.second->small_blocks);
}

std::string private_pool_msg;

if (allocated_in_private_pools > 0) {
private_pool_msg = "with " + format_size(allocated_in_private_pools) +
" allocated in private pools (e.g., CUDA Graphs), ";
}

// Make sure we do not have the device lock before calling our
// observers which might need hold the GIL
// It is safe to release at this point because will no longer
Expand Down Expand Up @@ -1153,9 +1173,12 @@ class DeviceCachingAllocator {
" is free. ",
proc_info,
"Of the allocated memory ",
format_size(allocated_bytes),
" is allocated by PyTorch, and ",
format_size(reserved_bytes - allocated_bytes),
format_size(allocated_bytes + allocated_in_private_pools),
" is allocated by PyTorch, ",
private_pool_msg,
"and ",
format_size(
reserved_bytes - allocated_bytes - allocated_in_private_pools),
" is reserved by PyTorch but unallocated.",
" If reserved but unallocated memory is large try setting",
" PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid"
Expand Down
Loading