improve gc threshold

This commit is contained in:
Vladimir Mandic
2024-06-21 12:57:15 -04:00
parent 77657611c0
commit b036c2fc3b
3 changed files with 12 additions and 7 deletions
+2
View File
@@ -12,6 +12,7 @@ But there's more than SD3:
- support for **PixArt-Sigma** in small/medium/large variants
- support for **HunyuanDiT 1.1**
- (finally) new release of **Torch-DirectML**
- additional efficiencies for users with low vram gpus
- over 20 overall fixes
### Model Improvements
@@ -47,6 +48,7 @@ But there's more than SD3:
*note*: new directml is finally based on modern `torch` 2.3.1!
- extra networks: info display now contains link to source url if model if its known
works for civitai and huggingface models
- force gc for lowvram users and improve gc logging
- improved google.colab support
- css tweaks for standardui
- css tweaks for modernui
+1 -1
View File
@@ -139,7 +139,7 @@ class Processor():
self.model = None
self.processor_id = processor_id
# self.override = None
devices.torch_gc()
# devices.torch_gc()
self.load_config = { 'cache_dir': cache_dir }
def config(self, processor_id = None):
+9 -6
View File
@@ -140,11 +140,8 @@ def torch_gc(force=False):
used_gpu = round(100 * gpu.get('used', 0) / gpu.get('total', 1)) if gpu.get('total', 1) > 1 else 0
used_ram = round(100 * ram.get('used', 0) / ram.get('total', 1)) if ram.get('total', 1) > 1 else 0
global previous_oom # pylint: disable=global-statement
if force or shared.opts.torch_gc_threshold == 0:
log.debug(f'Forced Torch GC: GPU={used_gpu}% RAM={used_ram}% {mem}')
force = True
elif used_gpu >= shared.opts.torch_gc_threshold or used_ram >= shared.opts.torch_gc_threshold:
log.info(f'High memory utilization: GPU={used_gpu}% RAM={used_ram}% {mem}')
threshold = 0 if (shared.cmd_opts.lowvram and not shared.cmd_opts.use_zluda) else shared.opts.torch_gc_threshold
if force or threshold == 0 or used_gpu >= threshold or used_ram >= threshold:
force = True
if oom > previous_oom:
previous_oom = oom
@@ -163,7 +160,13 @@ def torch_gc(force=False):
except Exception:
pass
t1 = time.time()
log.debug(f'GC: collected={collected} device={torch.device(get_optimal_device_name())} {memstats.memory_stats()} time={round(t1 - t0, 2)}')
mem = memstats.memory_stats()
saved = round(gpu.get('used', 0) - mem.get('gpu', {}).get('used', 0), 2)
before = { 'gpu': gpu.get('used', 0), 'ram': ram.get('used', 0) }
after = { 'gpu': mem.get('gpu', {}).get('used', 0), 'ram': mem.get('ram', {}).get('used', 0), 'retries': mem.get('retries', 0), 'oom': mem.get('oom', 0) }
utilization = { 'gpu': used_gpu, 'ram': used_ram, 'threshold': threshold }
results = { 'collected': collected, 'saved': saved }
log.debug(f'GC: utilization={utilization} gc={results} beofre={before} after={after} device={torch.device(get_optimal_device_name())} fn={sys._getframe(1).f_code.co_name} time={round(t1 - t0, 2)}') # pylint: disable=protected-access
def set_cuda_sync_mode(mode):