Skip to content

Commit edc154d

Browse files
authored
Update Ruff to latest Version (#10919)
* update * update * update * update
1 parent 552cd32 commit edc154d

File tree

200 files changed

+4714
-4655
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

200 files changed

+4714
-4655
lines changed

examples/advanced_diffusion_training/train_dreambooth_lora_flux_advanced.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -839,9 +839,9 @@ def initialize_new_tokens(self, inserting_toks: List[str]):
839839
idx = 0
840840
for tokenizer, text_encoder in zip(self.tokenizers, self.text_encoders):
841841
assert isinstance(inserting_toks, list), "inserting_toks should be a list of strings."
842-
assert all(
843-
isinstance(tok, str) for tok in inserting_toks
844-
), "All elements in inserting_toks should be strings."
842+
assert all(isinstance(tok, str) for tok in inserting_toks), (
843+
"All elements in inserting_toks should be strings."
844+
)
845845

846846
self.inserting_toks = inserting_toks
847847
special_tokens_dict = {"additional_special_tokens": self.inserting_toks}
@@ -1605,7 +1605,7 @@ def load_model_hook(models, input_dir):
16051605
lora_state_dict = FluxPipeline.lora_state_dict(input_dir)
16061606

16071607
transformer_state_dict = {
1608-
f'{k.replace("transformer.", "")}': v for k, v in lora_state_dict.items() if k.startswith("transformer.")
1608+
f"{k.replace('transformer.', '')}": v for k, v in lora_state_dict.items() if k.startswith("transformer.")
16091609
}
16101610
transformer_state_dict = convert_unet_state_dict_to_peft(transformer_state_dict)
16111611
incompatible_keys = set_peft_model_state_dict(transformer_, transformer_state_dict, adapter_name="default")

examples/advanced_diffusion_training/train_dreambooth_lora_sd15_advanced.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ def save_model_card(
200200
"diffusers",
201201
"diffusers-training",
202202
lora,
203-
"template:sd-lora" "stable-diffusion",
203+
"template:sd-lora",
204+
"stable-diffusion",
204205
"stable-diffusion-diffusers",
205206
]
206207
model_card = populate_model_card(model_card, tags=tags)
@@ -724,9 +725,9 @@ def initialize_new_tokens(self, inserting_toks: List[str]):
724725
idx = 0
725726
for tokenizer, text_encoder in zip(self.tokenizers, self.text_encoders):
726727
assert isinstance(inserting_toks, list), "inserting_toks should be a list of strings."
727-
assert all(
728-
isinstance(tok, str) for tok in inserting_toks
729-
), "All elements in inserting_toks should be strings."
728+
assert all(isinstance(tok, str) for tok in inserting_toks), (
729+
"All elements in inserting_toks should be strings."
730+
)
730731

731732
self.inserting_toks = inserting_toks
732733
special_tokens_dict = {"additional_special_tokens": self.inserting_toks}
@@ -746,9 +747,9 @@ def initialize_new_tokens(self, inserting_toks: List[str]):
746747
.to(dtype=self.dtype)
747748
* std_token_embedding
748749
)
749-
self.embeddings_settings[
750-
f"original_embeddings_{idx}"
751-
] = text_encoder.text_model.embeddings.token_embedding.weight.data.clone()
750+
self.embeddings_settings[f"original_embeddings_{idx}"] = (
751+
text_encoder.text_model.embeddings.token_embedding.weight.data.clone()
752+
)
752753
self.embeddings_settings[f"std_token_embedding_{idx}"] = std_token_embedding
753754

754755
inu = torch.ones((len(tokenizer),), dtype=torch.bool)
@@ -1322,7 +1323,7 @@ def load_model_hook(models, input_dir):
13221323

13231324
lora_state_dict, network_alphas = StableDiffusionPipeline.lora_state_dict(input_dir)
13241325

1325-
unet_state_dict = {f'{k.replace("unet.", "")}': v for k, v in lora_state_dict.items() if k.startswith("unet.")}
1326+
unet_state_dict = {f"{k.replace('unet.', '')}": v for k, v in lora_state_dict.items() if k.startswith("unet.")}
13261327
unet_state_dict = convert_unet_state_dict_to_peft(unet_state_dict)
13271328
incompatible_keys = set_peft_model_state_dict(unet_, unet_state_dict, adapter_name="default")
13281329
if incompatible_keys is not None:

examples/advanced_diffusion_training/train_dreambooth_lora_sdxl_advanced.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -890,9 +890,9 @@ def initialize_new_tokens(self, inserting_toks: List[str]):
890890
idx = 0
891891
for tokenizer, text_encoder in zip(self.tokenizers, self.text_encoders):
892892
assert isinstance(inserting_toks, list), "inserting_toks should be a list of strings."
893-
assert all(
894-
isinstance(tok, str) for tok in inserting_toks
895-
), "All elements in inserting_toks should be strings."
893+
assert all(isinstance(tok, str) for tok in inserting_toks), (
894+
"All elements in inserting_toks should be strings."
895+
)
896896

897897
self.inserting_toks = inserting_toks
898898
special_tokens_dict = {"additional_special_tokens": self.inserting_toks}
@@ -912,9 +912,9 @@ def initialize_new_tokens(self, inserting_toks: List[str]):
912912
.to(dtype=self.dtype)
913913
* std_token_embedding
914914
)
915-
self.embeddings_settings[
916-
f"original_embeddings_{idx}"
917-
] = text_encoder.text_model.embeddings.token_embedding.weight.data.clone()
915+
self.embeddings_settings[f"original_embeddings_{idx}"] = (
916+
text_encoder.text_model.embeddings.token_embedding.weight.data.clone()
917+
)
918918
self.embeddings_settings[f"std_token_embedding_{idx}"] = std_token_embedding
919919

920920
inu = torch.ones((len(tokenizer),), dtype=torch.bool)
@@ -1647,7 +1647,7 @@ def load_model_hook(models, input_dir):
16471647

16481648
lora_state_dict, network_alphas = StableDiffusionLoraLoaderMixin.lora_state_dict(input_dir)
16491649

1650-
unet_state_dict = {f'{k.replace("unet.", "")}': v for k, v in lora_state_dict.items() if k.startswith("unet.")}
1650+
unet_state_dict = {f"{k.replace('unet.', '')}": v for k, v in lora_state_dict.items() if k.startswith("unet.")}
16511651
unet_state_dict = convert_unet_state_dict_to_peft(unet_state_dict)
16521652
incompatible_keys = set_peft_model_state_dict(unet_, unet_state_dict, adapter_name="default")
16531653
if incompatible_keys is not None:

examples/amused/train_amused.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ def load_model_hook(models, input_dir):
720720
# Train!
721721
logger.info("***** Running training *****")
722722
logger.info(f" Num training steps = {args.max_train_steps}")
723-
logger.info(f" Instantaneous batch size per device = { args.train_batch_size}")
723+
logger.info(f" Instantaneous batch size per device = {args.train_batch_size}")
724724
logger.info(f" Total train batch size (w. parallel, distributed & accumulation) = {total_batch_size}")
725725
logger.info(f" Gradient Accumulation steps = {args.gradient_accumulation_steps}")
726726

examples/cogvideo/train_cogvideox_image_to_video_lora.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ def load_model_hook(models, input_dir):
11381138
lora_state_dict = CogVideoXImageToVideoPipeline.lora_state_dict(input_dir)
11391139

11401140
transformer_state_dict = {
1141-
f'{k.replace("transformer.", "")}': v for k, v in lora_state_dict.items() if k.startswith("transformer.")
1141+
f"{k.replace('transformer.', '')}": v for k, v in lora_state_dict.items() if k.startswith("transformer.")
11421142
}
11431143
transformer_state_dict = convert_unet_state_dict_to_peft(transformer_state_dict)
11441144
incompatible_keys = set_peft_model_state_dict(transformer_, transformer_state_dict, adapter_name="default")

examples/cogvideo/train_cogvideox_lora.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ def load_model_hook(models, input_dir):
11591159
lora_state_dict = CogVideoXPipeline.lora_state_dict(input_dir)
11601160

11611161
transformer_state_dict = {
1162-
f'{k.replace("transformer.", "")}': v for k, v in lora_state_dict.items() if k.startswith("transformer.")
1162+
f"{k.replace('transformer.', '')}": v for k, v in lora_state_dict.items() if k.startswith("transformer.")
11631163
}
11641164
transformer_state_dict = convert_unet_state_dict_to_peft(transformer_state_dict)
11651165
incompatible_keys = set_peft_model_state_dict(transformer_, transformer_state_dict, adapter_name="default")

examples/community/adaptive_mask_inpainting.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ def __call__(
11031103
f"Incorrect configuration settings! The config of `pipeline.unet`: {self.unet.config} expects"
11041104
f" {self.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +"
11051105
f" `num_channels_mask`: {num_channels_mask} + `num_channels_masked_image`: {num_channels_masked_image}"
1106-
f" = {num_channels_latents+num_channels_masked_image+num_channels_mask}. Please verify the config of"
1106+
f" = {num_channels_latents + num_channels_masked_image + num_channels_mask}. Please verify the config of"
11071107
" `pipeline.unet` or your `default_mask_image` or `image` input."
11081108
)
11091109
elif num_channels_unet != 4:

examples/community/hd_painter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ def __call__(
686686
f"Incorrect configuration settings! The config of `pipeline.unet`: {self.unet.config} expects"
687687
f" {self.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +"
688688
f" `num_channels_mask`: {num_channels_mask} + `num_channels_masked_image`: {num_channels_masked_image}"
689-
f" = {num_channels_latents+num_channels_masked_image+num_channels_mask}. Please verify the config of"
689+
f" = {num_channels_latents + num_channels_masked_image + num_channels_mask}. Please verify the config of"
690690
" `pipeline.unet` or your `mask_image` or `image` input."
691691
)
692692
elif num_channels_unet != 4:

examples/community/img2img_inpainting.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def __call__(
362362
f"Incorrect configuration settings! The config of `pipeline.unet`: {self.unet.config} expects"
363363
f" {self.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +"
364364
f" `num_channels_mask`: {num_channels_mask} + `num_channels_masked_image`: {num_channels_masked_image}"
365-
f" = {num_channels_latents+num_channels_masked_image+num_channels_mask}. Please verify the config of"
365+
f" = {num_channels_latents + num_channels_masked_image + num_channels_mask}. Please verify the config of"
366366
" `pipeline.unet` or your `mask_image` or `image` input."
367367
)
368368

examples/community/llm_grounded_diffusion.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ def latent_lmd_guidance(
11201120

11211121
if verbose:
11221122
logger.info(
1123-
f"time index {index}, loss: {loss.item()/loss_scale:.3f} (de-scaled with scale {loss_scale:.1f}), loss threshold: {loss_threshold:.3f}"
1123+
f"time index {index}, loss: {loss.item() / loss_scale:.3f} (de-scaled with scale {loss_scale:.1f}), loss threshold: {loss_threshold:.3f}"
11241124
)
11251125

11261126
try:
@@ -1184,7 +1184,7 @@ def latent_lmd_guidance(
11841184

11851185
if verbose:
11861186
logger.info(
1187-
f"time index {index}, loss: {loss.item()/loss_scale:.3f}, loss threshold: {loss_threshold:.3f}, iteration: {iteration}"
1187+
f"time index {index}, loss: {loss.item() / loss_scale:.3f}, loss threshold: {loss_threshold:.3f}, iteration: {iteration}"
11881188
)
11891189

11901190
finally:

examples/community/mod_controlnet_tile_sr_sdxl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ def check_inputs(
701701
raise ValueError("`max_tile_size` cannot be None.")
702702
elif not isinstance(max_tile_size, int) or max_tile_size not in (1024, 1280):
703703
raise ValueError(
704-
f"`max_tile_size` has to be in 1024 or 1280 but is {max_tile_size} of type" f" {type(max_tile_size)}."
704+
f"`max_tile_size` has to be in 1024 or 1280 but is {max_tile_size} of type {type(max_tile_size)}."
705705
)
706706
if tile_gaussian_sigma is None:
707707
raise ValueError("`tile_gaussian_sigma` cannot be None.")

examples/community/pipeline_flux_differential_img2img.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -488,15 +488,15 @@ def check_inputs(
488488
if padding_mask_crop is not None:
489489
if not isinstance(image, PIL.Image.Image):
490490
raise ValueError(
491-
f"The image should be a PIL image when inpainting mask crop, but is of type" f" {type(image)}."
491+
f"The image should be a PIL image when inpainting mask crop, but is of type {type(image)}."
492492
)
493493
if not isinstance(mask_image, PIL.Image.Image):
494494
raise ValueError(
495495
f"The mask image should be a PIL image when inpainting mask crop, but is of type"
496496
f" {type(mask_image)}."
497497
)
498498
if output_type != "pil":
499-
raise ValueError(f"The output type should be PIL when inpainting mask crop, but is" f" {output_type}.")
499+
raise ValueError(f"The output type should be PIL when inpainting mask crop, but is {output_type}.")
500500

501501
if max_sequence_length is not None and max_sequence_length > 512:
502502
raise ValueError(f"`max_sequence_length` cannot be greater than 512 but is {max_sequence_length}")

examples/community/pipeline_prompt2prompt.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -907,12 +907,12 @@ def create_controller(
907907

908908
# reweight
909909
if edit_type == "reweight":
910-
assert (
911-
equalizer_words is not None and equalizer_strengths is not None
912-
), "To use reweight edit, please specify equalizer_words and equalizer_strengths."
913-
assert len(equalizer_words) == len(
914-
equalizer_strengths
915-
), "equalizer_words and equalizer_strengths must be of same length."
910+
assert equalizer_words is not None and equalizer_strengths is not None, (
911+
"To use reweight edit, please specify equalizer_words and equalizer_strengths."
912+
)
913+
assert len(equalizer_words) == len(equalizer_strengths), (
914+
"equalizer_words and equalizer_strengths must be of same length."
915+
)
916916
equalizer = get_equalizer(prompts[1], equalizer_words, equalizer_strengths, tokenizer=tokenizer)
917917
return AttentionReweight(
918918
prompts,

examples/community/pipeline_sdxl_style_aligned.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,7 @@ def denoising_value_valid(dnv):
17381738
f"Incorrect configuration settings! The config of `pipeline.unet`: {self.unet.config} expects"
17391739
f" {self.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +"
17401740
f" `num_channels_mask`: {num_channels_mask} + `num_channels_masked_image`: {num_channels_masked_image}"
1741-
f" = {num_channels_latents+num_channels_masked_image+num_channels_mask}. Please verify the config of"
1741+
f" = {num_channels_latents + num_channels_masked_image + num_channels_mask}. Please verify the config of"
17421742
" `pipeline.unet` or your `mask_image` or `image` input."
17431743
)
17441744
elif num_channels_unet != 4:

examples/community/pipeline_stable_diffusion_upscale_ldm3d.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ def __call__(
689689
f"Incorrect configuration settings! The config of `pipeline.unet`: {self.unet.config} expects"
690690
f" {self.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +"
691691
f" `num_channels_image`: {num_channels_image} "
692-
f" = {num_channels_latents+num_channels_image}. Please verify the config of"
692+
f" = {num_channels_latents + num_channels_image}. Please verify the config of"
693693
" `pipeline.unet` or your `image` input."
694694
)
695695

examples/community/pipeline_stable_diffusion_xl_attentive_eraser.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1028,15 +1028,15 @@ def check_inputs(
10281028
if padding_mask_crop is not None:
10291029
if not isinstance(image, PIL.Image.Image):
10301030
raise ValueError(
1031-
f"The image should be a PIL image when inpainting mask crop, but is of type" f" {type(image)}."
1031+
f"The image should be a PIL image when inpainting mask crop, but is of type {type(image)}."
10321032
)
10331033
if not isinstance(mask_image, PIL.Image.Image):
10341034
raise ValueError(
10351035
f"The mask image should be a PIL image when inpainting mask crop, but is of type"
10361036
f" {type(mask_image)}."
10371037
)
10381038
if output_type != "pil":
1039-
raise ValueError(f"The output type should be PIL when inpainting mask crop, but is" f" {output_type}.")
1039+
raise ValueError(f"The output type should be PIL when inpainting mask crop, but is {output_type}.")
10401040

10411041
if ip_adapter_image is not None and ip_adapter_image_embeds is not None:
10421042
raise ValueError(
@@ -2050,7 +2050,7 @@ def denoising_value_valid(dnv):
20502050
f"Incorrect configuration settings! The config of `pipeline.unet`: {self.unet.config} expects"
20512051
f" {self.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +"
20522052
f" `num_channels_mask`: {num_channels_mask} + `num_channels_masked_image`: {num_channels_masked_image}"
2053-
f" = {num_channels_latents+num_channels_masked_image+num_channels_mask}. Please verify the config of"
2053+
f" = {num_channels_latents + num_channels_masked_image + num_channels_mask}. Please verify the config of"
20542054
" `pipeline.unet` or your `mask_image` or `image` input."
20552055
)
20562056
elif num_channels_unet != 4:

examples/community/pipeline_stable_diffusion_xl_controlnet_adapter_inpaint.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ def denoising_value_valid(dnv):
15781578
f"Incorrect configuration settings! The config of `pipeline.unet`: {self.unet.config} expects"
15791579
f" {self.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +"
15801580
f" `num_channels_mask`: {num_channels_mask} + `num_channels_masked_image`: {num_channels_masked_image}"
1581-
f" = {num_channels_latents+num_channels_masked_image+num_channels_mask}. Please verify the config of"
1581+
f" = {num_channels_latents + num_channels_masked_image + num_channels_mask}. Please verify the config of"
15821582
" `pipeline.unet` or your `mask_image` or `image` input."
15831583
)
15841584
elif num_channels_unet != 4:

examples/community/scheduling_ufogen.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ def set_timesteps(
288288

289289
if timesteps[0] >= self.config.num_train_timesteps:
290290
raise ValueError(
291-
f"`timesteps` must start before `self.config.train_timesteps`:"
292-
f" {self.config.num_train_timesteps}."
291+
f"`timesteps` must start before `self.config.train_timesteps`: {self.config.num_train_timesteps}."
293292
)
294293

295294
timesteps = np.array(timesteps, dtype=np.int64)

examples/consistency_distillation/train_lcm_distill_lora_sd_wds.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def get_module_kohya_state_dict(module, prefix: str, dtype: torch.dtype, adapter
8989

9090
# Set alpha parameter
9191
if "lora_down" in kohya_key:
92-
alpha_key = f'{kohya_key.split(".")[0]}.alpha'
92+
alpha_key = f"{kohya_key.split('.')[0]}.alpha"
9393
kohya_ss_state_dict[alpha_key] = torch.tensor(module.peft_config[adapter_name].lora_alpha).to(dtype)
9494

9595
return kohya_ss_state_dict

examples/consistency_distillation/train_lcm_distill_lora_sdxl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ def load_model_hook(models, input_dir):
901901
unet_ = accelerator.unwrap_model(unet)
902902
lora_state_dict, _ = StableDiffusionXLPipeline.lora_state_dict(input_dir)
903903
unet_state_dict = {
904-
f'{k.replace("unet.", "")}': v for k, v in lora_state_dict.items() if k.startswith("unet.")
904+
f"{k.replace('unet.', '')}": v for k, v in lora_state_dict.items() if k.startswith("unet.")
905905
}
906906
unet_state_dict = convert_unet_state_dict_to_peft(unet_state_dict)
907907
incompatible_keys = set_peft_model_state_dict(unet_, unet_state_dict, adapter_name="default")

examples/consistency_distillation/train_lcm_distill_lora_sdxl_wds.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def get_module_kohya_state_dict(module, prefix: str, dtype: torch.dtype, adapter
9595

9696
# Set alpha parameter
9797
if "lora_down" in kohya_key:
98-
alpha_key = f'{kohya_key.split(".")[0]}.alpha'
98+
alpha_key = f"{kohya_key.split('.')[0]}.alpha"
9999
kohya_ss_state_dict[alpha_key] = torch.tensor(module.peft_config[adapter_name].lora_alpha).to(dtype)
100100

101101
return kohya_ss_state_dict

examples/custom_diffusion/retrieve.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ def retrieve(class_prompt, class_data_dir, num_class_images):
5050
total = 0
5151
pbar = tqdm(desc="downloading real regularization images", total=num_class_images)
5252

53-
with open(f"{class_data_dir}/caption.txt", "w") as f1, open(f"{class_data_dir}/urls.txt", "w") as f2, open(
54-
f"{class_data_dir}/images.txt", "w"
55-
) as f3:
53+
with (
54+
open(f"{class_data_dir}/caption.txt", "w") as f1,
55+
open(f"{class_data_dir}/urls.txt", "w") as f2,
56+
open(f"{class_data_dir}/images.txt", "w") as f3,
57+
):
5658
while total < num_class_images:
5759
images = class_images[count]
5860
count += 1

0 commit comments

Comments
 (0)