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
09e777a3
Unverified
Commit
09e777a3
authored
Sep 24, 2025
by
Sayak Paul
Committed by
GitHub
Sep 24, 2025
Browse files
[tests] Single scheduler in lora tests (#12315)
* single scheduler please. * up * up * up
parent
a72bc0c4
Changes
14
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
1044 additions
and
1143 deletions
+1044
-1143
tests/lora/test_lora_layers_auraflow.py
tests/lora/test_lora_layers_auraflow.py
+0
-1
tests/lora/test_lora_layers_cogvideox.py
tests/lora/test_lora_layers_cogvideox.py
+0
-2
tests/lora/test_lora_layers_cogview4.py
tests/lora/test_lora_layers_cogview4.py
+17
-19
tests/lora/test_lora_layers_flux.py
tests/lora/test_lora_layers_flux.py
+2
-4
tests/lora/test_lora_layers_hunyuanvideo.py
tests/lora/test_lora_layers_hunyuanvideo.py
+0
-1
tests/lora/test_lora_layers_ltx_video.py
tests/lora/test_lora_layers_ltx_video.py
+0
-1
tests/lora/test_lora_layers_lumina2.py
tests/lora/test_lora_layers_lumina2.py
+27
-31
tests/lora/test_lora_layers_mochi.py
tests/lora/test_lora_layers_mochi.py
+0
-1
tests/lora/test_lora_layers_qwenimage.py
tests/lora/test_lora_layers_qwenimage.py
+0
-1
tests/lora/test_lora_layers_sana.py
tests/lora/test_lora_layers_sana.py
+2
-3
tests/lora/test_lora_layers_sd3.py
tests/lora/test_lora_layers_sd3.py
+0
-1
tests/lora/test_lora_layers_wan.py
tests/lora/test_lora_layers_wan.py
+0
-1
tests/lora/test_lora_layers_wanvace.py
tests/lora/test_lora_layers_wanvace.py
+1
-3
tests/lora/utils.py
tests/lora/utils.py
+995
-1074
No files found.
tests/lora/test_lora_layers_auraflow.py
View file @
09e777a3
...
...
@@ -43,7 +43,6 @@ from .utils import PeftLoraLoaderMixinTests # noqa: E402
class
AuraFlowLoRATests
(
unittest
.
TestCase
,
PeftLoraLoaderMixinTests
):
pipeline_class
=
AuraFlowPipeline
scheduler_cls
=
FlowMatchEulerDiscreteScheduler
scheduler_classes
=
[
FlowMatchEulerDiscreteScheduler
]
scheduler_kwargs
=
{}
transformer_kwargs
=
{
...
...
tests/lora/test_lora_layers_cogvideox.py
View file @
09e777a3
...
...
@@ -21,7 +21,6 @@ from transformers import AutoTokenizer, T5EncoderModel
from
diffusers
import
(
AutoencoderKLCogVideoX
,
CogVideoXDDIMScheduler
,
CogVideoXDPMScheduler
,
CogVideoXPipeline
,
CogVideoXTransformer3DModel
,
...
...
@@ -44,7 +43,6 @@ class CogVideoXLoRATests(unittest.TestCase, PeftLoraLoaderMixinTests):
pipeline_class
=
CogVideoXPipeline
scheduler_cls
=
CogVideoXDPMScheduler
scheduler_kwargs
=
{
"timestep_spacing"
:
"trailing"
}
scheduler_classes
=
[
CogVideoXDDIMScheduler
,
CogVideoXDPMScheduler
]
transformer_kwargs
=
{
"num_attention_heads"
:
4
,
...
...
tests/lora/test_lora_layers_cogview4.py
View file @
09e777a3
...
...
@@ -50,7 +50,6 @@ class TokenizerWrapper:
class
CogView4LoRATests
(
unittest
.
TestCase
,
PeftLoraLoaderMixinTests
):
pipeline_class
=
CogView4Pipeline
scheduler_cls
=
FlowMatchEulerDiscreteScheduler
scheduler_classes
=
[
FlowMatchEulerDiscreteScheduler
]
scheduler_kwargs
=
{}
transformer_kwargs
=
{
...
...
@@ -124,30 +123,29 @@ class CogView4LoRATests(unittest.TestCase, PeftLoraLoaderMixinTests):
"""
Tests a simple usecase where users could use saving utilities for LoRA through save_pretrained
"""
for
scheduler_cls
in
self
.
scheduler_classes
:
components
,
_
,
_
=
self
.
get_dummy_components
(
scheduler_cls
)
pipe
=
self
.
pipeline_class
(
**
components
)
pipe
=
pipe
.
to
(
torch_device
)
pipe
.
set_progress_bar_config
(
disable
=
None
)
_
,
_
,
inputs
=
self
.
get_dummy_inputs
(
with_generator
=
False
)
components
,
_
,
_
=
self
.
get_dummy_components
()
pipe
=
self
.
pipeline_class
(
**
components
)
pipe
=
pipe
.
to
(
torch_device
)
pipe
.
set_progress_bar_config
(
disable
=
None
)
_
,
_
,
inputs
=
self
.
get_dummy_inputs
(
with_generator
=
False
)
output_no_lora
=
pipe
(
**
inputs
,
generator
=
torch
.
manual_seed
(
0
))[
0
]
self
.
assertTrue
(
output_no_lora
.
shape
==
self
.
output_shape
)
output_no_lora
=
pipe
(
**
inputs
,
generator
=
torch
.
manual_seed
(
0
))[
0
]
self
.
assertTrue
(
output_no_lora
.
shape
==
self
.
output_shape
)
images_lora
=
pipe
(
**
inputs
,
generator
=
torch
.
manual_seed
(
0
))[
0
]
images_lora
=
pipe
(
**
inputs
,
generator
=
torch
.
manual_seed
(
0
))[
0
]
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
:
pipe
.
save_pretrained
(
tmpdirname
)
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
:
pipe
.
save_pretrained
(
tmpdirname
)
pipe_from_pretrained
=
self
.
pipeline_class
.
from_pretrained
(
tmpdirname
)
pipe_from_pretrained
.
to
(
torch_device
)
pipe_from_pretrained
=
self
.
pipeline_class
.
from_pretrained
(
tmpdirname
)
pipe_from_pretrained
.
to
(
torch_device
)
images_lora_save_pretrained
=
pipe_from_pretrained
(
**
inputs
,
generator
=
torch
.
manual_seed
(
0
))[
0
]
images_lora_save_pretrained
=
pipe_from_pretrained
(
**
inputs
,
generator
=
torch
.
manual_seed
(
0
))[
0
]
self
.
assertTrue
(
np
.
allclose
(
images_lora
,
images_lora_save_pretrained
,
atol
=
1e-3
,
rtol
=
1e-3
),
"Loading from saved checkpoints should give same results."
,
)
self
.
assertTrue
(
np
.
allclose
(
images_lora
,
images_lora_save_pretrained
,
atol
=
1e-3
,
rtol
=
1e-3
),
"Loading from saved checkpoints should give same results."
,
)
@
parameterized
.
expand
([(
"block_level"
,
True
),
(
"leaf_level"
,
False
)])
@
require_torch_accelerator
...
...
tests/lora/test_lora_layers_flux.py
View file @
09e777a3
...
...
@@ -55,9 +55,8 @@ from .utils import PeftLoraLoaderMixinTests, check_if_lora_correctly_set # noqa
@
require_peft_backend
class
FluxLoRATests
(
unittest
.
TestCase
,
PeftLoraLoaderMixinTests
):
pipeline_class
=
FluxPipeline
scheduler_cls
=
FlowMatchEulerDiscreteScheduler
()
scheduler_cls
=
FlowMatchEulerDiscreteScheduler
scheduler_kwargs
=
{}
scheduler_classes
=
[
FlowMatchEulerDiscreteScheduler
]
transformer_kwargs
=
{
"patch_size"
:
1
,
"in_channels"
:
4
,
...
...
@@ -282,9 +281,8 @@ class FluxLoRATests(unittest.TestCase, PeftLoraLoaderMixinTests):
class
FluxControlLoRATests
(
unittest
.
TestCase
,
PeftLoraLoaderMixinTests
):
pipeline_class
=
FluxControlPipeline
scheduler_cls
=
FlowMatchEulerDiscreteScheduler
()
scheduler_cls
=
FlowMatchEulerDiscreteScheduler
scheduler_kwargs
=
{}
scheduler_classes
=
[
FlowMatchEulerDiscreteScheduler
]
transformer_kwargs
=
{
"patch_size"
:
1
,
"in_channels"
:
8
,
...
...
tests/lora/test_lora_layers_hunyuanvideo.py
View file @
09e777a3
...
...
@@ -51,7 +51,6 @@ from .utils import PeftLoraLoaderMixinTests # noqa: E402
class
HunyuanVideoLoRATests
(
unittest
.
TestCase
,
PeftLoraLoaderMixinTests
):
pipeline_class
=
HunyuanVideoPipeline
scheduler_cls
=
FlowMatchEulerDiscreteScheduler
scheduler_classes
=
[
FlowMatchEulerDiscreteScheduler
]
scheduler_kwargs
=
{}
transformer_kwargs
=
{
...
...
tests/lora/test_lora_layers_ltx_video.py
View file @
09e777a3
...
...
@@ -37,7 +37,6 @@ from .utils import PeftLoraLoaderMixinTests # noqa: E402
class
LTXVideoLoRATests
(
unittest
.
TestCase
,
PeftLoraLoaderMixinTests
):
pipeline_class
=
LTXPipeline
scheduler_cls
=
FlowMatchEulerDiscreteScheduler
scheduler_classes
=
[
FlowMatchEulerDiscreteScheduler
]
scheduler_kwargs
=
{}
transformer_kwargs
=
{
...
...
tests/lora/test_lora_layers_lumina2.py
View file @
09e777a3
...
...
@@ -39,7 +39,6 @@ from .utils import PeftLoraLoaderMixinTests, check_if_lora_correctly_set # noqa
class
Lumina2LoRATests
(
unittest
.
TestCase
,
PeftLoraLoaderMixinTests
):
pipeline_class
=
Lumina2Pipeline
scheduler_cls
=
FlowMatchEulerDiscreteScheduler
scheduler_classes
=
[
FlowMatchEulerDiscreteScheduler
]
scheduler_kwargs
=
{}
transformer_kwargs
=
{
...
...
@@ -141,33 +140,30 @@ class Lumina2LoRATests(unittest.TestCase, PeftLoraLoaderMixinTests):
strict
=
False
,
)
def
test_lora_fuse_nan
(
self
):
for
scheduler_cls
in
self
.
scheduler_classes
:
components
,
text_lora_config
,
denoiser_lora_config
=
self
.
get_dummy_components
(
scheduler_cls
)
pipe
=
self
.
pipeline_class
(
**
components
)
pipe
=
pipe
.
to
(
torch_device
)
pipe
.
set_progress_bar_config
(
disable
=
None
)
_
,
_
,
inputs
=
self
.
get_dummy_inputs
(
with_generator
=
False
)
if
"text_encoder"
in
self
.
pipeline_class
.
_lora_loadable_modules
:
pipe
.
text_encoder
.
add_adapter
(
text_lora_config
,
"adapter-1"
)
self
.
assertTrue
(
check_if_lora_correctly_set
(
pipe
.
text_encoder
),
"Lora not correctly set in text encoder"
)
denoiser
=
pipe
.
transformer
if
self
.
unet_kwargs
is
None
else
pipe
.
unet
denoiser
.
add_adapter
(
denoiser_lora_config
,
"adapter-1"
)
self
.
assertTrue
(
check_if_lora_correctly_set
(
denoiser
),
"Lora not correctly set in denoiser."
)
# corrupt one LoRA weight with `inf` values
with
torch
.
no_grad
():
pipe
.
transformer
.
layers
[
0
].
attn
.
to_q
.
lora_A
[
"adapter-1"
].
weight
+=
float
(
"inf"
)
# with `safe_fusing=True` we should see an Error
with
self
.
assertRaises
(
ValueError
):
pipe
.
fuse_lora
(
components
=
self
.
pipeline_class
.
_lora_loadable_modules
,
safe_fusing
=
True
)
# without we should not see an error, but every image will be black
pipe
.
fuse_lora
(
components
=
self
.
pipeline_class
.
_lora_loadable_modules
,
safe_fusing
=
False
)
out
=
pipe
(
**
inputs
)[
0
]
self
.
assertTrue
(
np
.
isnan
(
out
).
all
())
components
,
text_lora_config
,
denoiser_lora_config
=
self
.
get_dummy_components
()
pipe
=
self
.
pipeline_class
(
**
components
)
pipe
=
pipe
.
to
(
torch_device
)
pipe
.
set_progress_bar_config
(
disable
=
None
)
_
,
_
,
inputs
=
self
.
get_dummy_inputs
(
with_generator
=
False
)
if
"text_encoder"
in
self
.
pipeline_class
.
_lora_loadable_modules
:
pipe
.
text_encoder
.
add_adapter
(
text_lora_config
,
"adapter-1"
)
self
.
assertTrue
(
check_if_lora_correctly_set
(
pipe
.
text_encoder
),
"Lora not correctly set in text encoder"
)
denoiser
=
pipe
.
transformer
if
self
.
unet_kwargs
is
None
else
pipe
.
unet
denoiser
.
add_adapter
(
denoiser_lora_config
,
"adapter-1"
)
self
.
assertTrue
(
check_if_lora_correctly_set
(
denoiser
),
"Lora not correctly set in denoiser."
)
# corrupt one LoRA weight with `inf` values
with
torch
.
no_grad
():
pipe
.
transformer
.
layers
[
0
].
attn
.
to_q
.
lora_A
[
"adapter-1"
].
weight
+=
float
(
"inf"
)
# with `safe_fusing=True` we should see an Error
with
self
.
assertRaises
(
ValueError
):
pipe
.
fuse_lora
(
components
=
self
.
pipeline_class
.
_lora_loadable_modules
,
safe_fusing
=
True
)
# without we should not see an error, but every image will be black
pipe
.
fuse_lora
(
components
=
self
.
pipeline_class
.
_lora_loadable_modules
,
safe_fusing
=
False
)
out
=
pipe
(
**
inputs
)[
0
]
self
.
assertTrue
(
np
.
isnan
(
out
).
all
())
tests/lora/test_lora_layers_mochi.py
View file @
09e777a3
...
...
@@ -37,7 +37,6 @@ from .utils import PeftLoraLoaderMixinTests # noqa: E402
class
MochiLoRATests
(
unittest
.
TestCase
,
PeftLoraLoaderMixinTests
):
pipeline_class
=
MochiPipeline
scheduler_cls
=
FlowMatchEulerDiscreteScheduler
scheduler_classes
=
[
FlowMatchEulerDiscreteScheduler
]
scheduler_kwargs
=
{}
transformer_kwargs
=
{
...
...
tests/lora/test_lora_layers_qwenimage.py
View file @
09e777a3
...
...
@@ -37,7 +37,6 @@ from .utils import PeftLoraLoaderMixinTests # noqa: E402
class
QwenImageLoRATests
(
unittest
.
TestCase
,
PeftLoraLoaderMixinTests
):
pipeline_class
=
QwenImagePipeline
scheduler_cls
=
FlowMatchEulerDiscreteScheduler
scheduler_classes
=
[
FlowMatchEulerDiscreteScheduler
]
scheduler_kwargs
=
{}
transformer_kwargs
=
{
...
...
tests/lora/test_lora_layers_sana.py
View file @
09e777a3
...
...
@@ -31,9 +31,8 @@ from .utils import PeftLoraLoaderMixinTests # noqa: E402
@
require_peft_backend
class
SanaLoRATests
(
unittest
.
TestCase
,
PeftLoraLoaderMixinTests
):
pipeline_class
=
SanaPipeline
scheduler_cls
=
FlowMatchEulerDiscreteScheduler
(
shift
=
7.0
)
scheduler_kwargs
=
{}
scheduler_classes
=
[
FlowMatchEulerDiscreteScheduler
]
scheduler_cls
=
FlowMatchEulerDiscreteScheduler
scheduler_kwargs
=
{
"shift"
:
7.0
}
transformer_kwargs
=
{
"patch_size"
:
1
,
"in_channels"
:
4
,
...
...
tests/lora/test_lora_layers_sd3.py
View file @
09e777a3
...
...
@@ -55,7 +55,6 @@ class SD3LoRATests(unittest.TestCase, PeftLoraLoaderMixinTests):
pipeline_class
=
StableDiffusion3Pipeline
scheduler_cls
=
FlowMatchEulerDiscreteScheduler
scheduler_kwargs
=
{}
scheduler_classes
=
[
FlowMatchEulerDiscreteScheduler
]
transformer_kwargs
=
{
"sample_size"
:
32
,
"patch_size"
:
1
,
...
...
tests/lora/test_lora_layers_wan.py
View file @
09e777a3
...
...
@@ -42,7 +42,6 @@ from .utils import PeftLoraLoaderMixinTests # noqa: E402
class
WanLoRATests
(
unittest
.
TestCase
,
PeftLoraLoaderMixinTests
):
pipeline_class
=
WanPipeline
scheduler_cls
=
FlowMatchEulerDiscreteScheduler
scheduler_classes
=
[
FlowMatchEulerDiscreteScheduler
]
scheduler_kwargs
=
{}
transformer_kwargs
=
{
...
...
tests/lora/test_lora_layers_wanvace.py
View file @
09e777a3
...
...
@@ -50,7 +50,6 @@ from .utils import PeftLoraLoaderMixinTests # noqa: E402
class
WanVACELoRATests
(
unittest
.
TestCase
,
PeftLoraLoaderMixinTests
):
pipeline_class
=
WanVACEPipeline
scheduler_cls
=
FlowMatchEulerDiscreteScheduler
scheduler_classes
=
[
FlowMatchEulerDiscreteScheduler
]
scheduler_kwargs
=
{}
transformer_kwargs
=
{
...
...
@@ -165,9 +164,8 @@ class WanVACELoRATests(unittest.TestCase, PeftLoraLoaderMixinTests):
@
require_peft_version_greater
(
"0.13.2"
)
def
test_lora_exclude_modules_wanvace
(
self
):
scheduler_cls
=
self
.
scheduler_classes
[
0
]
exclude_module_name
=
"vace_blocks.0.proj_out"
components
,
text_lora_config
,
denoiser_lora_config
=
self
.
get_dummy_components
(
scheduler_cls
)
components
,
text_lora_config
,
denoiser_lora_config
=
self
.
get_dummy_components
()
pipe
=
self
.
pipeline_class
(
**
components
).
to
(
torch_device
)
_
,
_
,
inputs
=
self
.
get_dummy_inputs
(
with_generator
=
False
)
...
...
tests/lora/utils.py
View file @
09e777a3
This diff is collapsed.
Click to expand it.
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