Skip to content

Commit

Permalink
Remove some trailing white space.
Browse files Browse the repository at this point in the history
  • Loading branch information
comfyanonymous committed Dec 27, 2024
1 parent 9cfd185 commit d170292
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 38 deletions.
2 changes: 1 addition & 1 deletion comfy/controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def get_models(self):
if self.previous_controlnet is not None:
out += self.previous_controlnet.get_models()
return out

def get_extra_hooks(self):
out = []
if self.extra_hooks is not None:
Expand Down
10 changes: 5 additions & 5 deletions comfy/extra_samplers/uni_pc.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(
'linear' or 'cosine' for continuous-time DPMs.
Returns:
A wrapper object of the forward SDE (VP type).
===============================================================
Example:
Expand Down Expand Up @@ -208,7 +208,7 @@ def model_wrapper(
arXiv preprint arXiv:2202.00512 (2022).
[2] Ho, Jonathan, et al. "Imagen Video: High Definition Video Generation with Diffusion Models."
arXiv preprint arXiv:2210.02303 (2022).
4. "score": marginal score function. (Trained by denoising score matching).
Note that the score function and the noise prediction model follows a simple relationship:
```
Expand Down Expand Up @@ -245,7 +245,7 @@ def model_wrapper(
[4] Ho, Jonathan, and Tim Salimans. "Classifier-free diffusion guidance."
arXiv preprint arXiv:2207.12598 (2022).
The `t_input` is the time label of the model, which may be discrete-time labels (i.e. 0 to 999)
or continuous-time labels (i.e. epsilon to T).
Expand Down Expand Up @@ -621,7 +621,7 @@ def multistep_uni_pc_bh_update(self, x, model_prev_list, t_prev_list, t, order,
B_h = torch.expm1(hh)
else:
raise NotImplementedError()

for i in range(1, order + 1):
R.append(torch.pow(rks, i - 1))
b.append(h_phi_k * factorial_i / B_h)
Expand Down Expand Up @@ -870,4 +870,4 @@ def sample_unipc(model, noise, sigmas, extra_args=None, callback=None, disable=F
return x

def sample_unipc_bh2(model, noise, sigmas, extra_args=None, callback=None, disable=False):
return sample_unipc(model, noise, sigmas, extra_args, callback, disable, variant='bh2')
return sample_unipc(model, noise, sigmas, extra_args, callback, disable, variant='bh2')
2 changes: 1 addition & 1 deletion comfy/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self, strength_model=1.0, strength_clip=1.0):
self.need_weight_init = True
self._strength_model = strength_model
self._strength_clip = strength_clip

@property
def strength_model(self):
return self._strength_model * self.strength
Expand Down
2 changes: 1 addition & 1 deletion comfy/k_diffusion/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ def post_cfg_function(args):
nonlocal uncond_denoised
uncond_denoised = args["uncond_denoised"]
return args["denoised"]

model_options = extra_args.get("model_options", {}).copy()
extra_args["model_options"] = comfy.model_patcher.set_model_options_post_cfg_function(model_options, post_cfg_function, disable_cfg1_optimization=True)

Expand Down
2 changes: 1 addition & 1 deletion comfy/ldm/modules/sub_quadratic_attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def get_mask_chunk(chunk_idx: int) -> Tensor:
value=value,
mask=mask,
)

# TODO: maybe we should use torch.empty_like(query) to allocate storage in-advance,
# and pass slices to be mutated, instead of torch.cat()ing the returned slices
res = torch.cat([
Expand Down
2 changes: 1 addition & 1 deletion comfy/ldm/pixart/pixartms.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def forward(self, x, timesteps, context, c_size=None, c_ar=None, **kwargs):
if self.micro_conditioning:
if c_size is None:
c_size = torch.tensor([H*8, W*8], dtype=x.dtype, device=x.device).repeat(B, 1)

if c_ar is None:
c_ar = torch.tensor([H/W], dtype=x.dtype, device=x.device).repeat(B, 1)

Expand Down
4 changes: 2 additions & 2 deletions comfy/model_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def detect_unet_config(state_dict, key_prefix):
if pe_key in state_dict_keys:
dit_config["input_size"] = int(math.sqrt(state_dict[pe_key].shape[1])) * patch_size
dit_config["pe_interpolation"] = dit_config["input_size"] // (512//8) # guess

ar_key = "{}ar_embedder.mlp.0.weight".format(key_prefix)
if ar_key in state_dict_keys:
dit_config["image_model"] = "pixart_alpha"
Expand Down Expand Up @@ -571,7 +571,7 @@ def unet_config_from_diffusers_unet(state_dict, dtype=None):
'transformer_depth': [0, 1, 1], 'channel_mult': [1, 2, 4], 'transformer_depth_middle': -2, 'use_linear_in_transformer': False,
'context_dim': 768, 'num_head_channels': 64, 'transformer_depth_output': [0, 0, 1, 1, 1, 1],
'use_temporal_attention': False, 'use_temporal_resblock': False}

SD15_diffusers_inpaint = {'use_checkpoint': False, 'image_size': 32, 'out_channels': 4, 'use_spatial_transformer': True, 'legacy': False, 'adm_in_channels': None,
'dtype': dtype, 'in_channels': 9, 'model_channels': 320, 'num_res_blocks': [2, 2, 2, 2], 'transformer_depth': [1, 1, 1, 1, 1, 1, 0, 0],
'channel_mult': [1, 2, 4, 4], 'transformer_depth_middle': 1, 'use_linear_in_transformer': False, 'context_dim': 768, 'num_heads': 8,
Expand Down
2 changes: 1 addition & 1 deletion comfy/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def prepare_noise(latent_image, seed, noise_inds=None):
generator = torch.manual_seed(seed)
if noise_inds is None:
return torch.randn(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, generator=generator, device="cpu")

unique_inds, inverse = np.unique(noise_inds, return_inverse=True)
noises = []
for i in range(unique_inds[-1]+1):
Expand Down
2 changes: 1 addition & 1 deletion comfy/sampler_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_extra_hooks_from_cnet(cnet: ControlBase, _list: list):
if cnet.previous_controlnet is None:
return _list
return get_extra_hooks_from_cnet(cnet.previous_controlnet, _list)

hooks_list = []
cnets = set(cnets)
for base_cnet in cnets:
Expand Down
10 changes: 5 additions & 5 deletions comfy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def pixart_to_diffusers(mmdit_config, output_prefix=""):

for k in PIXART_MAP_BASIC:
key_map[k[1]] = "{}{}".format(output_prefix, k[0])

return key_map

def auraflow_to_diffusers(mmdit_config, output_prefix=""):
Expand Down Expand Up @@ -702,7 +702,7 @@ def get_attr(obj, attr):
def bislerp(samples, width, height):
def slerp(b1, b2, r):
'''slerps batches b1, b2 according to ratio r, batches should be flat e.g. NxC'''

c = b1.shape[-1]

#norms
Expand Down Expand Up @@ -730,13 +730,13 @@ def slerp(b1, b2, r):
res[dot > 1 - 1e-5] = b1[dot > 1 - 1e-5]
res[dot < 1e-5 - 1] = (b1 * (1.0-r) + b2 * r)[dot < 1e-5 - 1]
return res

def generate_bilinear_data(length_old, length_new, device):
coords_1 = torch.arange(length_old, dtype=torch.float32, device=device).reshape((1,1,1,-1))
coords_1 = torch.nn.functional.interpolate(coords_1, size=(1, length_new), mode="bilinear")
ratios = coords_1 - coords_1.floor()
coords_1 = coords_1.to(torch.int64)

coords_2 = torch.arange(length_old, dtype=torch.float32, device=device).reshape((1,1,1,-1)) + 1
coords_2[:,:,:,-1] -= 1
coords_2 = torch.nn.functional.interpolate(coords_2, size=(1, length_new), mode="bilinear")
Expand All @@ -747,7 +747,7 @@ def generate_bilinear_data(length_old, length_new, device):
samples = samples.float()
n,c,h,w = samples.shape
h_new, w_new = (height, width)

#linear w
ratios, coords_1, coords_2 = generate_bilinear_data(w, w_new, samples.device)
coords_1 = coords_1.expand((n, c, h, -1))
Expand Down
4 changes: 2 additions & 2 deletions comfy_extras/nodes_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def feather(self, mask, left, top, right, bottom):
output[:, -y, :] *= feather_rate

return (output,)

class GrowMask:
@classmethod
def INPUT_TYPES(cls):
Expand All @@ -316,7 +316,7 @@ def INPUT_TYPES(cls):
"tapered_corners": ("BOOLEAN", {"default": True}),
},
}

CATEGORY = "mask"

RETURN_TYPES = ("MASK",)
Expand Down
2 changes: 1 addition & 1 deletion comfy_extras/nodes_perpneg.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def set_cfg(self, cfg, neg_scale):
def predict_noise(self, x, timestep, model_options={}, seed=None):
# in CFGGuider.predict_noise, we call sampling_function(), which uses cfg_function() to compute pos & neg
# but we'd rather do a single batch of sampling pos, neg, and empty, so we call calc_cond_batch([pos,neg,empty]) directly

positive_cond = self.conds.get("positive", None)
negative_cond = self.conds.get("negative", None)
empty_cond = self.conds.get("empty_negative_prompt", None)
Expand Down
4 changes: 2 additions & 2 deletions comfy_extras/nodes_rebatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_slices(indexable, num, batch_size):
return slices, indexable[num * batch_size:]
else:
return slices, None

@staticmethod
def slice_batch(batch, num, batch_size):
result = [LatentRebatch.get_slices(x, num, batch_size) for x in batch]
Expand Down Expand Up @@ -81,7 +81,7 @@ def rebatch(self, latents, batch_size):
if current_batch[0].shape[0] > batch_size:
num = current_batch[0].shape[0] // batch_size
sliced, remainder = self.slice_batch(current_batch, num, batch_size)

for i in range(num):
output_list.append({'samples': sliced[0][i], 'noise_mask': sliced[1][i], 'batch_index': sliced[2][i]})

Expand Down
7 changes: 3 additions & 4 deletions comfy_extras/nodes_tomesd.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,16 @@ def bipartite_soft_matching_random2d(metric: torch.Tensor,
return do_nothing, do_nothing

gather = mps_gather_workaround if metric.device.type == "mps" else torch.gather

with torch.no_grad():

hsy, wsx = h // sy, w // sx

# For each sy by sx kernel, randomly assign one token to be dst and the rest src
if no_rand:
rand_idx = torch.zeros(hsy, wsx, 1, device=metric.device, dtype=torch.int64)
else:
rand_idx = torch.randint(sy*sx, size=(hsy, wsx, 1), device=metric.device)

# The image might not divide sx and sy, so we need to work on a view of the top left if the idx buffer instead
idx_buffer_view = torch.zeros(hsy, wsx, sy*sx, device=metric.device, dtype=torch.int64)
idx_buffer_view.scatter_(dim=2, index=rand_idx, src=-torch.ones_like(rand_idx, dtype=rand_idx.dtype))
Expand Down Expand Up @@ -99,7 +98,7 @@ def split(x):
def merge(x: torch.Tensor, mode="mean") -> torch.Tensor:
src, dst = split(x)
n, t1, c = src.shape

unm = gather(src, dim=-2, index=unm_idx.expand(n, t1 - r, c))
src = gather(src, dim=-2, index=src_idx.expand(n, r, c))
dst = dst.scatter_reduce(-2, dst_idx.expand(n, r, c), src, reduce=mode)
Expand Down
20 changes: 10 additions & 10 deletions nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def INPUT_TYPES(s) -> InputTypeDict:
def encode(self, clip, text):
tokens = clip.tokenize(text)
return (clip.encode_from_tokens_scheduled(tokens), )


class ConditioningCombine:
@classmethod
Expand Down Expand Up @@ -641,7 +641,7 @@ def INPUT_TYPES(s):
"strength_clip": ("FLOAT", {"default": 1.0, "min": -100.0, "max": 100.0, "step": 0.01, "tooltip": "How strongly to modify the CLIP model. This value can be negative."}),
}
}

RETURN_TYPES = ("MODEL", "CLIP")
OUTPUT_TOOLTIPS = ("The modified diffusion model.", "The modified CLIP model.")
FUNCTION = "load_lora"
Expand Down Expand Up @@ -1211,7 +1211,7 @@ def frombatch(self, samples, batch_index, length):
else:
s["batch_index"] = samples["batch_index"][batch_index:batch_index + length]
return (s,)

class RepeatLatentBatch:
@classmethod
def INPUT_TYPES(s):
Expand All @@ -1226,7 +1226,7 @@ def INPUT_TYPES(s):
def repeat(self, samples, amount):
s = samples.copy()
s_in = samples["samples"]

s["samples"] = s_in.repeat((amount, 1,1,1))
if "noise_mask" in samples and samples["noise_mask"].shape[0] > 1:
masks = samples["noise_mask"]
Expand Down Expand Up @@ -1636,15 +1636,15 @@ def INPUT_TYPES(s):
FUNCTION = "load_image"
def load_image(self, image):
image_path = folder_paths.get_annotated_filepath(image)

img = node_helpers.pillow(Image.open, image_path)

output_images = []
output_masks = []
w, h = None, None

excluded_formats = ['MPO']

for i in ImageSequence.Iterator(img):
i = node_helpers.pillow(ImageOps.exif_transpose, i)

Expand All @@ -1655,10 +1655,10 @@ def load_image(self, image):
if len(output_images) == 0:
w = image.size[0]
h = image.size[1]

if image.size[0] != w or image.size[1] != h:
continue

image = np.array(image).astype(np.float32) / 255.0
image = torch.from_numpy(image)[None,]
if 'A' in i.getbands():
Expand Down Expand Up @@ -2234,5 +2234,5 @@ def init_extra_nodes(init_custom_nodes=True):
else:
logging.warning("Please do a: pip install -r requirements.txt")
logging.warning("")

return import_failed

0 comments on commit d170292

Please sign in to comment.