dagloop5 commited on
Commit
005fd94
·
verified ·
1 Parent(s): 3759021

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -2
app.py CHANGED
@@ -158,12 +158,30 @@ def load_models() -> str | None:
158
  # request asks for them. `load_lora_adapter` is the model-level loader (`PeftAdapterMixin`), used because
159
  # `MiniMaxH3ModularPipeline` has no pipeline-level `load_lora_weights` of its own.
160
  if LORA_REPO.lower() not in ("", "off", "none"):
 
 
161
  try:
 
162
  for name, filename in LORA_FILES.items():
163
- pipe.transformer.load_lora_adapter(LORA_REPO, weight_name=filename, adapter_name=name)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  pipe.transformer.set_adapters(list(LORA_FILES), weights=[0.0] * len(LORA_FILES))
165
  LORA_STATUS = "LoRAs loaded: " + ", ".join(
166
- f"`{name}` ({LORA_REPO}/{filename})" for name, filename in LORA_FILES.items()
 
167
  )
168
  except Exception as error:
169
  LORA_STATUS = f"LoRA load failed: {type(error).__name__}: {error}"
 
158
  # request asks for them. `load_lora_adapter` is the model-level loader (`PeftAdapterMixin`), used because
159
  # `MiniMaxH3ModularPipeline` has no pipeline-level `load_lora_weights` of its own.
160
  if LORA_REPO.lower() not in ("", "off", "none"):
161
+ from peft.tuners.tuners_utils import BaseTunerLayer
162
+
163
  try:
164
+ counts = {}
165
  for name, filename in LORA_FILES.items():
166
+ pipe.transformer.load_lora_adapter(
167
+ LORA_REPO, weight_name=filename, adapter_name=name, prefix=None
168
+ )
169
+ # `load_lora_adapter` warns-and-continues on a zero-key match instead of raising, so count
170
+ # matched layers ourselves and fail loudly if a file attached nothing.
171
+ counts[name] = sum(
172
+ 1
173
+ for module in pipe.transformer.modules()
174
+ if isinstance(module, BaseTunerLayer) and name in module.lora_A
175
+ )
176
+ if counts[name] == 0:
177
+ raise RuntimeError(
178
+ f"'{filename}' matched 0 target modules on MiniMaxH3Transformer3DModel — its LoRA "
179
+ f"keys don't line up with this transformer's naming. Inspect its safetensors keys."
180
+ )
181
  pipe.transformer.set_adapters(list(LORA_FILES), weights=[0.0] * len(LORA_FILES))
182
  LORA_STATUS = "LoRAs loaded: " + ", ".join(
183
+ f"`{name}` ({LORA_REPO}/{filename}, {counts[name]} layers)"
184
+ for name, filename in LORA_FILES.items()
185
  )
186
  except Exception as error:
187
  LORA_STATUS = f"LoRA load failed: {type(error).__name__}: {error}"