"""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.")