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
fengzch-das
nunchaku
Commits
3ef186fd
Commit
3ef186fd
authored
Mar 26, 2025
by
Muyang Li
Committed by
Zhekai Zhang
Apr 01, 2025
Browse files
Multiple LoRAs
parent
ca1a2e90
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
22 deletions
+3
-22
tests/flux/test_flux_dev.py
tests/flux/test_flux_dev.py
+2
-21
tests/flux/test_flux_dev_loras.py
tests/flux/test_flux_dev_loras.py
+1
-1
No files found.
tests/flux/test_flux_dev.py
View file @
3ef186fd
import
os
import
tempfile
import
pytest
import
torch
from
diffusers
import
FluxPipeline
from
peft.tuners
import
lora
from
safetensors.torch
import
save_file
from
nunchaku
import
NunchakuFluxTransformer2dModel
,
NunchakuT5EncoderModel
from
nunchaku.caching.diffusers_adapters
import
apply_cache_on_pipe
from
nunchaku.lora.flux
import
comfyui2diffusers
,
convert_to_nunchaku_flux_lowrank_dict
,
detect
_format
,
xlab2
diffusers
from
nunchaku.lora.flux
import
convert_to_nunchaku_flux_lowrank_dict
,
is_nunchaku
_format
,
to_
diffusers
from
.utils
import
run_pipeline
from
..data
import
get_dataset
from
..utils
import
already_generate
,
compute_lpips
...
...
@@ -98,24 +96,7 @@ def run_test_flux_dev(
)
if
lora_name
is
not
None
:
lora_path
=
LORA_PATH_MAP
[
lora_name
]
lora_format
=
detect_format
(
lora_path
)
if
lora_format
!=
"svdquant"
:
if
lora_format
==
"comfyui"
:
input_lora
=
comfyui2diffusers
(
lora_path
)
elif
lora_format
==
"xlab"
:
input_lora
=
xlab2diffusers
(
lora_path
)
elif
lora_format
==
"diffusers"
:
input_lora
=
lora_path
else
:
raise
ValueError
(
f
"Invalid LoRA format
{
lora_format
}
."
)
state_dict
=
convert_to_nunchaku_flux_lowrank_dict
(
"mit-han-lab/svdq-int4-flux.1-dev/transformer_blocks.safetensors"
,
input_lora
)
with
tempfile
.
NamedTemporaryFile
(
suffix
=
".safetensors"
,
delete
=
True
)
as
tmp_file
:
save_file
(
state_dict
,
tmp_file
.
name
)
transformer
.
update_lora_params
(
tmp_file
.
name
)
else
:
transformer
.
update_lora_params
(
lora_path
)
transformer
.
update_lora_params
(
lora_path
)
transformer
.
set_lora_strength
(
lora_scale
)
pipeline_init_kwargs
[
"transformer"
]
=
transformer
...
...
tests/flux/test_flux_dev_loras.py
View file @
3ef186fd
...
...
@@ -6,7 +6,7 @@ from tests.flux.test_flux_dev import run_test_flux_dev
@
pytest
.
mark
.
parametrize
(
"num_inference_steps,lora_name,lora_scale,cpu_offload,expected_lpips"
,
[
(
25
,
"realism"
,
0.9
,
False
,
0.1
6
),
(
25
,
"realism"
,
0.9
,
False
,
0.1
7
),
(
25
,
"ghibsky"
,
1
,
False
,
0.16
),
(
28
,
"anime"
,
1
,
False
,
0.27
),
(
24
,
"sketch"
,
1
,
False
,
0.35
),
...
...
Prev
1
2
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