"docs/advanced/vscode:/vscode.git/clone" did not exist on "b8863698d6f53ea86dd26c681eeaa837888c66d6"
Unverified Commit edc154da authored by Dhruv Nair's avatar Dhruv Nair Committed by GitHub
Browse files

Update Ruff to latest Version (#10919)

* update

* update

* update

* update
parent 552cd320
...@@ -660,7 +660,7 @@ class StableDiffusionInpaintPipeline( ...@@ -660,7 +660,7 @@ class StableDiffusionInpaintPipeline(
if padding_mask_crop is not None: if padding_mask_crop is not None:
if not isinstance(image, PIL.Image.Image): if not isinstance(image, PIL.Image.Image):
raise ValueError( raise ValueError(
f"The image should be a PIL image when inpainting mask crop, but is of type" f" {type(image)}." f"The image should be a PIL image when inpainting mask crop, but is of type {type(image)}."
) )
if not isinstance(mask_image, PIL.Image.Image): if not isinstance(mask_image, PIL.Image.Image):
raise ValueError( raise ValueError(
...@@ -668,7 +668,7 @@ class StableDiffusionInpaintPipeline( ...@@ -668,7 +668,7 @@ class StableDiffusionInpaintPipeline(
f" {type(mask_image)}." f" {type(mask_image)}."
) )
if output_type != "pil": if output_type != "pil":
raise ValueError(f"The output type should be PIL when inpainting mask crop, but is" f" {output_type}.") raise ValueError(f"The output type should be PIL when inpainting mask crop, but is {output_type}.")
if ip_adapter_image is not None and ip_adapter_image_embeds is not None: if ip_adapter_image is not None and ip_adapter_image_embeds is not None:
raise ValueError( raise ValueError(
...@@ -1226,7 +1226,7 @@ class StableDiffusionInpaintPipeline( ...@@ -1226,7 +1226,7 @@ class StableDiffusionInpaintPipeline(
f"Incorrect configuration settings! The config of `pipeline.unet`: {self.unet.config} expects" f"Incorrect configuration settings! The config of `pipeline.unet`: {self.unet.config} expects"
f" {self.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +" f" {self.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +"
f" `num_channels_mask`: {num_channels_mask} + `num_channels_masked_image`: {num_channels_masked_image}" f" `num_channels_mask`: {num_channels_mask} + `num_channels_masked_image`: {num_channels_masked_image}"
f" = {num_channels_latents+num_channels_masked_image+num_channels_mask}. Please verify the config of" f" = {num_channels_latents + num_channels_masked_image + num_channels_mask}. Please verify the config of"
" `pipeline.unet` or your `mask_image` or `image` input." " `pipeline.unet` or your `mask_image` or `image` input."
) )
elif num_channels_unet != 4: elif num_channels_unet != 4:
......
...@@ -401,7 +401,7 @@ class StableDiffusionInstructPix2PixPipeline( ...@@ -401,7 +401,7 @@ class StableDiffusionInstructPix2PixPipeline(
f"Incorrect configuration settings! The config of `pipeline.unet`: {self.unet.config} expects" f"Incorrect configuration settings! The config of `pipeline.unet`: {self.unet.config} expects"
f" {self.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +" f" {self.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +"
f" `num_channels_image`: {num_channels_image} " f" `num_channels_image`: {num_channels_image} "
f" = {num_channels_latents+num_channels_image}. Please verify the config of" f" = {num_channels_latents + num_channels_image}. Please verify the config of"
" `pipeline.unet` or your `image` input." " `pipeline.unet` or your `image` input."
) )
......
...@@ -600,7 +600,7 @@ class StableDiffusionLatentUpscalePipeline(DiffusionPipeline, StableDiffusionMix ...@@ -600,7 +600,7 @@ class StableDiffusionLatentUpscalePipeline(DiffusionPipeline, StableDiffusionMix
f"Incorrect configuration settings! The config of `pipeline.unet`: {self.unet.config} expects" f"Incorrect configuration settings! The config of `pipeline.unet`: {self.unet.config} expects"
f" {self.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +" f" {self.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +"
f" `num_channels_image`: {num_channels_image} " f" `num_channels_image`: {num_channels_image} "
f" = {num_channels_latents+num_channels_image}. Please verify the config of" f" = {num_channels_latents + num_channels_image}. Please verify the config of"
" `pipeline.unet` or your `image` input." " `pipeline.unet` or your `image` input."
) )
......
...@@ -740,7 +740,7 @@ class StableDiffusionUpscalePipeline( ...@@ -740,7 +740,7 @@ class StableDiffusionUpscalePipeline(
f"Incorrect configuration settings! The config of `pipeline.unet`: {self.unet.config} expects" f"Incorrect configuration settings! The config of `pipeline.unet`: {self.unet.config} expects"
f" {self.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +" f" {self.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +"
f" `num_channels_image`: {num_channels_image} " f" `num_channels_image`: {num_channels_image} "
f" = {num_channels_latents+num_channels_image}. Please verify the config of" f" = {num_channels_latents + num_channels_image}. Please verify the config of"
" `pipeline.unet` or your `image` input." " `pipeline.unet` or your `image` input."
) )
......
...@@ -1258,7 +1258,7 @@ class StableDiffusion3InpaintPipeline(DiffusionPipeline, SD3LoraLoaderMixin, Fro ...@@ -1258,7 +1258,7 @@ class StableDiffusion3InpaintPipeline(DiffusionPipeline, SD3LoraLoaderMixin, Fro
f"Incorrect configuration settings! The config of `pipeline.transformer`: {self.transformer.config} expects" f"Incorrect configuration settings! The config of `pipeline.transformer`: {self.transformer.config} expects"
f" {self.transformer.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +" f" {self.transformer.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +"
f" `num_channels_mask`: {num_channels_mask} + `num_channels_masked_image`: {num_channels_masked_image}" f" `num_channels_mask`: {num_channels_mask} + `num_channels_masked_image`: {num_channels_masked_image}"
f" = {num_channels_latents+num_channels_masked_image+num_channels_mask}. Please verify the config of" f" = {num_channels_latents + num_channels_masked_image + num_channels_mask}. Please verify the config of"
" `pipeline.transformer` or your `mask_image` or `image` input." " `pipeline.transformer` or your `mask_image` or `image` input."
) )
elif num_channels_transformer != 16: elif num_channels_transformer != 16:
......
...@@ -741,7 +741,7 @@ class StableDiffusionXLInpaintPipeline( ...@@ -741,7 +741,7 @@ class StableDiffusionXLInpaintPipeline(
if padding_mask_crop is not None: if padding_mask_crop is not None:
if not isinstance(image, PIL.Image.Image): if not isinstance(image, PIL.Image.Image):
raise ValueError( raise ValueError(
f"The image should be a PIL image when inpainting mask crop, but is of type" f" {type(image)}." f"The image should be a PIL image when inpainting mask crop, but is of type {type(image)}."
) )
if not isinstance(mask_image, PIL.Image.Image): if not isinstance(mask_image, PIL.Image.Image):
raise ValueError( raise ValueError(
...@@ -749,7 +749,7 @@ class StableDiffusionXLInpaintPipeline( ...@@ -749,7 +749,7 @@ class StableDiffusionXLInpaintPipeline(
f" {type(mask_image)}." f" {type(mask_image)}."
) )
if output_type != "pil": if output_type != "pil":
raise ValueError(f"The output type should be PIL when inpainting mask crop, but is" f" {output_type}.") raise ValueError(f"The output type should be PIL when inpainting mask crop, but is {output_type}.")
if ip_adapter_image is not None and ip_adapter_image_embeds is not None: if ip_adapter_image is not None and ip_adapter_image_embeds is not None:
raise ValueError( raise ValueError(
...@@ -1509,7 +1509,7 @@ class StableDiffusionXLInpaintPipeline( ...@@ -1509,7 +1509,7 @@ class StableDiffusionXLInpaintPipeline(
f"Incorrect configuration settings! The config of `pipeline.unet`: {self.unet.config} expects" f"Incorrect configuration settings! The config of `pipeline.unet`: {self.unet.config} expects"
f" {self.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +" f" {self.unet.config.in_channels} but received `num_channels_latents`: {num_channels_latents} +"
f" `num_channels_mask`: {num_channels_mask} + `num_channels_masked_image`: {num_channels_masked_image}" f" `num_channels_mask`: {num_channels_mask} + `num_channels_masked_image`: {num_channels_masked_image}"
f" = {num_channels_latents+num_channels_masked_image+num_channels_mask}. Please verify the config of" f" = {num_channels_latents + num_channels_masked_image + num_channels_mask}. Please verify the config of"
" `pipeline.unet` or your `mask_image` or `image` input." " `pipeline.unet` or your `mask_image` or `image` input."
) )
elif num_channels_unet != 4: elif num_channels_unet != 4:
......
...@@ -334,7 +334,7 @@ class WanImageToVideoPipeline(DiffusionPipeline, WanLoraLoaderMixin): ...@@ -334,7 +334,7 @@ class WanImageToVideoPipeline(DiffusionPipeline, WanLoraLoaderMixin):
"Provide either `image` or `prompt_embeds`. Cannot leave both `image` and `image_embeds` undefined." "Provide either `image` or `prompt_embeds`. Cannot leave both `image` and `image_embeds` undefined."
) )
if image is not None and not isinstance(image, torch.Tensor) and not isinstance(image, PIL.Image.Image): if image is not None and not isinstance(image, torch.Tensor) and not isinstance(image, PIL.Image.Image):
raise ValueError("`image` has to be of type `torch.Tensor` or `PIL.Image.Image` but is" f" {type(image)}") raise ValueError(f"`image` has to be of type `torch.Tensor` or `PIL.Image.Image` but is {type(image)}")
if height % 16 != 0 or width % 16 != 0: if height % 16 != 0 or width % 16 != 0:
raise ValueError(f"`height` and `width` have to be divisible by 16 but are {height} and {width}.") raise ValueError(f"`height` and `width` have to be divisible by 16 but are {height} and {width}.")
......
...@@ -215,19 +215,15 @@ class DiffusersQuantizer(ABC): ...@@ -215,19 +215,15 @@ class DiffusersQuantizer(ABC):
) )
@abstractmethod @abstractmethod
def _process_model_before_weight_loading(self, model, **kwargs): def _process_model_before_weight_loading(self, model, **kwargs): ...
...
@abstractmethod @abstractmethod
def _process_model_after_weight_loading(self, model, **kwargs): def _process_model_after_weight_loading(self, model, **kwargs): ...
...
@property @property
@abstractmethod @abstractmethod
def is_serializable(self): def is_serializable(self): ...
...
@property @property
@abstractmethod @abstractmethod
def is_trainable(self): def is_trainable(self): ...
...
...@@ -203,8 +203,7 @@ class CMStochasticIterativeScheduler(SchedulerMixin, ConfigMixin): ...@@ -203,8 +203,7 @@ class CMStochasticIterativeScheduler(SchedulerMixin, ConfigMixin):
if timesteps[0] >= self.config.num_train_timesteps: if timesteps[0] >= self.config.num_train_timesteps:
raise ValueError( raise ValueError(
f"`timesteps` must start before `self.config.train_timesteps`:" f"`timesteps` must start before `self.config.train_timesteps`: {self.config.num_train_timesteps}."
f" {self.config.num_train_timesteps}."
) )
timesteps = np.array(timesteps, dtype=np.int64) timesteps = np.array(timesteps, dtype=np.int64)
......
...@@ -279,8 +279,7 @@ class DDPMScheduler(SchedulerMixin, ConfigMixin): ...@@ -279,8 +279,7 @@ class DDPMScheduler(SchedulerMixin, ConfigMixin):
if timesteps[0] >= self.config.num_train_timesteps: if timesteps[0] >= self.config.num_train_timesteps:
raise ValueError( raise ValueError(
f"`timesteps` must start before `self.config.train_timesteps`:" f"`timesteps` must start before `self.config.train_timesteps`: {self.config.num_train_timesteps}."
f" {self.config.num_train_timesteps}."
) )
timesteps = np.array(timesteps, dtype=np.int64) timesteps = np.array(timesteps, dtype=np.int64)
......
...@@ -289,8 +289,7 @@ class DDPMParallelScheduler(SchedulerMixin, ConfigMixin): ...@@ -289,8 +289,7 @@ class DDPMParallelScheduler(SchedulerMixin, ConfigMixin):
if timesteps[0] >= self.config.num_train_timesteps: if timesteps[0] >= self.config.num_train_timesteps:
raise ValueError( raise ValueError(
f"`timesteps` must start before `self.config.train_timesteps`:" f"`timesteps` must start before `self.config.train_timesteps`: {self.config.num_train_timesteps}."
f" {self.config.num_train_timesteps}."
) )
timesteps = np.array(timesteps, dtype=np.int64) timesteps = np.array(timesteps, dtype=np.int64)
......
...@@ -413,8 +413,7 @@ class LCMScheduler(SchedulerMixin, ConfigMixin): ...@@ -413,8 +413,7 @@ class LCMScheduler(SchedulerMixin, ConfigMixin):
if timesteps[0] >= self.config.num_train_timesteps: if timesteps[0] >= self.config.num_train_timesteps:
raise ValueError( raise ValueError(
f"`timesteps` must start before `self.config.train_timesteps`:" f"`timesteps` must start before `self.config.train_timesteps`: {self.config.num_train_timesteps}."
f" {self.config.num_train_timesteps}."
) )
# Raise warning if timestep schedule does not start with self.config.num_train_timesteps - 1 # Raise warning if timestep schedule does not start with self.config.num_train_timesteps - 1
......
...@@ -431,8 +431,7 @@ class TCDScheduler(SchedulerMixin, ConfigMixin): ...@@ -431,8 +431,7 @@ class TCDScheduler(SchedulerMixin, ConfigMixin):
if timesteps[0] >= self.config.num_train_timesteps: if timesteps[0] >= self.config.num_train_timesteps:
raise ValueError( raise ValueError(
f"`timesteps` must start before `self.config.train_timesteps`:" f"`timesteps` must start before `self.config.train_timesteps`: {self.config.num_train_timesteps}."
f" {self.config.num_train_timesteps}."
) )
# Raise warning if timestep schedule does not start with self.config.num_train_timesteps - 1 # Raise warning if timestep schedule does not start with self.config.num_train_timesteps - 1
......
...@@ -241,7 +241,7 @@ def _set_state_dict_into_text_encoder( ...@@ -241,7 +241,7 @@ def _set_state_dict_into_text_encoder(
""" """
text_encoder_state_dict = { text_encoder_state_dict = {
f'{k.replace(prefix, "")}': v for k, v in lora_state_dict.items() if k.startswith(prefix) f"{k.replace(prefix, '')}": v for k, v in lora_state_dict.items() if k.startswith(prefix)
} }
text_encoder_state_dict = convert_state_dict_to_peft(convert_state_dict_to_diffusers(text_encoder_state_dict)) text_encoder_state_dict = convert_state_dict_to_peft(convert_state_dict_to_diffusers(text_encoder_state_dict))
set_peft_model_state_dict(text_encoder, text_encoder_state_dict, adapter_name="default") set_peft_model_state_dict(text_encoder, text_encoder_state_dict, adapter_name="default")
...@@ -583,7 +583,7 @@ class EMAModel: ...@@ -583,7 +583,7 @@ class EMAModel:
""" """
if self.temp_stored_params is None: if self.temp_stored_params is None:
raise RuntimeError("This ExponentialMovingAverage has no `store()`ed weights " "to `restore()`") raise RuntimeError("This ExponentialMovingAverage has no `store()`ed weights to `restore()`")
if self.foreach: if self.foreach:
torch._foreach_copy_( torch._foreach_copy_(
[param.data for param in parameters], [c_param.data for c_param in self.temp_stored_params] [param.data for param in parameters], [c_param.data for c_param in self.temp_stored_params]
......
...@@ -40,7 +40,7 @@ def deprecate(*args, take_from: Optional[Union[Dict, Any]] = None, standard_warn ...@@ -40,7 +40,7 @@ def deprecate(*args, take_from: Optional[Union[Dict, Any]] = None, standard_warn
line_number = call_frame.lineno line_number = call_frame.lineno
function = call_frame.function function = call_frame.function
key, value = next(iter(deprecated_kwargs.items())) key, value = next(iter(deprecated_kwargs.items()))
raise TypeError(f"{function} in {filename} line {line_number-1} got an unexpected keyword argument `{key}`") raise TypeError(f"{function} in {filename} line {line_number - 1} got an unexpected keyword argument `{key}`")
if len(values) == 0: if len(values) == 0:
return return
......
...@@ -60,8 +60,7 @@ def _get_default_logging_level() -> int: ...@@ -60,8 +60,7 @@ def _get_default_logging_level() -> int:
return log_levels[env_level_str] return log_levels[env_level_str]
else: else:
logging.getLogger().warning( logging.getLogger().warning(
f"Unknown option DIFFUSERS_VERBOSITY={env_level_str}, " f"Unknown option DIFFUSERS_VERBOSITY={env_level_str}, has to be one of: {', '.join(log_levels.keys())}"
f"has to be one of: { ', '.join(log_levels.keys()) }"
) )
return _default_log_level return _default_log_level
......
...@@ -334,7 +334,7 @@ def convert_state_dict_to_kohya(state_dict, original_type=None, **kwargs): ...@@ -334,7 +334,7 @@ def convert_state_dict_to_kohya(state_dict, original_type=None, **kwargs):
kohya_key = kohya_key.replace(peft_adapter_name, "") # Kohya doesn't take names kohya_key = kohya_key.replace(peft_adapter_name, "") # Kohya doesn't take names
kohya_ss_state_dict[kohya_key] = weight kohya_ss_state_dict[kohya_key] = weight
if "lora_down" in kohya_key: if "lora_down" in kohya_key:
alpha_key = f'{kohya_key.split(".")[0]}.alpha' alpha_key = f"{kohya_key.split('.')[0]}.alpha"
kohya_ss_state_dict[alpha_key] = torch.tensor(len(weight)) kohya_ss_state_dict[alpha_key] = torch.tensor(len(weight))
return kohya_ss_state_dict return kohya_ss_state_dict
......
...@@ -882,7 +882,7 @@ def pytest_terminal_summary_main(tr, id): ...@@ -882,7 +882,7 @@ def pytest_terminal_summary_main(tr, id):
f.write("slowest durations\n") f.write("slowest durations\n")
for i, rep in enumerate(dlist): for i, rep in enumerate(dlist):
if rep.duration < durations_min: if rep.duration < durations_min:
f.write(f"{len(dlist)-i} durations < {durations_min} secs were omitted") f.write(f"{len(dlist) - i} durations < {durations_min} secs were omitted")
break break
f.write(f"{rep.duration:02.2f}s {rep.when:<8} {rep.nodeid}\n") f.write(f"{rep.duration:02.2f}s {rep.when:<8} {rep.nodeid}\n")
...@@ -1027,7 +1027,7 @@ def run_test_in_subprocess(test_case, target_func, inputs=None, timeout=None): ...@@ -1027,7 +1027,7 @@ def run_test_in_subprocess(test_case, target_func, inputs=None, timeout=None):
process.join(timeout=timeout) process.join(timeout=timeout)
if results["error"] is not None: if results["error"] is not None:
test_case.fail(f'{results["error"]}') test_case.fail(f"{results['error']}")
class CaptureLogger: class CaptureLogger:
......
...@@ -168,9 +168,7 @@ class HookTests(unittest.TestCase): ...@@ -168,9 +168,7 @@ class HookTests(unittest.TestCase):
registry.register_hook(MultiplyHook(2), "multiply_hook") registry.register_hook(MultiplyHook(2), "multiply_hook")
registry_repr = repr(registry) registry_repr = repr(registry)
expected_repr = ( expected_repr = "HookRegistry(\n (0) add_hook - AddHook\n (1) multiply_hook - MultiplyHook(value=2)\n)"
"HookRegistry(\n" " (0) add_hook - AddHook\n" " (1) multiply_hook - MultiplyHook(value=2)\n" ")"
)
self.assertEqual(len(registry.hooks), 2) self.assertEqual(len(registry.hooks), 2)
self.assertEqual(registry._hook_order, ["add_hook", "multiply_hook"]) self.assertEqual(registry._hook_order, ["add_hook", "multiply_hook"])
...@@ -285,12 +283,7 @@ class HookTests(unittest.TestCase): ...@@ -285,12 +283,7 @@ class HookTests(unittest.TestCase):
self.model(input) self.model(input)
output = cap_logger.out.replace(" ", "").replace("\n", "") output = cap_logger.out.replace(" ", "").replace("\n", "")
expected_invocation_order_log = ( expected_invocation_order_log = (
( ("MultiplyHook pre_forward\nAddHook pre_forward\nAddHook post_forward\nMultiplyHook post_forward\n")
"MultiplyHook pre_forward\n"
"AddHook pre_forward\n"
"AddHook post_forward\n"
"MultiplyHook post_forward\n"
)
.replace(" ", "") .replace(" ", "")
.replace("\n", "") .replace("\n", "")
) )
......
...@@ -299,9 +299,9 @@ class ModelUtilsTest(unittest.TestCase): ...@@ -299,9 +299,9 @@ class ModelUtilsTest(unittest.TestCase):
) )
download_requests = [r.method for r in m.request_history] download_requests = [r.method for r in m.request_history]
assert ( assert download_requests.count("HEAD") == 3, (
download_requests.count("HEAD") == 3 "3 HEAD requests one for config, one for model, and one for shard index file."
), "3 HEAD requests one for config, one for model, and one for shard index file." )
assert download_requests.count("GET") == 2, "2 GET requests one for config, one for model" assert download_requests.count("GET") == 2, "2 GET requests one for config, one for model"
with requests_mock.mock(real_http=True) as m: with requests_mock.mock(real_http=True) as m:
...@@ -313,9 +313,9 @@ class ModelUtilsTest(unittest.TestCase): ...@@ -313,9 +313,9 @@ class ModelUtilsTest(unittest.TestCase):
) )
cache_requests = [r.method for r in m.request_history] cache_requests = [r.method for r in m.request_history]
assert ( assert "HEAD" == cache_requests[0] and len(cache_requests) == 2, (
"HEAD" == cache_requests[0] and len(cache_requests) == 2 "We should call only `model_info` to check for commit hash and knowing if shard index is present."
), "We should call only `model_info` to check for commit hash and knowing if shard index is present." )
def test_weight_overwrite(self): def test_weight_overwrite(self):
with tempfile.TemporaryDirectory() as tmpdirname, self.assertRaises(ValueError) as error_context: with tempfile.TemporaryDirectory() as tmpdirname, self.assertRaises(ValueError) as error_context:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment