Skip to content

Commit e97a633

Browse files
Update access of configuration attributes (huggingface#7343)
Co-authored-by: Sayak Paul <[email protected]>
1 parent 01ac37b commit e97a633

20 files changed

+36
-36
lines changed

docs/source/ko/optimization/fp16.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ unet_traced = torch.jit.load("unet_traced.pt")
355355
class TracedUNet(torch.nn.Module):
356356
def __init__(self):
357357
super().__init__()
358-
self.in_channels = pipe.unet.in_channels
358+
self.in_channels = pipe.unet.config.in_channels
359359
self.device = pipe.unet.device
360360

361361
def forward(self, latent_model_input, t, encoder_hidden_states):

docs/source/ko/using-diffusers/write_own_pipeline.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ Stable Diffusion 은 text-to-image *latent diffusion* 모델입니다. latent di
210210

211211
```py
212212
>>> latents = torch.randn(
213-
... (batch_size, unet.in_channels, height // 8, width // 8),
213+
... (batch_size, unet.config.in_channels, height // 8, width // 8),
214214
... generator=generator,
215215
... device=torch_device,
216216
... )

examples/community/stable_diffusion_ipex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def get_input_example(self, prompt, height=None, width=None, guidance_scale=7.5,
224224
# 5. Prepare latent variables
225225
latents = self.prepare_latents(
226226
batch_size * num_images_per_prompt,
227-
self.unet.in_channels,
227+
self.unet.config.in_channels,
228228
height,
229229
width,
230230
prompt_embeds.dtype,
@@ -679,7 +679,7 @@ def __call__(
679679
timesteps = self.scheduler.timesteps
680680

681681
# 5. Prepare latent variables
682-
num_channels_latents = self.unet.in_channels
682+
num_channels_latents = self.unet.config.in_channels
683683
latents = self.prepare_latents(
684684
batch_size * num_images_per_prompt,
685685
num_channels_latents,

examples/community/stable_diffusion_tensorrt_txt2img.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ def __call__(
917917
text_embeddings = self.__encode_prompt(prompt, negative_prompt)
918918

919919
# Pre-initialize latents
920-
num_channels_latents = self.unet.in_channels
920+
num_channels_latents = self.unet.config.in_channels
921921
latents = self.prepare_latents(
922922
batch_size,
923923
num_channels_latents,

scripts/convert_if.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,9 +1195,9 @@ def superres_check_against_original(dump_path, unet_checkpoint_path):
11951195
if_II_model = IFStageIII(device="cuda", dir_or_name=orig_path, model_kwargs={"precision": "fp32"}).model
11961196

11971197
batch_size = 1
1198-
channels = model.in_channels // 2
1199-
height = model.sample_size
1200-
width = model.sample_size
1198+
channels = model.config.in_channels // 2
1199+
height = model.config.sample_size
1200+
width = model.config.sample_size
12011201
height = 1024
12021202
width = 1024
12031203

src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ def numpy_to_pt(images):
613613

614614
for image_ in image:
615615
image_ = image_.convert("RGB")
616-
image_ = resize(image_, self.unet.sample_size)
616+
image_ = resize(image_, self.unet.config.sample_size)
617617
image_ = np.array(image_)
618618
image_ = image_.astype(np.float32)
619619
image_ = image_ / 127.5 - 1

src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img_superresolution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ def numpy_to_pt(images):
662662

663663
for image_ in image:
664664
image_ = image_.convert("RGB")
665-
image_ = resize(image_, self.unet.sample_size)
665+
image_ = resize(image_, self.unet.config.sample_size)
666666
image_ = np.array(image_)
667667
image_ = image_.astype(np.float32)
668668
image_ = image_ / 127.5 - 1

src/diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ def numpy_to_pt(images):
654654

655655
for image_ in image:
656656
image_ = image_.convert("RGB")
657-
image_ = resize(image_, self.unet.sample_size)
657+
image_ = resize(image_, self.unet.config.sample_size)
658658
image_ = np.array(image_)
659659
image_ = image_.astype(np.float32)
660660
image_ = image_ / 127.5 - 1
@@ -701,7 +701,7 @@ def preprocess_mask_image(self, mask_image) -> torch.Tensor:
701701

702702
for mask_image_ in mask_image:
703703
mask_image_ = mask_image_.convert("L")
704-
mask_image_ = resize(mask_image_, self.unet.sample_size)
704+
mask_image_ = resize(mask_image_, self.unet.config.sample_size)
705705
mask_image_ = np.array(mask_image_)
706706
mask_image_ = mask_image_[None, None, :]
707707
new_mask_image.append(mask_image_)

src/diffusers/pipelines/deepfloyd_if/pipeline_if_inpainting_superresolution.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ def numpy_to_pt(images):
698698

699699
for image_ in image:
700700
image_ = image_.convert("RGB")
701-
image_ = resize(image_, self.unet.sample_size)
701+
image_ = resize(image_, self.unet.config.sample_size)
702702
image_ = np.array(image_)
703703
image_ = image_.astype(np.float32)
704704
image_ = image_ / 127.5 - 1
@@ -778,7 +778,7 @@ def preprocess_mask_image(self, mask_image) -> torch.Tensor:
778778

779779
for mask_image_ in mask_image:
780780
mask_image_ = mask_image_.convert("L")
781-
mask_image_ = resize(mask_image_, self.unet.sample_size)
781+
mask_image_ = resize(mask_image_, self.unet.config.sample_size)
782782
mask_image_ = np.array(mask_image_)
783783
mask_image_ = mask_image_[None, None, :]
784784
new_mask_image.append(mask_image_)

src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_upscale.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ def __call__(
469469

470470
latents = self.prepare_latents(
471471
batch_size * num_images_per_prompt,
472-
self.num_latent_channels,
472+
self.config.num_latent_channels,
473473
height,
474474
width,
475475
latents_dtype,
@@ -498,12 +498,12 @@ def __call__(
498498

499499
# 7. Check that sizes of image and latents match
500500
num_channels_image = image.shape[1]
501-
if self.num_latent_channels + num_channels_image != self.num_unet_input_channels:
501+
if self.config.num_latent_channels + num_channels_image != self.config.num_unet_input_channels:
502502
raise ValueError(
503503
"Incorrect configuration settings! The config of `pipeline.unet` expects"
504-
f" {self.num_unet_input_channels} but received `num_channels_latents`: {self.num_latent_channels} +"
504+
f" {self.config.num_unet_input_channels} but received `num_channels_latents`: {self.config.num_latent_channels} +"
505505
f" `num_channels_image`: {num_channels_image} "
506-
f" = {self.num_latent_channels + num_channels_image}. Please verify the config of"
506+
f" = {self.config.num_latent_channels + num_channels_image}. Please verify the config of"
507507
" `pipeline.unet` or your `image` input."
508508
)
509509

0 commit comments

Comments
 (0)