mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-08-12 18:30:02 +08:00
Fix Python 3.12 VRAM spikes with CUDNN benchmark
Disables torch.backends.cudnn.benchmark on Python 3.12 to prevent severe VRAM allocation spikes that occur during model operations. The CUDNN benchmarking feature, introduced in v0.3.57 (commit e2d1e5da), tests multiple convolution algorithms and allocates temporary VRAM. This interacts poorly with Python 3.12's garbage collection behavior, causing multi-GB VRAM spikes before and after model inference. Solution: - Preserves CUDNN benchmarking performance benefit on other Python versions - Only disables the problematic behavior on Python 3.12 - Maintains full functionality while fixing memory management issues - No impact on users not using --fast autotune flag Tested with TTS model wrappers that reproduce the issue consistently on Python 3.12 with ComfyUI v0.3.57+. Fixes: VRAM spikes in Python 3.12 environments Related: ComfyUI v0.3.57 regression affecting model memory management
This commit is contained in:
parent
ce4cb2389c
commit
1ce987cf52
@ -53,7 +53,10 @@ except (ModuleNotFoundError, TypeError):
|
|||||||
cast_to = comfy.model_management.cast_to #TODO: remove once no more references
|
cast_to = comfy.model_management.cast_to #TODO: remove once no more references
|
||||||
|
|
||||||
if torch.cuda.is_available() and torch.backends.cudnn.is_available() and PerformanceFeature.AutoTune in args.fast:
|
if torch.cuda.is_available() and torch.backends.cudnn.is_available() and PerformanceFeature.AutoTune in args.fast:
|
||||||
torch.backends.cudnn.benchmark = True
|
import sys
|
||||||
|
# Skip CUDNN benchmark on Python 3.12 due to VRAM allocation issues with model wrappers
|
||||||
|
if sys.version_info[:2] != (3, 12):
|
||||||
|
torch.backends.cudnn.benchmark = True
|
||||||
|
|
||||||
def cast_to_input(weight, input, non_blocking=False, copy=True):
|
def cast_to_input(weight, input, non_blocking=False, copy=True):
|
||||||
return comfy.model_management.cast_to(weight, input.dtype, input.device, non_blocking=non_blocking, copy=copy)
|
return comfy.model_management.cast_to(weight, input.dtype, input.device, non_blocking=non_blocking, copy=copy)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user