Skip to content

Commit 9d8a817

Browse files
Enable async offloading by default on Nvidia. (#10953)
Add --disable-async-offload to disable it. If this causes OOMs that go away when you --disable-async-offload please report it.
1 parent b59750a commit 9d8a817

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

comfy/cli_args.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ class LatentPreviewMethod(enum.Enum):
131131

132132
parser.add_argument("--reserve-vram", type=float, default=None, help="Set the amount of vram in GB you want to reserve for use by your OS/other software. By default some amount is reserved depending on your OS.")
133133

134-
parser.add_argument("--async-offload", action="store_true", help="Use async weight offloading.")
134+
parser.add_argument("--async-offload", nargs='?', const=2, type=int, default=None, metavar="NUM_STREAMS", help="Use async weight offloading. An optional argument controls the amount of offload streams. Default is 2. Enabled by default on Nvidia.")
135+
parser.add_argument("--disable-async-offload", action="store_true", help="Disable async weight offloading.")
135136

136137
parser.add_argument("--force-non-blocking", action="store_true", help="Force ComfyUI to use non-blocking operations for all applicable tensors. This may improve performance on some non-Nvidia systems but can cause issues with some workflows.")
137138

comfy/model_management.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,8 +1013,17 @@ def force_channels_last():
10131013

10141014
STREAMS = {}
10151015
NUM_STREAMS = 0
1016-
if args.async_offload:
1017-
NUM_STREAMS = 2
1016+
if args.async_offload is not None:
1017+
NUM_STREAMS = args.async_offload
1018+
else:
1019+
# Enable by default on Nvidia
1020+
if is_nvidia():
1021+
NUM_STREAMS = 2
1022+
1023+
if args.disable_async_offload:
1024+
NUM_STREAMS = 0
1025+
1026+
if NUM_STREAMS > 0:
10181027
logging.info("Using async weight offloading with {} streams".format(NUM_STREAMS))
10191028

10201029
def current_stream(device):

0 commit comments

Comments
 (0)