anima-gradio-zerogpu-space / src /comfy_entry.py
JSCPPProgrammer's picture
fix: launch Comfy via comfy_entry.py; disable cuDNN SDPA to avoid H200 plan-builder errors in Anima attention
612669e verified
"""
Launch ComfyUI's main.py with PyTorch's cuDNN Scaled-Dot-Product-Attention
backend disabled. On H200 (ZeroGPU), cuDNN "frontend" attention can error with:
RuntimeError: cuDNN Frontend error: [cudnn_frontend] Error: No valid execution plans built.
in Anima's LLM/attention path (F.scaled_dot_product_attention). Flash / math SDPA
still work.
Set ANIMA_ALLOW_CUDNN_SDPA=1 in the environment to opt out and use PyTorch defaults.
"""
from __future__ import annotations
import os
import runpy
import sys
def main() -> None:
allow = os.environ.get("ANIMA_ALLOW_CUDNN_SDPA", "").strip() == "1"
if not allow:
os.environ.setdefault("TORCH_CUDNN_SDPA_ENABLED", "0")
root = os.environ.get("COMFYUI_ROOT", "").strip()
if not root:
print("comfy_entry: missing COMFYUI_ROOT", file=sys.stderr)
sys.exit(1)
main_py = os.path.join(root, "main.py")
if not os.path.isfile(main_py):
print(f"comfy_entry: not found: {main_py}", file=sys.stderr)
sys.exit(1)
if not allow:
import torch
if torch.cuda.is_available() and hasattr(
torch.backends.cuda, "enable_cudnn_sdp"
):
torch.backends.cuda.enable_cudnn_sdp(False)
os.chdir(root)
if root not in sys.path:
sys.path.insert(0, root)
# Same argv shape as: python main.py [args...]
sys.argv = [main_py, *sys.argv[1:]]
runpy.run_path(main_py, run_name="__main__")
if __name__ == "__main__":
main()