mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Disable GC if fraction is not set (#76648)
Summary: If fraction is not set, don't trigger GC! In the current codebase, if you turn on the GC and *do not set the fraction* in the application, the GC will be triggered every time which does not make much sense -- perf will be as bad as turning off the caching allocator. With this fix, GC is invoked only when the fraction is set. Test Plan: Unit tests Differential Revision: D36026128 Pull Request resolved: https://github.com/pytorch/pytorch/pull/76648 Approved by: https://github.com/yinghai
This commit is contained in:
committed by
PyTorch MergeBot
parent
8c50414233
commit
3e89a1d6b7
@ -526,6 +526,7 @@ class DeviceCachingAllocator {
|
||||
if (!block_found) {
|
||||
// Do garbage collection if the flag is set.
|
||||
if (C10_UNLIKELY(
|
||||
set_fraction &&
|
||||
CachingAllocatorConfig::garbage_collection_threshold() > 0.0)) {
|
||||
garbage_collect_cached_blocks();
|
||||
}
|
||||
@ -1129,6 +1130,7 @@ class DeviceCachingAllocator {
|
||||
BlockPool& pool = *p.pool;
|
||||
|
||||
if (C10_UNLIKELY(
|
||||
set_fraction &&
|
||||
CachingAllocatorConfig::garbage_collection_threshold() > 0.0)) {
|
||||
// Track block reuse interval only when garbage collection is enabled.
|
||||
for (auto& b : pool.blocks) {
|
||||
|
Reference in New Issue
Block a user