MiniMax-H3-Image-GGUF / patch_comfyui_gguf.py
LSDJesus's picture
Add ComfyUI-GGUF patch script; README: how to use it
7d2ed44 verified
Raw History Blame Contribute Delete
2.53 kB
"""Let ComfyUI-GGUF load MiniMax-H3-Image GGUF files.
ComfyUI-GGUF only loads GGUF files whose architecture is on its list, and
"minimax_h3" isn't on it yet. This adds it: one word in
custom_nodes/ComfyUI-GGUF/loader.py. Nothing else changes.
Usage, from anywhere, with the Python that runs your ComfyUI:
python patch_comfyui_gguf.py PATH/TO/ComfyUI
python_embeded\\python.exe patch_comfyui_gguf.py ComfyUI (Windows portable)
Then restart ComfyUI. Running it twice is harmless. A copy of the original
is saved next to it as loader.py.bak.
If updating ComfyUI-GGUF later complains about local changes to loader.py,
restore the original (git checkout loader.py, or copy loader.py.bak back),
update, and run this again. Once ComfyUI-GGUF includes minimax_h3 itself,
you no longer need it.
"""
import glob
import os
import re
import shutil
import sys
ARCH = b'"minimax_h3"'
def find_loaders(root):
"""ComfyUI-GGUF's loader.py under root/custom_nodes (any folder name)."""
hits = []
for path in glob.glob(os.path.join(root, "custom_nodes", "*", "loader.py")):
with open(path, "rb") as f:
if b"IMG_ARCH_LIST" in f.read():
hits.append(path)
return hits
def patch(path):
with open(path, "rb") as f:
src = f.read()
m = re.search(rb"^IMG_ARCH_LIST\s*=\s*\{([^}\r\n]*)\}", src, re.M)
if not m:
print(f" {path}: no IMG_ARCH_LIST line in the expected form; edit it by hand")
return False
if ARCH in m.group(1):
print(f" {path}: already allows minimax_h3")
return True
body = m.group(1).rstrip()
new_body = (body + b", " if body else b"") + ARCH
out = src[:m.start(1)] + new_body + src[m.end(1):]
shutil.copy2(path, path + ".bak")
with open(path, "wb") as f:
f.write(out)
print(f" {path}: patched (original saved as loader.py.bak)")
return True
def main():
root = sys.argv[1] if len(sys.argv) > 1 else os.getcwd()
if os.path.basename(os.path.normpath(root)) == "custom_nodes":
root = os.path.dirname(os.path.normpath(root))
loaders = find_loaders(root)
if not loaders:
sys.exit(f"No ComfyUI-GGUF found in {os.path.join(root, 'custom_nodes')}. "
"Pass your ComfyUI folder: python patch_comfyui_gguf.py PATH/TO/ComfyUI")
ok = all(patch(p) for p in loaders)
print("Done. Restart ComfyUI." if ok else "Not every copy could be patched; see above.")
sys.exit(0 if ok else 1)
if __name__ == "__main__":
main()