mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-04-18 22:42:35 +08:00
Merge upstream/master, keep local README.md
This commit is contained in:
commit
04faeead5b
@ -37,7 +37,7 @@ class ChromaRadianceParams(ChromaParams):
|
|||||||
nerf_final_head_type: str
|
nerf_final_head_type: str
|
||||||
# None means use the same dtype as the model.
|
# None means use the same dtype as the model.
|
||||||
nerf_embedder_dtype: Optional[torch.dtype]
|
nerf_embedder_dtype: Optional[torch.dtype]
|
||||||
|
use_x0: bool
|
||||||
|
|
||||||
class ChromaRadiance(Chroma):
|
class ChromaRadiance(Chroma):
|
||||||
"""
|
"""
|
||||||
@ -159,6 +159,9 @@ class ChromaRadiance(Chroma):
|
|||||||
self.skip_dit = []
|
self.skip_dit = []
|
||||||
self.lite = False
|
self.lite = False
|
||||||
|
|
||||||
|
if params.use_x0:
|
||||||
|
self.register_buffer("__x0__", torch.tensor([]))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _nerf_final_layer(self) -> nn.Module:
|
def _nerf_final_layer(self) -> nn.Module:
|
||||||
if self.params.nerf_final_head_type == "linear":
|
if self.params.nerf_final_head_type == "linear":
|
||||||
@ -276,6 +279,12 @@ class ChromaRadiance(Chroma):
|
|||||||
params_dict |= overrides
|
params_dict |= overrides
|
||||||
return params.__class__(**params_dict)
|
return params.__class__(**params_dict)
|
||||||
|
|
||||||
|
def _apply_x0_residual(self, predicted, noisy, timesteps):
|
||||||
|
|
||||||
|
# non zero during training to prevent 0 div
|
||||||
|
eps = 0.0
|
||||||
|
return (noisy - predicted) / (timesteps.view(-1,1,1,1) + eps)
|
||||||
|
|
||||||
def _forward(
|
def _forward(
|
||||||
self,
|
self,
|
||||||
x: Tensor,
|
x: Tensor,
|
||||||
@ -316,4 +325,11 @@ class ChromaRadiance(Chroma):
|
|||||||
transformer_options,
|
transformer_options,
|
||||||
attn_mask=kwargs.get("attention_mask", None),
|
attn_mask=kwargs.get("attention_mask", None),
|
||||||
)
|
)
|
||||||
return self.forward_nerf(img, img_out, params)[:, :, :h, :w]
|
|
||||||
|
out = self.forward_nerf(img, img_out, params)[:, :, :h, :w]
|
||||||
|
|
||||||
|
# If x0 variant → v-pred, just return this instead
|
||||||
|
if hasattr(self, "__x0__"):
|
||||||
|
out = self._apply_x0_residual(out, img, timestep)
|
||||||
|
return out
|
||||||
|
|
||||||
|
|||||||
@ -43,6 +43,7 @@ class HunyuanVideoParams:
|
|||||||
meanflow: bool
|
meanflow: bool
|
||||||
use_cond_type_embedding: bool
|
use_cond_type_embedding: bool
|
||||||
vision_in_dim: int
|
vision_in_dim: int
|
||||||
|
meanflow_sum: bool
|
||||||
|
|
||||||
|
|
||||||
class SelfAttentionRef(nn.Module):
|
class SelfAttentionRef(nn.Module):
|
||||||
@ -317,7 +318,7 @@ class HunyuanVideo(nn.Module):
|
|||||||
timesteps_r = transformer_options['sample_sigmas'][w[0] + 1]
|
timesteps_r = transformer_options['sample_sigmas'][w[0] + 1]
|
||||||
timesteps_r = timesteps_r.unsqueeze(0).to(device=timesteps.device, dtype=timesteps.dtype)
|
timesteps_r = timesteps_r.unsqueeze(0).to(device=timesteps.device, dtype=timesteps.dtype)
|
||||||
vec_r = self.time_r_in(timestep_embedding(timesteps_r, 256, time_factor=1000.0).to(img.dtype))
|
vec_r = self.time_r_in(timestep_embedding(timesteps_r, 256, time_factor=1000.0).to(img.dtype))
|
||||||
vec = (vec + vec_r) / 2
|
vec = (vec + vec_r) if self.params.meanflow_sum else (vec + vec_r) / 2
|
||||||
|
|
||||||
if ref_latent is not None:
|
if ref_latent is not None:
|
||||||
ref_latent_ids = self.img_ids(ref_latent)
|
ref_latent_ids = self.img_ids(ref_latent)
|
||||||
|
|||||||
@ -180,8 +180,10 @@ def detect_unet_config(state_dict, key_prefix, metadata=None):
|
|||||||
dit_config["use_cond_type_embedding"] = False
|
dit_config["use_cond_type_embedding"] = False
|
||||||
if '{}vision_in.proj.0.weight'.format(key_prefix) in state_dict_keys:
|
if '{}vision_in.proj.0.weight'.format(key_prefix) in state_dict_keys:
|
||||||
dit_config["vision_in_dim"] = state_dict['{}vision_in.proj.0.weight'.format(key_prefix)].shape[0]
|
dit_config["vision_in_dim"] = state_dict['{}vision_in.proj.0.weight'.format(key_prefix)].shape[0]
|
||||||
|
dit_config["meanflow_sum"] = True
|
||||||
else:
|
else:
|
||||||
dit_config["vision_in_dim"] = None
|
dit_config["vision_in_dim"] = None
|
||||||
|
dit_config["meanflow_sum"] = False
|
||||||
return dit_config
|
return dit_config
|
||||||
|
|
||||||
if '{}double_blocks.0.img_attn.norm.key_norm.scale'.format(key_prefix) in state_dict_keys and ('{}img_in.weight'.format(key_prefix) in state_dict_keys or f"{key_prefix}distilled_guidance_layer.norms.0.scale" in state_dict_keys): #Flux, Chroma or Chroma Radiance (has no img_in.weight)
|
if '{}double_blocks.0.img_attn.norm.key_norm.scale'.format(key_prefix) in state_dict_keys and ('{}img_in.weight'.format(key_prefix) in state_dict_keys or f"{key_prefix}distilled_guidance_layer.norms.0.scale" in state_dict_keys): #Flux, Chroma or Chroma Radiance (has no img_in.weight)
|
||||||
@ -257,6 +259,8 @@ def detect_unet_config(state_dict, key_prefix, metadata=None):
|
|||||||
dit_config["nerf_tile_size"] = 512
|
dit_config["nerf_tile_size"] = 512
|
||||||
dit_config["nerf_final_head_type"] = "conv" if f"{key_prefix}nerf_final_layer_conv.norm.scale" in state_dict_keys else "linear"
|
dit_config["nerf_final_head_type"] = "conv" if f"{key_prefix}nerf_final_layer_conv.norm.scale" in state_dict_keys else "linear"
|
||||||
dit_config["nerf_embedder_dtype"] = torch.float32
|
dit_config["nerf_embedder_dtype"] = torch.float32
|
||||||
|
if "__x0__" in state_dict_keys: # x0 pred
|
||||||
|
dit_config["use_x0"] = True
|
||||||
else:
|
else:
|
||||||
dit_config["guidance_embed"] = "{}guidance_in.in_layer.weight".format(key_prefix) in state_dict_keys
|
dit_config["guidance_embed"] = "{}guidance_in.in_layer.weight".format(key_prefix) in state_dict_keys
|
||||||
dit_config["yak_mlp"] = '{}double_blocks.0.img_mlp.gate_proj.weight'.format(key_prefix) in state_dict_keys
|
dit_config["yak_mlp"] = '{}double_blocks.0.img_mlp.gate_proj.weight'.format(key_prefix) in state_dict_keys
|
||||||
|
|||||||
@ -35,6 +35,7 @@ import comfy.model_management
|
|||||||
import comfy.patcher_extension
|
import comfy.patcher_extension
|
||||||
import comfy.utils
|
import comfy.utils
|
||||||
from comfy.comfy_types import UnetWrapperFunction
|
from comfy.comfy_types import UnetWrapperFunction
|
||||||
|
from comfy.quant_ops import QuantizedTensor
|
||||||
from comfy.patcher_extension import CallbacksMP, PatcherInjection, WrappersMP
|
from comfy.patcher_extension import CallbacksMP, PatcherInjection, WrappersMP
|
||||||
|
|
||||||
|
|
||||||
@ -665,12 +666,18 @@ class ModelPatcher:
|
|||||||
module_mem = comfy.model_management.module_size(m)
|
module_mem = comfy.model_management.module_size(m)
|
||||||
module_offload_mem = module_mem
|
module_offload_mem = module_mem
|
||||||
if hasattr(m, "comfy_cast_weights"):
|
if hasattr(m, "comfy_cast_weights"):
|
||||||
weight_key = "{}.weight".format(n)
|
def check_module_offload_mem(key):
|
||||||
bias_key = "{}.bias".format(n)
|
if key in self.patches:
|
||||||
if weight_key in self.patches:
|
return low_vram_patch_estimate_vram(self.model, key)
|
||||||
module_offload_mem += low_vram_patch_estimate_vram(self.model, weight_key)
|
model_dtype = getattr(self.model, "manual_cast_dtype", None)
|
||||||
if bias_key in self.patches:
|
weight, _, _ = get_key_weight(self.model, key)
|
||||||
module_offload_mem += low_vram_patch_estimate_vram(self.model, bias_key)
|
if model_dtype is None or weight is None:
|
||||||
|
return 0
|
||||||
|
if (weight.dtype != model_dtype or isinstance(weight, QuantizedTensor)):
|
||||||
|
return weight.numel() * model_dtype.itemsize
|
||||||
|
return 0
|
||||||
|
module_offload_mem += check_module_offload_mem("{}.weight".format(n))
|
||||||
|
module_offload_mem += check_module_offload_mem("{}.bias".format(n))
|
||||||
loading.append((module_offload_mem, module_mem, n, m, params))
|
loading.append((module_offload_mem, module_mem, n, m, params))
|
||||||
return loading
|
return loading
|
||||||
|
|
||||||
@ -923,7 +930,7 @@ class ModelPatcher:
|
|||||||
patch_counter += 1
|
patch_counter += 1
|
||||||
cast_weight = True
|
cast_weight = True
|
||||||
|
|
||||||
if cast_weight:
|
if cast_weight and hasattr(m, "comfy_cast_weights"):
|
||||||
m.prev_comfy_cast_weights = m.comfy_cast_weights
|
m.prev_comfy_cast_weights = m.comfy_cast_weights
|
||||||
m.comfy_cast_weights = True
|
m.comfy_cast_weights = True
|
||||||
m.comfy_patched_weights = False
|
m.comfy_patched_weights = False
|
||||||
|
|||||||
@ -22,7 +22,6 @@ import comfy.model_management
|
|||||||
from comfy.cli_args import args, PerformanceFeature
|
from comfy.cli_args import args, PerformanceFeature
|
||||||
import comfy.float
|
import comfy.float
|
||||||
import comfy.rmsnorm
|
import comfy.rmsnorm
|
||||||
import contextlib
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
def run_every_op():
|
def run_every_op():
|
||||||
@ -94,13 +93,6 @@ def cast_bias_weight(s, input=None, dtype=None, device=None, bias_dtype=None, of
|
|||||||
else:
|
else:
|
||||||
offload_stream = None
|
offload_stream = None
|
||||||
|
|
||||||
if offload_stream is not None:
|
|
||||||
wf_context = offload_stream
|
|
||||||
if hasattr(wf_context, "as_context"):
|
|
||||||
wf_context = wf_context.as_context(offload_stream)
|
|
||||||
else:
|
|
||||||
wf_context = contextlib.nullcontext()
|
|
||||||
|
|
||||||
non_blocking = comfy.model_management.device_supports_non_blocking(device)
|
non_blocking = comfy.model_management.device_supports_non_blocking(device)
|
||||||
|
|
||||||
weight_has_function = len(s.weight_function) > 0
|
weight_has_function = len(s.weight_function) > 0
|
||||||
|
|||||||
@ -399,7 +399,10 @@ class TensorCoreFP8Layout(QuantizedLayout):
|
|||||||
orig_dtype = tensor.dtype
|
orig_dtype = tensor.dtype
|
||||||
|
|
||||||
if isinstance(scale, str) and scale == "recalculate":
|
if isinstance(scale, str) and scale == "recalculate":
|
||||||
scale = torch.amax(tensor.abs()) / torch.finfo(dtype).max
|
scale = torch.amax(tensor.abs()).to(dtype=torch.float32) / torch.finfo(dtype).max
|
||||||
|
if tensor.dtype not in [torch.float32, torch.bfloat16]: # Prevent scale from being too small
|
||||||
|
tensor_info = torch.finfo(tensor.dtype)
|
||||||
|
scale = (1.0 / torch.clamp((1.0 / scale), min=tensor_info.min, max=tensor_info.max))
|
||||||
|
|
||||||
if scale is not None:
|
if scale is not None:
|
||||||
if not isinstance(scale, torch.Tensor):
|
if not isinstance(scale, torch.Tensor):
|
||||||
|
|||||||
@ -127,6 +127,8 @@ class CLIP:
|
|||||||
|
|
||||||
self.tokenizer = tokenizer(embedding_directory=embedding_directory, tokenizer_data=tokenizer_data)
|
self.tokenizer = tokenizer(embedding_directory=embedding_directory, tokenizer_data=tokenizer_data)
|
||||||
self.patcher = comfy.model_patcher.ModelPatcher(self.cond_stage_model, load_device=load_device, offload_device=offload_device)
|
self.patcher = comfy.model_patcher.ModelPatcher(self.cond_stage_model, load_device=load_device, offload_device=offload_device)
|
||||||
|
#Match torch.float32 hardcode upcast in TE implemention
|
||||||
|
self.patcher.set_model_compute_dtype(torch.float32)
|
||||||
self.patcher.hook_mode = comfy.hooks.EnumHookMode.MinVram
|
self.patcher.hook_mode = comfy.hooks.EnumHookMode.MinVram
|
||||||
self.patcher.is_clip = True
|
self.patcher.is_clip = True
|
||||||
self.apply_hooks_to_conds = None
|
self.apply_hooks_to_conds = None
|
||||||
|
|||||||
@ -803,12 +803,17 @@ def safetensors_header(safetensors_path, max_size=100*1024*1024):
|
|||||||
return None
|
return None
|
||||||
return f.read(length_of_header)
|
return f.read(length_of_header)
|
||||||
|
|
||||||
|
ATTR_UNSET={}
|
||||||
|
|
||||||
def set_attr(obj, attr, value):
|
def set_attr(obj, attr, value):
|
||||||
attrs = attr.split(".")
|
attrs = attr.split(".")
|
||||||
for name in attrs[:-1]:
|
for name in attrs[:-1]:
|
||||||
obj = getattr(obj, name)
|
obj = getattr(obj, name)
|
||||||
prev = getattr(obj, attrs[-1])
|
prev = getattr(obj, attrs[-1], ATTR_UNSET)
|
||||||
setattr(obj, attrs[-1], value)
|
if value is ATTR_UNSET:
|
||||||
|
delattr(obj, attrs[-1])
|
||||||
|
else:
|
||||||
|
setattr(obj, attrs[-1], value)
|
||||||
return prev
|
return prev
|
||||||
|
|
||||||
def set_attr_param(obj, attr, value):
|
def set_attr_param(obj, attr, value):
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
# This file is automatically generated by the build process when version is
|
# This file is automatically generated by the build process when version is
|
||||||
# updated in pyproject.toml.
|
# updated in pyproject.toml.
|
||||||
__version__ = "0.3.76"
|
__version__ = "0.4.0"
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "ComfyUI"
|
name = "ComfyUI"
|
||||||
version = "0.3.76"
|
version = "0.4.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = { file = "LICENSE" }
|
license = { file = "LICENSE" }
|
||||||
requires-python = ">=3.9"
|
requires-python = ">=3.9"
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
comfyui-frontend-package==1.33.10
|
comfyui-frontend-package==1.33.13
|
||||||
comfyui-workflow-templates==0.7.54
|
comfyui-workflow-templates==0.7.54
|
||||||
comfyui-embedded-docs==0.3.1
|
comfyui-embedded-docs==0.3.1
|
||||||
torch
|
torch
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user