Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -512,6 +512,21 @@ def load_models() -> str | None:
|
|
| 512 |
raw = {k: handle.get_tensor(k) for k in handle.keys()}
|
| 513 |
converted = _convert_full_checkpoint(raw, base_shapes)
|
| 514 |
custom_transformer.load_state_dict(converted, strict=True, assign=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 515 |
pipe.update_components(transformer=custom_transformer)
|
| 516 |
print(f"[gen] transformer replaced with {CUSTOM_TRANSFORMER_REPO}/{CUSTOM_TRANSFORMER_FILE}", flush=True)
|
| 517 |
|
|
|
|
| 512 |
raw = {k: handle.get_tensor(k) for k in handle.keys()}
|
| 513 |
converted = _convert_full_checkpoint(raw, base_shapes)
|
| 514 |
custom_transformer.load_state_dict(converted, strict=True, assign=True)
|
| 515 |
+
|
| 516 |
+
# `rope.inv_freq` is a *non-persistent* buffer (`persistent=False` in `MiniMaxH3RotaryPosEmbed`) —
|
| 517 |
+
# excluded from `state_dict()` entirely, which is exactly why `strict=True` above never complained
|
| 518 |
+
# about its absence from the checkpoint (it was correctly dropped by `_convert_full_checkpoint` too).
|
| 519 |
+
# But that also means `load_state_dict(assign=True)` never touches it: it's still sitting on
|
| 520 |
+
# `torch.device("meta")` from construction, with nothing to move — which is what the later
|
| 521 |
+
# `pipe.transformer.to("cuda")` call was hitting ("Cannot copy out of meta tensor; no data!").
|
| 522 |
+
# Recomputed here from its own documented formula rather than moved, since a meta buffer has no data
|
| 523 |
+
# to move in the first place.
|
| 524 |
+
rope_theta = float(config["rope_theta"])
|
| 525 |
+
rope_freq_dim = int(config["rope_freq_dim"])
|
| 526 |
+
custom_transformer.rope.inv_freq = 1.0 / (
|
| 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 |
|