Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
renzhc
diffusers_dcu
Commits
edc154da
Unverified
Commit
edc154da
authored
Apr 09, 2025
by
Dhruv Nair
Committed by
GitHub
Apr 09, 2025
Browse files
Update Ruff to latest Version (#10919)
* update * update * update * update
parent
552cd320
Changes
200
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
35 additions
and
52 deletions
+35
-52
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py
...nes/stable_diffusion/pipeline_stable_diffusion_inpaint.py
+3
-3
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py
...e_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py
+1
-1
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py
...ble_diffusion/pipeline_stable_diffusion_latent_upscale.py
+1
-1
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py
...nes/stable_diffusion/pipeline_stable_diffusion_upscale.py
+1
-1
src/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_inpaint.py
...stable_diffusion_3/pipeline_stable_diffusion_3_inpaint.py
+1
-1
src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py
...able_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py
+3
-3
src/diffusers/pipelines/wan/pipeline_wan_i2v.py
src/diffusers/pipelines/wan/pipeline_wan_i2v.py
+1
-1
src/diffusers/quantizers/base.py
src/diffusers/quantizers/base.py
+4
-8
src/diffusers/schedulers/scheduling_consistency_models.py
src/diffusers/schedulers/scheduling_consistency_models.py
+1
-2
src/diffusers/schedulers/scheduling_ddpm.py
src/diffusers/schedulers/scheduling_ddpm.py
+1
-2
src/diffusers/schedulers/scheduling_ddpm_parallel.py
src/diffusers/schedulers/scheduling_ddpm_parallel.py
+1
-2
src/diffusers/schedulers/scheduling_lcm.py
src/diffusers/schedulers/scheduling_lcm.py
+1
-2
src/diffusers/schedulers/scheduling_tcd.py
src/diffusers/schedulers/scheduling_tcd.py
+1
-2
src/diffusers/training_utils.py
src/diffusers/training_utils.py
+2
-2
src/diffusers/utils/deprecation_utils.py
src/diffusers/utils/deprecation_utils.py
+1
-1
src/diffusers/utils/logging.py
src/diffusers/utils/logging.py
+1
-2
src/diffusers/utils/state_dict_utils.py
src/diffusers/utils/state_dict_utils.py
+1
-1
src/diffusers/utils/testing_utils.py
src/diffusers/utils/testing_utils.py
+2
-2
tests/hooks/test_hooks.py
tests/hooks/test_hooks.py
+2
-9
tests/models/test_modeling_common.py
tests/models/test_modeling_common.py
+6
-6
No files found.
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py
View file @
edc154da
...
...
@@ -660,7 +660,7 @@ class StableDiffusionInpaintPipeline(
if
padding_mask_crop
is
not
None
:
if
not
isinstance
(
image
,
PIL
.
Image
.
Image
):
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
):
raise
ValueError
(
...
...
@@ -668,7 +668,7 @@ class StableDiffusionInpaintPipeline(
f
"
{
type
(
mask_image
)
}
."
)
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
:
raise
ValueError
(
...
...
@@ -1226,7 +1226,7 @@ class StableDiffusionInpaintPipeline(
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
" `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."
)
elif
num_channels_unet
!=
4
:
...
...
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py
View file @
edc154da
...
...
@@ -401,7 +401,7 @@ class StableDiffusionInstructPix2PixPipeline(
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
" `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."
)
...
...
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_latent_upscale.py
View file @
edc154da
...
...
@@ -600,7 +600,7 @@ class StableDiffusionLatentUpscalePipeline(DiffusionPipeline, StableDiffusionMix
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
" `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."
)
...
...
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_upscale.py
View file @
edc154da
...
...
@@ -740,7 +740,7 @@ class StableDiffusionUpscalePipeline(
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
" `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."
)
...
...
src/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3_inpaint.py
View file @
edc154da
...
...
@@ -1258,7 +1258,7 @@ class StableDiffusion3InpaintPipeline(DiffusionPipeline, SD3LoraLoaderMixin, Fro
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
" `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."
)
elif
num_channels_transformer
!=
16
:
...
...
src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl_inpaint.py
View file @
edc154da
...
...
@@ -741,7 +741,7 @@ class StableDiffusionXLInpaintPipeline(
if
padding_mask_crop
is
not
None
:
if
not
isinstance
(
image
,
PIL
.
Image
.
Image
):
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
):
raise
ValueError
(
...
...
@@ -749,7 +749,7 @@ class StableDiffusionXLInpaintPipeline(
f
"
{
type
(
mask_image
)
}
."
)
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
:
raise
ValueError
(
...
...
@@ -1509,7 +1509,7 @@ class StableDiffusionXLInpaintPipeline(
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
" `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."
)
elif
num_channels_unet
!=
4
:
...
...
src/diffusers/pipelines/wan/pipeline_wan_i2v.py
View file @
edc154da
...
...
@@ -334,7 +334,7 @@ class WanImageToVideoPipeline(DiffusionPipeline, WanLoraLoaderMixin):
"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
):
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
:
raise
ValueError
(
f
"`height` and `width` have to be divisible by 16 but are
{
height
}
and
{
width
}
."
)
...
...
src/diffusers/quantizers/base.py
View file @
edc154da
...
...
@@ -215,19 +215,15 @@ class DiffusersQuantizer(ABC):
)
@
abstractmethod
def
_process_model_before_weight_loading
(
self
,
model
,
**
kwargs
):
...
def
_process_model_before_weight_loading
(
self
,
model
,
**
kwargs
):
...
@
abstractmethod
def
_process_model_after_weight_loading
(
self
,
model
,
**
kwargs
):
...
def
_process_model_after_weight_loading
(
self
,
model
,
**
kwargs
):
...
@
property
@
abstractmethod
def
is_serializable
(
self
):
...
def
is_serializable
(
self
):
...
@
property
@
abstractmethod
def
is_trainable
(
self
):
...
def
is_trainable
(
self
):
...
src/diffusers/schedulers/scheduling_consistency_models.py
View file @
edc154da
...
...
@@ -203,8 +203,7 @@ class CMStochasticIterativeScheduler(SchedulerMixin, ConfigMixin):
if
timesteps
[
0
]
>=
self
.
config
.
num_train_timesteps
:
raise
ValueError
(
f
"`timesteps` must start before `self.config.train_timesteps`:"
f
"
{
self
.
config
.
num_train_timesteps
}
."
f
"`timesteps` must start before `self.config.train_timesteps`:
{
self
.
config
.
num_train_timesteps
}
."
)
timesteps
=
np
.
array
(
timesteps
,
dtype
=
np
.
int64
)
...
...
src/diffusers/schedulers/scheduling_ddpm.py
View file @
edc154da
...
...
@@ -279,8 +279,7 @@ class DDPMScheduler(SchedulerMixin, ConfigMixin):
if
timesteps
[
0
]
>=
self
.
config
.
num_train_timesteps
:
raise
ValueError
(
f
"`timesteps` must start before `self.config.train_timesteps`:"
f
"
{
self
.
config
.
num_train_timesteps
}
."
f
"`timesteps` must start before `self.config.train_timesteps`:
{
self
.
config
.
num_train_timesteps
}
."
)
timesteps
=
np
.
array
(
timesteps
,
dtype
=
np
.
int64
)
...
...
src/diffusers/schedulers/scheduling_ddpm_parallel.py
View file @
edc154da
...
...
@@ -289,8 +289,7 @@ class DDPMParallelScheduler(SchedulerMixin, ConfigMixin):
if
timesteps
[
0
]
>=
self
.
config
.
num_train_timesteps
:
raise
ValueError
(
f
"`timesteps` must start before `self.config.train_timesteps`:"
f
"
{
self
.
config
.
num_train_timesteps
}
."
f
"`timesteps` must start before `self.config.train_timesteps`:
{
self
.
config
.
num_train_timesteps
}
."
)
timesteps
=
np
.
array
(
timesteps
,
dtype
=
np
.
int64
)
...
...
src/diffusers/schedulers/scheduling_lcm.py
View file @
edc154da
...
...
@@ -413,8 +413,7 @@ class LCMScheduler(SchedulerMixin, ConfigMixin):
if
timesteps
[
0
]
>=
self
.
config
.
num_train_timesteps
:
raise
ValueError
(
f
"`timesteps` must start before `self.config.train_timesteps`:"
f
"
{
self
.
config
.
num_train_timesteps
}
."
f
"`timesteps` must start before `self.config.train_timesteps`:
{
self
.
config
.
num_train_timesteps
}
."
)
# Raise warning if timestep schedule does not start with self.config.num_train_timesteps - 1
...
...
src/diffusers/schedulers/scheduling_tcd.py
View file @
edc154da
...
...
@@ -431,8 +431,7 @@ class TCDScheduler(SchedulerMixin, ConfigMixin):
if
timesteps
[
0
]
>=
self
.
config
.
num_train_timesteps
:
raise
ValueError
(
f
"`timesteps` must start before `self.config.train_timesteps`:"
f
"
{
self
.
config
.
num_train_timesteps
}
."
f
"`timesteps` must start before `self.config.train_timesteps`:
{
self
.
config
.
num_train_timesteps
}
."
)
# Raise warning if timestep schedule does not start with self.config.num_train_timesteps - 1
...
...
src/diffusers/training_utils.py
View file @
edc154da
...
...
@@ -241,7 +241,7 @@ def _set_state_dict_into_text_encoder(
"""
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
))
set_peft_model_state_dict
(
text_encoder
,
text_encoder_state_dict
,
adapter_name
=
"default"
)
...
...
@@ -583,7 +583,7 @@ class EMAModel:
"""
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
:
torch
.
_foreach_copy_
(
[
param
.
data
for
param
in
parameters
],
[
c_param
.
data
for
c_param
in
self
.
temp_stored_params
]
...
...
src/diffusers/utils/deprecation_utils.py
View file @
edc154da
...
...
@@ -40,7 +40,7 @@ def deprecate(*args, take_from: Optional[Union[Dict, Any]] = None, standard_warn
line_number
=
call_frame
.
lineno
function
=
call_frame
.
function
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
:
return
...
...
src/diffusers/utils/logging.py
View file @
edc154da
...
...
@@ -60,8 +60,7 @@ def _get_default_logging_level() -> int:
return
log_levels
[
env_level_str
]
else
:
logging
.
getLogger
().
warning
(
f
"Unknown option DIFFUSERS_VERBOSITY=
{
env_level_str
}
, "
f
"has to be one of:
{
', '
.
join
(
log_levels
.
keys
())
}
"
f
"Unknown option DIFFUSERS_VERBOSITY=
{
env_level_str
}
, has to be one of:
{
', '
.
join
(
log_levels
.
keys
())
}
"
)
return
_default_log_level
...
...
src/diffusers/utils/state_dict_utils.py
View file @
edc154da
...
...
@@ -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_ss_state_dict
[
kohya_key
]
=
weight
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
))
return
kohya_ss_state_dict
...
...
src/diffusers/utils/testing_utils.py
View file @
edc154da
...
...
@@ -882,7 +882,7 @@ def pytest_terminal_summary_main(tr, id):
f
.
write
(
"slowest durations
\n
"
)
for
i
,
rep
in
enumerate
(
dlist
):
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
f
.
write
(
f
"
{
rep
.
duration
:
02.2
f
}
s
{
rep
.
when
:
<
8
}
{
rep
.
nodeid
}
\n
"
)
...
...
@@ -1027,7 +1027,7 @@ def run_test_in_subprocess(test_case, target_func, inputs=None, timeout=None):
process
.
join
(
timeout
=
timeout
)
if
results
[
"error"
]
is
not
None
:
test_case
.
fail
(
f
'
{
results
[
"
error
"
]
}
'
)
test_case
.
fail
(
f
"
{
results
[
'
error
'
]
}
"
)
class
CaptureLogger
:
...
...
tests/hooks/test_hooks.py
View file @
edc154da
...
...
@@ -168,9 +168,7 @@ class HookTests(unittest.TestCase):
registry
.
register_hook
(
MultiplyHook
(
2
),
"multiply_hook"
)
registry_repr
=
repr
(
registry
)
expected_repr
=
(
"HookRegistry(
\n
"
" (0) add_hook - AddHook
\n
"
" (1) multiply_hook - MultiplyHook(value=2)
\n
"
")"
)
expected_repr
=
"HookRegistry(
\n
(0) add_hook - AddHook
\n
(1) multiply_hook - MultiplyHook(value=2)
\n
)"
self
.
assertEqual
(
len
(
registry
.
hooks
),
2
)
self
.
assertEqual
(
registry
.
_hook_order
,
[
"add_hook"
,
"multiply_hook"
])
...
...
@@ -285,12 +283,7 @@ class HookTests(unittest.TestCase):
self
.
model
(
input
)
output
=
cap_logger
.
out
.
replace
(
" "
,
""
).
replace
(
"
\n
"
,
""
)
expected_invocation_order_log
=
(
(
"MultiplyHook pre_forward
\n
"
"AddHook pre_forward
\n
"
"AddHook post_forward
\n
"
"MultiplyHook post_forward
\n
"
)
(
"MultiplyHook pre_forward
\n
AddHook pre_forward
\n
AddHook post_forward
\n
MultiplyHook post_forward
\n
"
)
.
replace
(
" "
,
""
)
.
replace
(
"
\n
"
,
""
)
)
...
...
tests/models/test_modeling_common.py
View file @
edc154da
...
...
@@ -299,9 +299,9 @@ class ModelUtilsTest(unittest.TestCase):
)
download_requests
=
[
r
.
method
for
r
in
m
.
request_history
]
assert
(
download_requests
.
count
(
"HEAD"
)
==
3
)
,
"3 HEAD requests one for config, one for model, and one for shard index file."
assert
download_requests
.
count
(
"HEAD"
)
==
3
,
(
"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"
with
requests_mock
.
mock
(
real_http
=
True
)
as
m
:
...
...
@@ -313,9 +313,9 @@ class ModelUtilsTest(unittest.TestCase):
)
cache_requests
=
[
r
.
method
for
r
in
m
.
request_history
]
assert
(
"
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."
assert
"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."
)
def
test_weight_overwrite
(
self
):
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
,
self
.
assertRaises
(
ValueError
)
as
error_context
:
...
...
Prev
1
2
3
4
5
6
7
8
9
10
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment