From 4c5cbde1f5ed031e6cc90eb70543e49cd79c3838 Mon Sep 17 00:00:00 2001 From: Disty0 Date: Mon, 21 Apr 2025 01:53:07 +0300 Subject: [PATCH] Make ROCm listen to the gc config and set the minimum gc threshold to 1 --- installer.py | 2 +- modules/shared.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/installer.py b/installer.py index 02f421157..25bc1f5cf 100644 --- a/installer.py +++ b/installer.py @@ -589,7 +589,6 @@ def install_rocm_zluda(): return os.environ.get('TORCH_COMMAND', 'torch torchvision') log.info('ROCm: AMD toolkit detected') - os.environ.setdefault('PYTORCH_HIP_ALLOC_CONF', 'garbage_collection_threshold:0.8,max_split_size_mb:512') # if not is_windows: # os.environ.setdefault('TENSORFLOW_PACKAGE', 'tensorflow-rocm') @@ -1226,6 +1225,7 @@ def set_environment(): if opts.get("torch_expandable_segments", False): allocator += ',expandable_segments:True' os.environ.setdefault('PYTORCH_CUDA_ALLOC_CONF', allocator) + os.environ.setdefault('PYTORCH_HIP_ALLOC_CONF', allocator) log.debug(f'Torch allocator: "{allocator}"') if sys.platform == 'darwin': os.environ.setdefault('PYTORCH_ENABLE_MPS_FALLBACK', '1') diff --git a/modules/shared.py b/modules/shared.py index faf0d1237..b7bb69b86 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -484,7 +484,7 @@ options_templates.update(options_section(('backends', "Backend Settings"), { "torch_tunable_ops": OptionInfo("default", "Tunable ops", gr.Radio, {"choices": ["default", "true", "false"]}), "torch_tunable_limit": OptionInfo(30, "Tunable ops limit", gr.Slider, {"minimum": 1, "maximum": 100, "step": 1}), "cuda_mem_fraction": OptionInfo(0.0, "Memory limit", gr.Slider, {"minimum": 0, "maximum": 2.0, "step": 0.05}), - "torch_gc_threshold": OptionInfo(70, "GC threshold", gr.Slider, {"minimum": 0, "maximum": 100, "step": 1}), + "torch_gc_threshold": OptionInfo(70, "GC threshold", gr.Slider, {"minimum": 1, "maximum": 100, "step": 1}), "inference_mode": OptionInfo("no-grad", "Inference mode", gr.Radio, {"choices": ["no-grad", "inference-mode", "none"]}), "torch_malloc": OptionInfo("native", "Memory allocator", gr.Radio, {"choices": ['native', 'cudaMallocAsync'] }),