Skip to content

Commit

Permalink
speed up using non_blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
wkpark committed Sep 22, 2024
1 parent eb6898b commit 452e349
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion modules/lowvram.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def setup_for_low_vram(sd_model, use_medvram):

parents = {}

non_blocking = devices.supports_non_blocking()

def send_me_to_gpu(module, _):
"""send this module to GPU; send whatever tracked module was previous in GPU to CPU;
we add this as forward_pre_hook to a lot of modules and this way all but one of them will
Expand All @@ -69,7 +71,7 @@ def send_me_to_gpu(module, _):
return

if module_in_gpu is not None:
module_in_gpu.to(cpu)
module_in_gpu.to(cpu, non_blocking=non_blocking)
devices.torch_gc()

module.to(devices.device)
Expand Down

0 comments on commit 452e349

Please sign in to comment.