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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py CHANGED
@@ -154,6 +154,52 @@ def load_models() -> str | None:
154
  pipe.load_components(dtype=torch.bfloat16)
155
  pipe.transformer.set_attention_backend(ATTENTION)
156
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  # Approach B: attach both LoRA adapters as PEFT layers on the transformer, inactive (weight 0) until a
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.
 
154
  pipe.load_components(dtype=torch.bfloat16)
155
  pipe.transformer.set_attention_backend(ATTENTION)
156
 
157
+ pipe.load_components(dtype=torch.bfloat16)
158
+ pipe.transformer.set_attention_backend(ATTENTION)
159
+
160
+ # --- Diagnostic: dump the LoRA files' key names/shapes and the transformer's own shapes to the Space
161
+ # logs, so the exact rename map can be worked out without a notebook or shell. Set H3_LORA_DEBUG=0 in
162
+ # the Space's env vars to silence this once you're done, or just delete this block later.
163
+ if os.environ.get("H3_LORA_DEBUG", "1") != "0" and LORA_REPO.lower() not in ("", "off", "none"):
164
+ from huggingface_hub import hf_hub_download
165
+ from safetensors import safe_open
166
+
167
+ for filename in LORA_FILES.values():
168
+ try:
169
+ path = hf_hub_download(LORA_REPO, filename)
170
+ with safe_open(path, framework="pt") as handle:
171
+ keys = sorted(handle.keys())
172
+ print(f"[lora-debug] {filename}: {len(keys)} keys", flush=True)
173
+ for k in keys[:40]:
174
+ print(f"[lora-debug] {k} {tuple(handle.get_slice(k).get_shape())}", flush=True)
175
+ if len(keys) > 40:
176
+ print(f"[lora-debug] ... and {len(keys) - 40} more", flush=True)
177
+ except Exception as error:
178
+ print(f"[lora-debug] failed to inspect {filename}: {error}", flush=True)
179
+
180
+ block0 = {
181
+ k: tuple(v.shape)
182
+ for k, v in pipe.transformer.state_dict().items()
183
+ if k.startswith("transformer_blocks.0.")
184
+ }
185
+ print(f"[lora-debug] transformer_blocks.0.* ({len(block0)} keys):", flush=True)
186
+ for k, shape in sorted(block0.items()):
187
+ print(f"[lora-debug] {k} {shape}", flush=True)
188
+ norm_out = {
189
+ k: tuple(v.shape) for k, v in pipe.transformer.state_dict().items() if k.startswith("norm_out.")
190
+ }
191
+ print(f"[lora-debug] norm_out.* ({len(norm_out)} keys):", flush=True)
192
+ for k, shape in sorted(norm_out.items()):
193
+ print(f"[lora-debug] {k} {shape}", flush=True)
194
+
195
+ if LORA_REPO.lower() not in ("", "off", "none"):
196
+ from peft.tuners.tuners_utils import BaseTunerLayer
197
+
198
+ try:
199
+ counts = {}
200
+ for name, filename in LORA_FILES.items():
201
+ ...
202
+
203
  # Approach B: attach both LoRA adapters as PEFT layers on the transformer, inactive (weight 0) until a
204
  # request asks for them. `load_lora_adapter` is the model-level loader (`PeftAdapterMixin`), used because
205
  # `MiniMaxH3ModularPipeline` has no pipeline-level `load_lora_weights` of its own.