@@ -103,12 +103,10 @@ def test_local_directory_with_multiple_files_warns_and_uses_first(tmp_path, monk
103103
104104
105105def test_unfuse_lora_partial_components_keeps_merged_adapters_in_sync ():
106- """Regression test for # 14214.
106+ """Regression test for gh- 14214.
107107
108- When unfuse_lora is called with a subset of components, _merged_adapters
109- should still reflect adapters that are physically fused in the remaining
110- components. Before the fix, it removed the adapter on the first unfuse
111- even if other components still had it baked in.
108+ Unfusing only a subset of components must keep _merged_adapters in sync
109+ with the adapters still physically fused in the remaining components.
112110 """
113111 import torch .nn as nn
114112 from peft import LoraConfig
@@ -140,24 +138,15 @@ def __init__(self, unet, text_encoder):
140138 pipe .fuse_lora (components = ["unet" , "text_encoder" ], adapter_names = ["adapter" ])
141139 assert pipe .num_fused_loras == 1
142140
143- # Unfuse only text_encoder — unet is still physically fused
144141 pipe .unfuse_lora (components = ["text_encoder" ])
142+ assert "adapter" in pipe .fused_loras , "adapter should remain tracked while unet is still fused"
143+ assert pipe .num_fused_loras == 1
145144
146- # _merged_adapters must still track the adapter (unet is still fused)
147- assert "adapter" in pipe .fused_loras , (
148- "adapter should remain in fused_loras while unet is still fused"
149- )
150- assert pipe .num_fused_loras == 1 , (
151- f"Expected 1 fused lora, got { pipe .num_fused_loras } "
152- )
153-
154- # Confirm unet is physically still merged at the PEFT level
155145 unet_still_merged = any (
156146 isinstance (m , BaseTunerLayer ) and len (m .merged_adapters ) > 0
157147 for m in unet .modules ()
158148 )
159- assert unet_still_merged , "unet should be physically merged at the PEFT level"
149+ assert unet_still_merged , "unet should still be physically merged at the PEFT level"
160150
161- # Now unfuse unet too — both components are done
162151 pipe .unfuse_lora (components = ["unet" ])
163- assert pipe .num_fused_loras == 0 , "All components unfused, fused_loras should be empty"
152+ assert pipe .num_fused_loras == 0
0 commit comments