Skip to content

Commit

Permalink
Invert the start and end percentages in the code.
Browse files Browse the repository at this point in the history
This doesn't affect how percentages behave in the frontend but breaks
things if you relied on them in the backend.

percent_to_sigma goes from 0 to 1.0 instead of 1.0 to 0 for less confusion.

Make percent 0 return an extremely large sigma and percent 1.0 return a
zero one to fix imprecision.
  • Loading branch information
comfyanonymous committed Nov 16, 2023
1 parent 7114cfe commit dcec104
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions comfy/controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, device=None):
self.cond_hint_original = None
self.cond_hint = None
self.strength = 1.0
self.timestep_percent_range = (1.0, 0.0)
self.timestep_percent_range = (0.0, 1.0)
self.timestep_range = None

if device is None:
Expand All @@ -42,7 +42,7 @@ def __init__(self, device=None):
self.previous_controlnet = None
self.global_average_pooling = False

def set_cond_hint(self, cond_hint, strength=1.0, timestep_percent_range=(1.0, 0.0)):
def set_cond_hint(self, cond_hint, strength=1.0, timestep_percent_range=(0.0, 1.0)):
self.cond_hint_original = cond_hint
self.strength = strength
self.timestep_percent_range = timestep_percent_range
Expand Down
5 changes: 5 additions & 0 deletions comfy/model_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,10 @@ def sigma(self, timestep):
return log_sigma.exp()

def percent_to_sigma(self, percent):
if percent <= 0.0:
return torch.tensor(999999999.9)
if percent >= 1.0:
return torch.tensor(0.0)
percent = 1.0 - percent
return self.sigma(torch.tensor(percent * 999.0))

2 changes: 2 additions & 0 deletions comfy/samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ def calc_cond_uncond_batch(model, cond, uncond, x_in, timestep, model_options):
transformer_options["patches"] = patches

transformer_options["cond_or_uncond"] = cond_or_uncond[:]
transformer_options["sigmas"] = timestep

c['transformer_options'] = transformer_options

if 'model_function_wrapper' in model_options:
Expand Down
5 changes: 5 additions & 0 deletions comfy_extras/nodes_model_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ def sigma(self, timestep):
return log_sigma.exp()

def percent_to_sigma(self, percent):
if percent <= 0.0:
return torch.tensor(999999999.9)
if percent >= 1.0:
return torch.tensor(0.0)
percent = 1.0 - percent
return self.sigma(torch.tensor(percent * 999.0))


Expand Down
6 changes: 3 additions & 3 deletions nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ def set_range(self, conditioning, start, end):
c = []
for t in conditioning:
d = t[1].copy()
d['start_percent'] = 1.0 - start
d['end_percent'] = 1.0 - end
d['start_percent'] = start
d['end_percent'] = end
n = [t[0], d]
c.append(n)
return (c, )
Expand Down Expand Up @@ -685,7 +685,7 @@ def apply_controlnet(self, positive, negative, control_net, image, strength, sta
if prev_cnet in cnets:
c_net = cnets[prev_cnet]
else:
c_net = control_net.copy().set_cond_hint(control_hint, strength, (1.0 - start_percent, 1.0 - end_percent))
c_net = control_net.copy().set_cond_hint(control_hint, strength, (start_percent, end_percent))
c_net.set_previous_controlnet(prev_cnet)
cnets[prev_cnet] = c_net

Expand Down

0 comments on commit dcec104

Please sign in to comment.