diff --git a/comfy/ldm/flux/model.py b/comfy/ldm/flux/model.py index 21f1a877e..e7931c16d 100644 --- a/comfy/ldm/flux/model.py +++ b/comfy/ldm/flux/model.py @@ -124,10 +124,16 @@ class Flux(nn.Module): def forward(self, x, timestep, context, y, guidance, **kwargs): bs, c, h, w = x.shape - img = rearrange(x, "b c (h ph) (w pw) -> b (h w) (c ph pw)", ph=2, pw=2) + patch_size = 2 + pad_h = (patch_size - h % 2) % patch_size + pad_w = (patch_size - w % 2) % patch_size - h_len = (h // 2) - w_len = (w // 2) + x = torch.nn.functional.pad(x, (0, pad_w, 0, pad_h), mode='circular') + + img = rearrange(x, "b c (h ph) (w pw) -> b (h w) (c ph pw)", ph=patch_size, pw=patch_size) + + h_len = ((h + (patch_size // 2)) // patch_size) + w_len = ((w + (patch_size // 2)) // patch_size) img_ids = torch.zeros((h_len, w_len, 3), device=x.device, dtype=x.dtype) img_ids[..., 1] = img_ids[..., 1] + torch.linspace(0, h_len - 1, steps=h_len, device=x.device, dtype=x.dtype)[:, None] img_ids[..., 2] = img_ids[..., 2] + torch.linspace(0, w_len - 1, steps=w_len, device=x.device, dtype=x.dtype)[None, :] @@ -135,4 +141,4 @@ class Flux(nn.Module): txt_ids = torch.zeros((bs, context.shape[1], 3), device=x.device, dtype=x.dtype) out = self.forward_orig(img, img_ids, context, txt_ids, timestep, y, guidance) - return rearrange(out, "b (h w) (c ph pw) -> b c (h ph) (w pw)", h=h_len, w=w_len, ph=2, pw=2) + return rearrange(out, "b (h w) (c ph pw) -> b c (h ph) (w pw)", h=h_len, w=w_len, ph=2, pw=2)[:,:,:h,:w] diff --git a/comfy/nodes/base_nodes.py b/comfy/nodes/base_nodes.py index 6c02230b1..455f231bb 100644 --- a/comfy/nodes/base_nodes.py +++ b/comfy/nodes/base_nodes.py @@ -823,9 +823,14 @@ class UNETLoader: CATEGORY = "advanced/loaders" def load_unet(self, unet_name, weight_dtype): - weight_dtype = {"default":None, "fp8_e4m3fn":torch.float8_e4m3fn, "fp8_e5m2":torch.float8_e4m3fn}[weight_dtype] + dtype = None + if weight_dtype == "fp8_e4m3fn": + dtype = torch.float8_e4m3fn + elif weight_dtype == "fp8_e5m2": + dtype = torch.float8_e5m2 + unet_path = get_or_download("unet", unet_name, KNOWN_UNET_MODELS) - model = sd.load_unet(unet_path, dtype=weight_dtype) + model = sd.load_unet(unet_path, dtype=dtype) return (model,) class CLIPLoader: diff --git a/comfy/web/scripts/pnginfo.js b/comfy/web/scripts/pnginfo.js index 8b1b2c61c..4477ed7a1 100644 --- a/comfy/web/scripts/pnginfo.js +++ b/comfy/web/scripts/pnginfo.js @@ -190,9 +190,10 @@ function parseVorbisComment(dataView) { const comment = getString(dataView, offset, commentLength); offset += commentLength; - const [key, value] = comment.split('='); + const ind = comment.indexOf('=') + const key = comment.substring(0, ind); - comments[key] = value; + comments[key] = comment.substring(ind+1); } return comments; diff --git a/comfy_extras/nodes/nodes_audio.py b/comfy_extras/nodes/nodes_audio.py index 7136a2908..7dafe10e2 100644 --- a/comfy_extras/nodes/nodes_audio.py +++ b/comfy_extras/nodes/nodes_audio.py @@ -8,6 +8,7 @@ import io import json import struct import random +import hashlib from comfy.cli_args import args class EmptyLatentAudio: diff --git a/comfy_extras/nodes/nodes_flux.py b/comfy_extras/nodes/nodes_flux.py index 6c1e8b0e0..b690432b5 100644 --- a/comfy_extras/nodes/nodes_flux.py +++ b/comfy_extras/nodes/nodes_flux.py @@ -1,3 +1,4 @@ +import node_helpers class CLIPTextEncodeFlux: @classmethod @@ -11,7 +12,7 @@ class CLIPTextEncodeFlux: RETURN_TYPES = ("CONDITIONING",) FUNCTION = "encode" - CATEGORY = "advanced/conditioning" + CATEGORY = "advanced/conditioning/flux" def encode(self, clip, clip_l, t5xxl, guidance): tokens = clip.tokenize(clip_l) @@ -22,6 +23,25 @@ class CLIPTextEncodeFlux: output["guidance"] = guidance return ([[cond, output]], ) +class FluxGuidance: + @classmethod + def INPUT_TYPES(s): + return {"required": { + "conditioning": ("CONDITIONING", ), + "guidance": ("FLOAT", {"default": 3.5, "min": 0.0, "max": 100.0, "step": 0.1}), + }} + + RETURN_TYPES = ("CONDITIONING",) + FUNCTION = "append" + + CATEGORY = "advanced/conditioning/flux" + + def append(self, conditioning, guidance): + c = node_helpers.conditioning_set_values(conditioning, {"guidance": guidance}) + return (c, ) + + NODE_CLASS_MAPPINGS = { "CLIPTextEncodeFlux": CLIPTextEncodeFlux, + "FluxGuidance": FluxGuidance, } diff --git a/comfy_extras/nodes/nodes_pag.py b/comfy_extras/nodes/nodes_pag.py index aec78bd8a..eb28196f4 100644 --- a/comfy_extras/nodes/nodes_pag.py +++ b/comfy_extras/nodes/nodes_pag.py @@ -12,7 +12,7 @@ class PerturbedAttentionGuidance: return { "required": { "model": ("MODEL",), - "scale": ("FLOAT", {"default": 3.0, "min": 0.0, "max": 100.0, "step": 0.1, "round": 0.01}), + "scale": ("FLOAT", {"default": 3.0, "min": 0.0, "max": 100.0, "step": 0.01, "round": 0.01}), } } diff --git a/comfy_extras/nodes/nodes_sag.py b/comfy_extras/nodes/nodes_sag.py index 6d7c24515..e9a1da664 100644 --- a/comfy_extras/nodes/nodes_sag.py +++ b/comfy_extras/nodes/nodes_sag.py @@ -96,8 +96,8 @@ class SelfAttentionGuidance: @classmethod def INPUT_TYPES(s): return {"required": { "model": ("MODEL",), - "scale": ("FLOAT", {"default": 0.5, "min": -2.0, "max": 5.0, "step": 0.01, "round": 0.01}), - "blur_sigma": ("FLOAT", {"default": 2.0, "min": 0.0, "max": 10.0, "step": 0.01, "round": 0.01}), + "scale": ("FLOAT", {"default": 0.5, "min": -2.0, "max": 5.0, "step": 0.01}), + "blur_sigma": ("FLOAT", {"default": 2.0, "min": 0.0, "max": 10.0, "step": 0.1}), }} RETURN_TYPES = ("MODEL",) FUNCTION = "patch"