Skip to content

Commit 3cb13d6

Browse files
Rename as suggested in other PRs
Co-Authored-By: Ryan Dick <[email protected]>
1 parent 42356ec commit 3cb13d6

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

invokeai/backend/stable_diffusion/extensions/controlnet.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,57 +31,57 @@ def __init__(
3131
resize_mode: str,
3232
):
3333
super().__init__()
34-
self.model = model
35-
self.image = image
36-
self.weight = weight
37-
self.begin_step_percent = begin_step_percent
38-
self.end_step_percent = end_step_percent
39-
self.control_mode = control_mode
40-
self.resize_mode = resize_mode
34+
self._model = model
35+
self._image = image
36+
self._weight = weight
37+
self._begin_step_percent = begin_step_percent
38+
self._end_step_percent = end_step_percent
39+
self._control_mode = control_mode
40+
self._resize_mode = resize_mode
4141

42-
self.image_tensor: Optional[torch.Tensor] = None
42+
self._image_tensor: Optional[torch.Tensor] = None
4343

4444
@contextmanager
4545
def patch_extension(self, ctx: DenoiseContext):
4646
try:
47-
original_processors = self.model.attn_processors
48-
self.model.set_attn_processor(ctx.inputs.attention_processor_cls())
47+
original_processors = self._model.attn_processors
48+
self._model.set_attn_processor(ctx.inputs.attention_processor_cls())
4949

5050
yield None
5151
finally:
52-
self.model.set_attn_processor(original_processors)
52+
self._model.set_attn_processor(original_processors)
5353

5454
@callback(ExtensionCallbackType.PRE_DENOISE_LOOP)
5555
def resize_image(self, ctx: DenoiseContext):
5656
_, _, latent_height, latent_width = ctx.latents.shape
5757
image_height = latent_height * LATENT_SCALE_FACTOR
5858
image_width = latent_width * LATENT_SCALE_FACTOR
5959

60-
self.image_tensor = prepare_control_image(
61-
image=self.image,
60+
self._image_tensor = prepare_control_image(
61+
image=self._image,
6262
do_classifier_free_guidance=False,
6363
width=image_width,
6464
height=image_height,
6565
# batch_size=batch_size * num_images_per_prompt,
6666
# num_images_per_prompt=num_images_per_prompt,
6767
device=ctx.latents.device,
6868
dtype=ctx.latents.dtype,
69-
control_mode=self.control_mode,
70-
resize_mode=self.resize_mode,
69+
control_mode=self._control_mode,
70+
resize_mode=self._resize_mode,
7171
)
7272

7373
@callback(ExtensionCallbackType.PRE_UNET)
7474
def pre_unet_step(self, ctx: DenoiseContext):
7575
# skip if model not active in current step
7676
total_steps = len(ctx.inputs.timesteps)
77-
first_step = math.floor(self.begin_step_percent * total_steps)
78-
last_step = math.ceil(self.end_step_percent * total_steps)
77+
first_step = math.floor(self._begin_step_percent * total_steps)
78+
last_step = math.ceil(self._end_step_percent * total_steps)
7979
if ctx.step_index < first_step or ctx.step_index > last_step:
8080
return
8181

8282
# convert mode to internal flags
83-
soft_injection = self.control_mode in ["more_prompt", "more_control"]
84-
cfg_injection = self.control_mode in ["more_control", "unbalanced"]
83+
soft_injection = self._control_mode in ["more_prompt", "more_control"]
84+
cfg_injection = self._control_mode in ["more_control", "unbalanced"]
8585

8686
# no negative conditioning in cfg_injection mode
8787
if cfg_injection:
@@ -117,7 +117,7 @@ def _run(self, ctx: DenoiseContext, soft_injection: bool, conditioning_mode: Con
117117
total_steps = len(ctx.inputs.timesteps)
118118

119119
model_input = ctx.latent_model_input
120-
image_tensor = self.image_tensor
120+
image_tensor = self._image_tensor
121121
if conditioning_mode == ConditioningMode.Both:
122122
model_input = torch.cat([model_input] * 2)
123123
image_tensor = torch.cat([image_tensor] * 2)
@@ -134,7 +134,7 @@ def _run(self, ctx: DenoiseContext, soft_injection: bool, conditioning_mode: Con
134134
ctx.inputs.conditioning_data.to_unet_kwargs(cn_unet_kwargs, conditioning_mode=conditioning_mode)
135135

136136
# get static weight, or weight corresponding to current step
137-
weight = self.weight
137+
weight = self._weight
138138
if isinstance(weight, list):
139139
weight = weight[ctx.step_index]
140140

@@ -144,7 +144,7 @@ def _run(self, ctx: DenoiseContext, soft_injection: bool, conditioning_mode: Con
144144
tmp_kwargs.pop("down_intrablock_additional_residuals", None)
145145

146146
# controlnet(s) inference
147-
down_samples, mid_sample = self.model(
147+
down_samples, mid_sample = self._model(
148148
controlnet_cond=image_tensor,
149149
conditioning_scale=weight, # controlnet specific, NOT the guidance scale
150150
guess_mode=soft_injection, # this is still called guess_mode in diffusers ControlNetModel

0 commit comments

Comments
 (0)