The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
Make loras work with --async-offload (#7824)
comfyanonymousac10a0d69e99
diff --git a/comfy/ops.py b/comfy/ops.pyindex 62daf447b..032787915 100644--- a/comfy/ops.py+++ b/comfy/ops.py@@ -22,6 +22,7 @@ import comfy.model_managementfrom comfy.cli_args import args, PerformanceFeatureimport comfy.floatimport comfy.rmsnorm+import contextlibcast_to = comfy.model_management.cast_to #TODO: remove once no more references@@ -38,20 +39,28 @@ def cast_bias_weight(s, input=None, dtype=None, device=None, bias_dtype=None):device = input.deviceoffload_stream = comfy.model_management.get_offload_stream(device)+ if offload_stream is not None:+ wf_context = offload_stream+ else:+ wf_context = contextlib.nullcontext()+bias = Nonenon_blocking = comfy.model_management.device_supports_non_blocking(device)if s.bias is not None:has_function = len(s.bias_function) > 0bias = comfy.model_management.cast_to(s.bias, bias_dtype, device, non_blocking=non_blocking, copy=has_function, stream=offload_stream)+if has_function:- for f in s.bias_function:- bias = f(bias)+ with wf_context:+ for f in s.bias_function:+ bias = f(bias)has_function = len(s.weight_function) > 0weight = comfy.model_management.cast_to(s.weight, dtype, device, non_blocking=non_blocking, copy=has_function, stream=offload_stream)if has_function:- for f in s.weight_function:- weight = f(weight)+ with wf_context:+ for f in s.weight_function:+ weight = f(weight)comfy.model_management.sync_stream(device, offload_stream)return weight, bias