Skip to content

Commit 0241dc6

Browse files
committed
fix: loras rearrange when refreshed
1 parent fac4304 commit 0241dc6

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

modules/interface.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,16 @@ def apply_startup_settings():
334334
)
335335
connect_audio_events(a, settings)
336336

337-
def refresh_loras():
337+
def refresh_loras(current_selected):
338338
if enumerate_lora_dir_fn:
339339
new_lora_names = enumerate_lora_dir_fn()
340-
return gr.update(choices=new_lora_names)
340+
preserved = [name for name in (current_selected or []) if name in new_lora_names]
341+
return gr.update(choices=new_lora_names, value=preserved)
341342
return gr.update()
342343

343-
g["refresh_loras_button"].click(fn=refresh_loras, outputs=[g["lora_selector"]])
344+
g["refresh_loras_button"].click(
345+
fn=refresh_loras, inputs=[g["lora_selector"]], outputs=[g["lora_selector"]]
346+
)
344347

345348
# General Connections
346349
def initial_gallery_load():

modules/ui/generate.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def create_generate_ui(
273273
latent_window_size = gr.Slider(
274274
label="Latent Window Size",
275275
minimum=1,
276-
maximum=33,
276+
maximum=60,
277277
value=9,
278278
step=1,
279279
info="Change at your own risk, very experimental",
@@ -611,6 +611,16 @@ def process_with_queue_update(model_type_arg, *args):
611611
if is_ui_video_model and input_video_arg is not None
612612
else None
613613
)
614+
# Realign LoRA names and weights to the stable slider order to prevent mis-mapping after refresh
615+
# The slider components are created at UI build time and their order remains stable.
616+
# After refreshing available LoRAs, choices can change, but we must keep lora_loaded_names (state)
617+
# aligned with the slider input order to avoid mixing/misalignment of weights.
618+
stable_slider_order = list(g["lora_sliders"].keys())
619+
incoming_weight_by_name = dict(zip(stable_slider_order, lora_slider_values_tuple))
620+
# Override the lora_names_states and weights passed to the backend to match the stable slider order
621+
lora_names_states_arg = stable_slider_order
622+
lora_slider_values_tuple = [incoming_weight_by_name.get(name, 1.0) for name in stable_slider_order]
623+
614624
result = f["process_fn"](
615625
backend_model_type,
616626
input_data,

shared/Enums.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from shared.StrEnum import StrEnum
66

7+
logger = logging.getLogger(__name__)
8+
79

810
class QuantizationFormat(StrEnum):
911
normal_float_4bit = auto()
@@ -12,7 +14,6 @@ class QuantizationFormat(StrEnum):
1214
NONE = brain_floating_point_16bit
1315
DEFAULT = NONE
1416

15-
__logger = logging.getLogger(__name__)
1617

1718
@staticmethod
1819
def supported_values() -> list[str]:
@@ -22,19 +23,19 @@ def supported_values() -> list[str]:
2223
@staticmethod
2324
def safe_parse(value: "str | QuantizationFormat") -> "QuantizationFormat":
2425
if find_spec("bitsandbytes") is None:
25-
QuantizationFormat.__logger.error(
26+
logger.error(
2627
"bitsandbytes not found, defaulting to no quantization. https://docs.framepackstudio.com/help"
2728
)
2829
# If bitsandbytes is not installed, we can not quantize, so return NONE
2930
return QuantizationFormat.NONE
3031

31-
QuantizationFormat.__logger.debug(f"QuantizationFormat: {value}")
32+
logger.debug(f"QuantizationFormat: {value}")
3233
if isinstance(value, QuantizationFormat):
3334
return value
3435
try:
3536
return QuantizationFormat(value)
3637
except ValueError:
37-
QuantizationFormat.__logger.exception(
38+
logger.exception(
3839
f"Invalid QuantizationFormat value: {value}, defaulting to {QuantizationFormat.DEFAULT}."
3940
)
4041
return QuantizationFormat.DEFAULT
@@ -45,7 +46,6 @@ class LoraLoader(StrEnum):
4546
LORA_READY = "lora_ready"
4647
DEFAULT = LORA_READY
4748

48-
__logger = logging.getLogger(__name__)
4949

5050
@staticmethod
5151
def supported_values() -> list[str]:
@@ -59,7 +59,7 @@ def safe_parse(value: "str | LoraLoader") -> "LoraLoader":
5959
try:
6060
return LoraLoader(value)
6161
except ValueError:
62-
LoraLoader.__logger.exception(
62+
logger.exception(
6363
f"Invalid LoraLoader value: {value}, defaulting to {LoraLoader.DEFAULT}."
6464
)
6565
return LoraLoader.DEFAULT

studio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def enumerate_lora_dir() -> list[str]:
265265
)
266266
lora_name = str(PurePath(lora_relative_path).with_suffix(""))
267267
found_files.append(lora_name)
268-
found_files.sort()
268+
found_files.sort(key=lambda s: s.casefold())
269269
print(f"Found LoRAs: {len(found_files)}")
270270
# Temp solution for only 1 lora
271271
if len(found_files) == 1:

0 commit comments

Comments
 (0)