Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -527,6 +527,15 @@ def load_models() -> str | None:
|
|
| 527 |
rope_theta ** (torch.arange(0, 2 * rope_freq_dim, 2, dtype=torch.float32) / (2 * rope_freq_dim))
|
| 528 |
)
|
| 529 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 530 |
pipe.update_components(transformer=custom_transformer)
|
| 531 |
print(f"[gen] transformer replaced with {CUSTOM_TRANSFORMER_REPO}/{CUSTOM_TRANSFORMER_FILE}", flush=True)
|
| 532 |
|
|
|
|
| 527 |
rope_theta ** (torch.arange(0, 2 * rope_freq_dim, 2, dtype=torch.float32) / (2 * rope_freq_dim))
|
| 528 |
)
|
| 529 |
|
| 530 |
+
# `_keep_in_fp32_modules` is normally enforced by `from_pretrained`'s own post-load dtype pass — a
|
| 531 |
+
# step this manual meta-device + `load_state_dict` path never goes through. The official checkpoint
|
| 532 |
+
# genuinely ships these modules as float32 while everything else is bfloat16; if the finetune's file
|
| 533 |
+
# is uniformly bf16 (common for a community single-file export), `assign=True` just adopted that
|
| 534 |
+
# dtype for these layers too, silently dropping precision the model actually needs to run correctly.
|
| 535 |
+
for name, tensor in list(custom_transformer.named_parameters()) + list(custom_transformer.named_buffers()):
|
| 536 |
+
if any(keep in name for keep in MiniMaxH3Transformer3DModel._keep_in_fp32_modules):
|
| 537 |
+
tensor.data = tensor.data.to(torch.float32)
|
| 538 |
+
|
| 539 |
pipe.update_components(transformer=custom_transformer)
|
| 540 |
print(f"[gen] transformer replaced with {CUSTOM_TRANSFORMER_REPO}/{CUSTOM_TRANSFORMER_FILE}", flush=True)
|
| 541 |
|