Merge branch 'comfyanonymous:master' into master

This commit is contained in:
patientx 2025-08-04 10:42:15 +03:00 committed by GitHub
commit d823c0c615
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 13 deletions

View File

@ -10,8 +10,8 @@ class CONDRegular:
def _copy_with(self, cond): def _copy_with(self, cond):
return self.__class__(cond) return self.__class__(cond)
def process_cond(self, batch_size, device, **kwargs): def process_cond(self, batch_size, **kwargs):
return self._copy_with(comfy.utils.repeat_to_batch_size(self.cond, batch_size).to(device)) return self._copy_with(comfy.utils.repeat_to_batch_size(self.cond, batch_size))
def can_concat(self, other): def can_concat(self, other):
if self.cond.shape != other.cond.shape: if self.cond.shape != other.cond.shape:
@ -29,14 +29,14 @@ class CONDRegular:
class CONDNoiseShape(CONDRegular): class CONDNoiseShape(CONDRegular):
def process_cond(self, batch_size, device, area, **kwargs): def process_cond(self, batch_size, area, **kwargs):
data = self.cond data = self.cond
if area is not None: if area is not None:
dims = len(area) // 2 dims = len(area) // 2
for i in range(dims): for i in range(dims):
data = data.narrow(i + 2, area[i + dims], area[i]) data = data.narrow(i + 2, area[i + dims], area[i])
return self._copy_with(comfy.utils.repeat_to_batch_size(data, batch_size).to(device)) return self._copy_with(comfy.utils.repeat_to_batch_size(data, batch_size))
class CONDCrossAttn(CONDRegular): class CONDCrossAttn(CONDRegular):
@ -73,7 +73,7 @@ class CONDConstant(CONDRegular):
def __init__(self, cond): def __init__(self, cond):
self.cond = cond self.cond = cond
def process_cond(self, batch_size, device, **kwargs): def process_cond(self, batch_size, **kwargs):
return self._copy_with(self.cond) return self._copy_with(self.cond)
def can_concat(self, other): def can_concat(self, other):
@ -92,10 +92,10 @@ class CONDList(CONDRegular):
def __init__(self, cond): def __init__(self, cond):
self.cond = cond self.cond = cond
def process_cond(self, batch_size, device, **kwargs): def process_cond(self, batch_size, **kwargs):
out = [] out = []
for c in self.cond: for c in self.cond:
out.append(comfy.utils.repeat_to_batch_size(c, batch_size).to(device)) out.append(comfy.utils.repeat_to_batch_size(c, batch_size))
return self._copy_with(out) return self._copy_with(out)

View File

@ -28,6 +28,7 @@ import comfy.model_detection
import comfy.model_patcher import comfy.model_patcher
import comfy.ops import comfy.ops
import comfy.latent_formats import comfy.latent_formats
import comfy.model_base
import comfy.cldm.cldm import comfy.cldm.cldm
import comfy.t2i_adapter.adapter import comfy.t2i_adapter.adapter
@ -264,12 +265,12 @@ class ControlNet(ControlBase):
for c in self.extra_conds: for c in self.extra_conds:
temp = cond.get(c, None) temp = cond.get(c, None)
if temp is not None: if temp is not None:
extra[c] = temp.to(dtype) extra[c] = comfy.model_base.convert_tensor(temp, dtype, x_noisy.device)
timestep = self.model_sampling_current.timestep(t) timestep = self.model_sampling_current.timestep(t)
x_noisy = self.model_sampling_current.calculate_input(t, x_noisy) x_noisy = self.model_sampling_current.calculate_input(t, x_noisy)
control = self.control_model(x=x_noisy.to(dtype), hint=self.cond_hint, timesteps=timestep.to(dtype), context=context.to(dtype), **extra) control = self.control_model(x=x_noisy.to(dtype), hint=self.cond_hint, timesteps=timestep.to(dtype), context=comfy.model_management.cast_to_device(context, x_noisy.device, dtype), **extra)
return self.control_merge(control, control_prev, output_dtype=None) return self.control_merge(control, control_prev, output_dtype=None)
def copy(self): def copy(self):

View File

@ -109,9 +109,9 @@ def model_sampling(model_config, model_type):
def convert_tensor(extra, dtype, device): def convert_tensor(extra, dtype, device):
if hasattr(extra, "dtype"): if hasattr(extra, "dtype"):
if extra.dtype != torch.int and extra.dtype != torch.long: if extra.dtype != torch.int and extra.dtype != torch.long:
extra = extra.to(dtype=dtype, device=device) extra = comfy.model_management.cast_to_device(extra, device, dtype)
else: else:
extra = extra.to(device=device) extra = comfy.model_management.cast_to_device(extra, device, None)
return extra return extra
@ -174,7 +174,7 @@ class BaseModel(torch.nn.Module):
device = xc.device device = xc.device
t = self.model_sampling.timestep(t).float() t = self.model_sampling.timestep(t).float()
if context is not None: if context is not None:
context = context.to(dtype=dtype, device=device) context = comfy.model_management.cast_to_device(context, device, dtype)
extra_conds = {} extra_conds = {}
for o in kwargs: for o in kwargs:

View File

@ -89,7 +89,7 @@ def get_area_and_mult(conds, x_in, timestep_in):
conditioning = {} conditioning = {}
model_conds = conds["model_conds"] model_conds = conds["model_conds"]
for c in model_conds: for c in model_conds:
conditioning[c] = model_conds[c].process_cond(batch_size=x_in.shape[0], device=x_in.device, area=area) conditioning[c] = model_conds[c].process_cond(batch_size=x_in.shape[0], area=area)
hooks = conds.get('hooks', None) hooks = conds.get('hooks', None)
control = conds.get('control', None) control = conds.get('control', None)