The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
Fix last commit not working on older pytorch. (#9346)
comfyanonymous4e5c230f6a95
diff --git a/comfy/ops.py b/comfy/ops.pyindex 2be35f76a..18e7db705 100644--- a/comfy/ops.py+++ b/comfy/ops.py@@ -32,20 +32,21 @@ def scaled_dot_product_attention(q, k, v, *args, **kwargs):try:if torch.cuda.is_available():from torch.nn.attention import SDPBackend, sdpa_kernel-- SDPA_BACKEND_PRIORITY = [- SDPBackend.FLASH_ATTENTION,- SDPBackend.EFFICIENT_ATTENTION,- SDPBackend.MATH,- ]-- SDPA_BACKEND_PRIORITY.insert(0, SDPBackend.CUDNN_ATTENTION)-- def scaled_dot_product_attention(q, k, v, *args, **kwargs):- # Use this (rather than the decorator syntax) to eliminate graph- # break for pytorch < 2.9- with sdpa_kernel(SDPA_BACKEND_PRIORITY, set_priority=True):- return torch.nn.functional.scaled_dot_product_attention(q, k, v, *args, **kwargs)+ import inspect+ if "set_priority" in inspect.signature(sdpa_kernel).parameters:+ SDPA_BACKEND_PRIORITY = [+ SDPBackend.FLASH_ATTENTION,+ SDPBackend.EFFICIENT_ATTENTION,+ SDPBackend.MATH,+ ]++ SDPA_BACKEND_PRIORITY.insert(0, SDPBackend.CUDNN_ATTENTION)++ def scaled_dot_product_attention(q, k, v, *args, **kwargs):+ with sdpa_kernel(SDPA_BACKEND_PRIORITY, set_priority=True):+ return torch.nn.functional.scaled_dot_product_attention(q, k, v, *args, **kwargs)+ else:+ logging.warning("Torch version too old to set sdpa backend priority.")except (ModuleNotFoundError, TypeError):logging.warning("Could not set sdpa backend priority.")