Skip to content

[Refactor] Initialize class members inside init method #11450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/diffusers/pipelines/allegro/pipeline_allegro.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ def __init__(
scheduler: KarrasDiffusionSchedulers,
):
super().__init__()
self._guidance_scale=1.0
self._num_timesteps=0
self._current_timestep=None
self._interrupt=False

self.register_modules(
tokenizer=tokenizer, text_encoder=text_encoder, vae=vae, transformer=transformer, scheduler=scheduler
Expand Down Expand Up @@ -819,8 +823,6 @@ def __call__(
negative_prompt_attention_mask,
)
self._guidance_scale = guidance_scale
self._current_timestep = None
self._interrupt = False

# 2. Default height and width to transformer
if prompt is not None and isinstance(prompt, str):
Expand Down
5 changes: 4 additions & 1 deletion src/diffusers/pipelines/animatediff/pipeline_animatediff.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ def __init__(
image_encoder: CLIPVisionModelWithProjection = None,
):
super().__init__()
self._guidance_scale=1.0
self._cross_attention_kwargs=None
self._num_timesteps=0
self._interrupt=False
if isinstance(unet, UNet2DConditionModel):
unet = UNetMotionModel.from_unet2d(unet, motion_adapter)

Expand Down Expand Up @@ -714,7 +718,6 @@ def __call__(
self._guidance_scale = guidance_scale
self._clip_skip = clip_skip
self._cross_attention_kwargs = cross_attention_kwargs
self._interrupt = False

# 2. Define call parameters
if prompt is not None and isinstance(prompt, (str, dict)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ def __init__(
image_encoder: Optional[CLIPVisionModelWithProjection] = None,
):
super().__init__()
self._guidance_scale=1.0
self._cross_attention_kwargs=None
self._num_timesteps=0
self._interrupt=False
if isinstance(unet, UNet2DConditionModel):
unet = UNetMotionModel.from_unet2d(unet, motion_adapter)

Expand Down Expand Up @@ -877,7 +881,6 @@ def __call__(
self._guidance_scale = guidance_scale
self._clip_skip = clip_skip
self._cross_attention_kwargs = cross_attention_kwargs
self._interrupt = False

# 2. Define call parameters
if prompt is not None and isinstance(prompt, (str, dict)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ def __init__(
force_zeros_for_empty_prompt: bool = True,
):
super().__init__()
self._guidance_scale=1.0
self._guidance_rescale=0.0
self._cross_attention_kwargs=None
self._denoising_end=None
self._num_timesteps=0
self._interrupt=False

if isinstance(unet, UNet2DConditionModel):
unet = UNetMotionModel.from_unet2d(unet, motion_adapter)
Expand Down Expand Up @@ -1082,7 +1088,6 @@ def __call__(
self._clip_skip = clip_skip
self._cross_attention_kwargs = cross_attention_kwargs
self._denoising_end = denoising_end
self._interrupt = False

# 2. Define call parameters
if prompt is not None and isinstance(prompt, str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ def __init__(
image_encoder: CLIPVisionModelWithProjection = None,
):
super().__init__()
self._guidance_scale=1.0
self._cross_attention_kwargs=None
self._num_timesteps=0
if isinstance(unet, UNet2DConditionModel):
unet = UNetMotionModel.from_unet2d(unet, motion_adapter)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ def __init__(
image_encoder: CLIPVisionModelWithProjection = None,
):
super().__init__()
self._guidance_scale=1.0
self._cross_attention_kwargs=None
self._num_timesteps=0
self._interrupt=False
if isinstance(unet, UNet2DConditionModel):
unet = UNetMotionModel.from_unet2d(unet, motion_adapter)

Expand Down Expand Up @@ -883,7 +887,6 @@ def __call__(
self._guidance_scale = guidance_scale
self._clip_skip = clip_skip
self._cross_attention_kwargs = cross_attention_kwargs
self._interrupt = False

# 2. Define call parameters
if prompt is not None and isinstance(prompt, (str, dict)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ def __init__(
image_encoder: CLIPVisionModelWithProjection = None,
):
super().__init__()
self._guidance_scale=1.0
self._cross_attention_kwargs=None
self._num_timesteps=0
self._interrupt=False
if isinstance(unet, UNet2DConditionModel):
unet = UNetMotionModel.from_unet2d(unet, motion_adapter)

Expand Down Expand Up @@ -1086,7 +1090,6 @@ def __call__(
self._guidance_scale = guidance_scale
self._clip_skip = clip_skip
self._cross_attention_kwargs = cross_attention_kwargs
self._interrupt = False

# 2. Define call parameters
if prompt is not None and isinstance(prompt, (str, dict)):
Expand Down
3 changes: 3 additions & 0 deletions src/diffusers/pipelines/aura_flow/pipeline_aura_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ def __init__(
scheduler: FlowMatchEulerDiscreteScheduler,
):
super().__init__()
self._guidance_scale=1.0
self._attention_kwargs=None
self._num_timesteps=0

self.register_modules(
tokenizer=tokenizer, text_encoder=text_encoder, vae=vae, transformer=transformer, scheduler=scheduler
Expand Down
7 changes: 5 additions & 2 deletions src/diffusers/pipelines/cogvideo/pipeline_cogvideox.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ def __init__(
scheduler: Union[CogVideoXDDIMScheduler, CogVideoXDPMScheduler],
):
super().__init__()
self._guidance_scale=1.0
self._num_timesteps=0
self._attention_kwargs=None
self._current_timestep=None
self._interrupt=False

self.register_modules(
tokenizer=tokenizer, text_encoder=text_encoder, vae=vae, transformer=transformer, scheduler=scheduler
Expand Down Expand Up @@ -631,8 +636,6 @@ def __call__(
)
self._guidance_scale = guidance_scale
self._attention_kwargs = attention_kwargs
self._current_timestep = None
self._interrupt = False

# 2. Default call parameters
if prompt is not None and isinstance(prompt, str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ def __init__(
scheduler: KarrasDiffusionSchedulers,
):
super().__init__()
self._guidance_scale=1.0
self._num_timesteps=0
self._attention_kwargs=None
self._current_timestep=None
self._interrupt=False

self.register_modules(
tokenizer=tokenizer, text_encoder=text_encoder, vae=vae, transformer=transformer, scheduler=scheduler
Expand Down Expand Up @@ -684,8 +689,6 @@ def __call__(
)
self._guidance_scale = guidance_scale
self._attention_kwargs = attention_kwargs
self._current_timestep = None
self._interrupt = False

# 2. Default call parameters
if prompt is not None and isinstance(prompt, str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ def __init__(
scheduler: Union[CogVideoXDDIMScheduler, CogVideoXDPMScheduler],
):
super().__init__()
self._guidance_scale=1.0
self._num_timesteps=0
self._attention_kwargs=None
self._current_timestep=None
self._interrupt=False

self.register_modules(
tokenizer=tokenizer,
Expand Down Expand Up @@ -732,9 +737,7 @@ def __call__(
negative_prompt_embeds=negative_prompt_embeds,
)
self._guidance_scale = guidance_scale
self._current_timestep = None
self._attention_kwargs = attention_kwargs
self._interrupt = False

# 2. Default call parameters
if prompt is not None and isinstance(prompt, str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ def __init__(
scheduler: Union[CogVideoXDDIMScheduler, CogVideoXDPMScheduler],
):
super().__init__()
self._guidance_scale=1.0
self._num_timesteps=0
self._attention_kwargs=None
self._current_timestep=None
self._interrupt=False

self.register_modules(
tokenizer=tokenizer, text_encoder=text_encoder, vae=vae, transformer=transformer, scheduler=scheduler
Expand Down Expand Up @@ -704,8 +709,6 @@ def __call__(
)
self._guidance_scale = guidance_scale
self._attention_kwargs = attention_kwargs
self._current_timestep = None
self._interrupt = False

# 2. Default call parameters
if prompt is not None and isinstance(prompt, str):
Expand Down
4 changes: 3 additions & 1 deletion src/diffusers/pipelines/cogview3/pipeline_cogview3plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ def __init__(
scheduler: Union[CogVideoXDDIMScheduler, CogVideoXDPMScheduler],
):
super().__init__()
self._guidance_scale=1.0
self._num_timesteps=0
self._interrupt=False

self.register_modules(
tokenizer=tokenizer, text_encoder=text_encoder, vae=vae, transformer=transformer, scheduler=scheduler
Expand Down Expand Up @@ -534,7 +537,6 @@ def __call__(
negative_prompt_embeds,
)
self._guidance_scale = guidance_scale
self._interrupt = False

# 2. Default call parameters
if prompt is not None and isinstance(prompt, str):
Expand Down
7 changes: 5 additions & 2 deletions src/diffusers/pipelines/cogview4/pipeline_cogview4.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ def __init__(
scheduler: FlowMatchEulerDiscreteScheduler,
):
super().__init__()
self._guidance_scale=1.0
self._num_timesteps=0
self._attention_kwargs=None
self._current_timestep=None
self._interrupt=False

self.register_modules(
tokenizer=tokenizer, text_encoder=text_encoder, vae=vae, transformer=transformer, scheduler=scheduler
Expand Down Expand Up @@ -535,8 +540,6 @@ def __call__(
)
self._guidance_scale = guidance_scale
self._attention_kwargs = attention_kwargs
self._current_timestep = None
self._interrupt = False

# Default call parameters
if prompt is not None and isinstance(prompt, str):
Expand Down
7 changes: 5 additions & 2 deletions src/diffusers/pipelines/cogview4/pipeline_cogview4_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ def __init__(
scheduler: FlowMatchEulerDiscreteScheduler,
):
super().__init__()
self._guidance_scale=1.0
self._num_timesteps=0
self._attention_kwargs=None
self._current_timestep=None
self._interrupt=False

self.register_modules(
tokenizer=tokenizer, text_encoder=text_encoder, vae=vae, transformer=transformer, scheduler=scheduler
Expand Down Expand Up @@ -567,8 +572,6 @@ def __call__(
)
self._guidance_scale = guidance_scale
self._attention_kwargs = attention_kwargs
self._current_timestep = None
self._interrupt = False

# Default call parameters
if prompt is not None and isinstance(prompt, str):
Expand Down
5 changes: 4 additions & 1 deletion src/diffusers/pipelines/consisid/pipeline_consisid.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ def __init__(
scheduler: CogVideoXDPMScheduler,
):
super().__init__()
self._guidance_scale=1.0
self._num_timesteps=0
self._attention_kwargs=None
self._interrupt=False

self.register_modules(
tokenizer=tokenizer,
Expand Down Expand Up @@ -808,7 +812,6 @@ def __call__(
)
self._guidance_scale = guidance_scale
self._attention_kwargs = attention_kwargs
self._interrupt = False

# 2. Default call parameters
if prompt is not None and isinstance(prompt, str):
Expand Down
5 changes: 4 additions & 1 deletion src/diffusers/pipelines/controlnet/pipeline_controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ def __init__(
requires_safety_checker: bool = True,
):
super().__init__()
self._guidance_scale=1.0
self._cross_attention_kwargs=None
self._num_timesteps=0
self._interrupt=False

if safety_checker is None and requires_safety_checker:
logger.warning(
Expand Down Expand Up @@ -1100,7 +1104,6 @@ def __call__(
self._guidance_scale = guidance_scale
self._clip_skip = clip_skip
self._cross_attention_kwargs = cross_attention_kwargs
self._interrupt = False

# 2. Define call parameters
if prompt is not None and isinstance(prompt, str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ def __init__(
requires_safety_checker: bool = True,
):
super().__init__()
self._guidance_scale=1.0
self._cross_attention_kwargs=None
self._num_timesteps=0
self._interrupt=False

if safety_checker is None and requires_safety_checker:
logger.warning(
Expand Down Expand Up @@ -1092,7 +1096,6 @@ def __call__(
self._guidance_scale = guidance_scale
self._clip_skip = clip_skip
self._cross_attention_kwargs = cross_attention_kwargs
self._interrupt = False

# 2. Define call parameters
if prompt is not None and isinstance(prompt, str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ def __init__(
requires_safety_checker: bool = True,
):
super().__init__()
self._guidance_scale=1.0
self._cross_attention_kwargs=None
self._num_timesteps=0
self._interrupt=False

if safety_checker is None and requires_safety_checker:
logger.warning(
Expand Down Expand Up @@ -1209,7 +1213,6 @@ def __call__(
self._guidance_scale = guidance_scale
self._clip_skip = clip_skip
self._cross_attention_kwargs = cross_attention_kwargs
self._interrupt = False

# 2. Define call parameters
if prompt is not None and isinstance(prompt, str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ def __init__(
image_encoder: Optional[CLIPVisionModelWithProjection] = None,
):
super().__init__()
self._guidance_scale=1.0
self._cross_attention_kwargs=None
self._num_timesteps=0
self._interrupt=False

if isinstance(controlnet, (list, tuple)):
controlnet = MultiControlNetModel(controlnet)
Expand Down Expand Up @@ -1457,7 +1461,6 @@ def __call__(
self._guidance_scale = guidance_scale
self._clip_skip = clip_skip
self._cross_attention_kwargs = cross_attention_kwargs
self._interrupt = False

# 2. Define call parameters
if prompt is not None and isinstance(prompt, str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ def __init__(
image_encoder: CLIPVisionModelWithProjection = None,
):
super().__init__()
self._guidance_scale=1.0
self._cross_attention_kwargs=None
self._denoising_end=None
self._num_timesteps=0
self._interrupt=False

if isinstance(controlnet, (list, tuple)):
controlnet = MultiControlNetModel(controlnet)
Expand Down Expand Up @@ -1262,7 +1267,6 @@ def __call__(
self._clip_skip = clip_skip
self._cross_attention_kwargs = cross_attention_kwargs
self._denoising_end = denoising_end
self._interrupt = False

# 2. Define call parameters
if prompt is not None and isinstance(prompt, str):
Expand Down
Loading