16 lines
896 B
Python
16 lines
896 B
Python
|
|
"""Add block-0 in-memory AdaLN projection weights to the capture."""
|
||
|
|
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
|
||
|
|
model = Path("/opt/ComfyUI/comfy/ldm/minimax/model.py")
|
||
|
|
source = model.read_text(encoding="utf-8")
|
||
|
|
old = 'torch.save({"norm": norm1.detach().cpu(), "shift": shift_msa.detach().cpu(), "scale": scale_msa.detach().cpu()}, os.path.join(capture_dir, "block0_norm1_adaln.pt"))'
|
||
|
|
new = 'torch.save({"norm": norm1.detach().cpu(), "shift": shift_msa.detach().cpu(), "scale": scale_msa.detach().cpu(), "weight": self.adaln_proj.linear.weight.detach().cpu(), "bias": self.adaln_proj.linear.bias.detach().cpu()}, os.path.join(capture_dir, "block0_norm1_adaln.pt"))'
|
||
|
|
if source.count(old) == 1:
|
||
|
|
source = source.replace(old, new)
|
||
|
|
elif new not in source:
|
||
|
|
raise RuntimeError("Unable to locate AdaLN capture payload.")
|
||
|
|
model.write_text(source, encoding="utf-8")
|
||
|
|
print("Applied H3 AdaLN weight capture patch.")
|