The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
ace15: Use dynamic_vram friendly trange (#12409)
rattus2a4328d63981
diff --git a/comfy/k_diffusion/sampling.py b/comfy/k_diffusion/sampling.pyindex c0c51d51a..6978eb717 100644--- a/comfy/k_diffusion/sampling.py+++ b/comfy/k_diffusion/sampling.py@@ -1,12 +1,11 @@import math-import timefrom functools import partialfrom scipy import integrateimport torchfrom torch import nnimport torchsde-from tqdm.auto import trange as trange_, tqdm+from tqdm.auto import tqdmfrom . import utilsfrom . import deis@@ -15,34 +14,7 @@ import comfy.model_patcherimport comfy.model_samplingimport comfy.memory_management---def trange(*args, **kwargs):- if comfy.memory_management.aimdo_allocator is None:- return trange_(*args, **kwargs)-- pbar = trange_(*args, **kwargs, smoothing=1.0)- pbar._i = 0- pbar.set_postfix_str(" Model Initializing ... ")-- _update = pbar.update-- def warmup_update(n=1):- pbar._i += 1- if pbar._i == 1:- pbar.i1_time = time.time()- pbar.set_postfix_str(" Model Initialization complete! ")- elif pbar._i == 2:- #bring forward the effective start time based the the diff between first and second iteration- #to attempt to remove load overhead from the final step rate estimate.- pbar.start_t = pbar.i1_time - (time.time() - pbar.i1_time)- pbar.set_postfix_str("")-- _update(n)-- pbar.update = warmup_update- return pbar-+from comfy.utils import model_trange as trangedef append_zero(x):return torch.cat([x, x.new_zeros([1])])diff --git a/comfy/text_encoders/ace15.py b/comfy/text_encoders/ace15.pyindex 73697b3c1..b8198a820 100644--- a/comfy/text_encoders/ace15.py+++ b/comfy/text_encoders/ace15.py@@ -3,7 +3,6 @@ import comfy.text_encoders.llamafrom comfy import sd1_clipimport torchimport math-from tqdm.auto import trangeimport yamlimport comfy.utils@@ -52,7 +51,7 @@ def sample_manual_loop_no_classes(progress_bar = comfy.utils.ProgressBar(max_new_tokens)- for step in trange(max_new_tokens, desc="LM sampling"):+ for step in comfy.utils.model_trange(max_new_tokens, desc="LM sampling"):outputs = model.transformer(None, attention_mask, embeds=embeds.to(execution_dtype), num_tokens=num_tokens, intermediate_output=None, dtype=execution_dtype, embeds_info=embeds_info, past_key_values=past_key_values)next_token_logits = model.transformer.logits(outputs[0])[:, -1]past_key_values = outputs[2]diff --git a/comfy/utils.py b/comfy/utils.pyindex edd80cebe..e0a94e2e1 100644--- a/comfy/utils.py+++ b/comfy/utils.py@@ -27,6 +27,7 @@ from PIL import Imageimport loggingimport itertoolsfrom torch.nn.functional import interpolate+from tqdm.auto import trangefrom einops import rearrangefrom comfy.cli_args import args, enables_dynamic_vramimport json@@ -1155,6 +1156,32 @@ def tiled_scale_multidim(samples, function, tile=(64, 64), overlap=8, upscale_amdef tiled_scale(samples, function, tile_x=64, tile_y=64, overlap = 8, upscale_amount = 4, out_channels = 3, output_device="cpu", pbar = None):return tiled_scale_multidim(samples, function, (tile_y, tile_x), overlap=overlap, upscale_amount=upscale_amount, out_channels=out_channels, output_device=output_device, pbar=pbar)+def model_trange(*args, **kwargs):+ if comfy.memory_management.aimdo_allocator is None:+ return trange(*args, **kwargs)++ pbar = trange(*args, **kwargs, smoothing=1.0)+ pbar._i = 0+ pbar.set_postfix_str(" Model Initializing ... ")++ _update = pbar.update++ def warmup_update(n=1):+ pbar._i += 1+ if pbar._i == 1:+ pbar.i1_time = time.time()+ pbar.set_postfix_str(" Model Initialization complete! ")+ elif pbar._i == 2:+ #bring forward the effective start time based the the diff between first and second iteration+ #to attempt to remove load overhead from the final step rate estimate.+ pbar.start_t = pbar.i1_time - (time.time() - pbar.i1_time)+ pbar.set_postfix_str("")++ _update(n)++ pbar.update = warmup_update+ return pbar+PROGRESS_BAR_ENABLED = Truedef set_progress_bar_enabled(enabled):global PROGRESS_BAR_ENABLED