h3-blackwell-runtime/tools/patch_comfy_h3_block0_adaln_capture.py
2026-08-12 21:11:02 +07:00

13 lines
678 B
Python

"""Keep the block-0 AdaLN capture from being overwritten by block 2."""
from pathlib import Path
model = Path("/opt/ComfyUI/comfy/ldm/minimax/model.py")
source = model.read_text(encoding="utf-8")
old = 'capture_dir = os.getenv("H3_CAPTURE_DIR") if getattr(self, "_h3_capture_index", -1) in (0, 2) and H3_CAPTURE_ACTIVE else None'
new = 'capture_dir = os.getenv("H3_CAPTURE_DIR") if getattr(self, "_h3_capture_index", -1) == 0 and H3_CAPTURE_ACTIVE else None'
if source.count(old) != 1:
raise RuntimeError("Unable to locate the H3 DiT AdaLN capture condition.")
model.write_text(source.replace(old, new), encoding="utf-8")
print("Restricted H3 AdaLN capture to block 0.")