From e589062ea4fa9fa561d0a67466d2eb3b86c88a00 Mon Sep 17 00:00:00 2001 From: Sirshendu Ganguly Date: Wed, 1 Oct 2025 12:16:58 -0400 Subject: [PATCH] feat: Replace TeaCache/DeepCache with unified Accelerator Options - Remove individual TeaCache and DeepCache modules - Create new unified 'Runware Accelerator Options' node - Support all accelerator parameters: fbcache, cacheDistance, teaCache, teaCacheDistance, deepCache, deepCacheInterval, deepCacheBranchId - Add cache step control: cacheStartStep, cacheStartStepPercentage, cacheEndStep, cacheEndStepPercentage, cacheMaxConsecutiveSteps - Update imageInference.py to support new accelerator system --- __init__.py | 6 +- modules/acceleratorOptions.py | 143 ++++++++++++++++++++++++++++++++++ modules/deepCache.py | 45 ----------- modules/imageInference.py | 4 +- modules/teaCache.py | 33 -------- 5 files changed, 147 insertions(+), 84 deletions(-) create mode 100644 modules/acceleratorOptions.py delete mode 100644 modules/deepCache.py delete mode 100644 modules/teaCache.py diff --git a/__init__.py b/__init__.py index 6738b38..c0938e6 100644 --- a/__init__.py +++ b/__init__.py @@ -9,8 +9,6 @@ from .modules.controlNet import controlNet from .modules.multiInference import multiInference from .modules.runwareBFL import runwareKontext from .modules.runwareImagen import runwareImagen -from .modules.teaCache import teaCache -from .modules.deepCache import deepCache from .modules.loraSearch import loraSearch from .modules.loraCombine import loraCombine from .modules.refiner import refiner @@ -37,6 +35,7 @@ from .modules.audioModelSearch import RunwareAudioModelSearch from .modules.audioSections import RunwareAudioSections from .modules.elevenlabsProviderSettings import RunwareElevenLabsProviderSettings from .modules.elevenlabsProviderSettingsSections import RunwareElevenLabsProviderSettingsSections +from .modules.acceleratorOptions import acceleratorOptions RUNWARE_COMFYUI_VERSION = "1.4.0 Beta" @@ -59,8 +58,6 @@ NODE_CLASS_MAPPINGS = { "Runware Kontext Inference": runwareKontext, "Runware Imagen Inference": runwareImagen, "Runware Multi Inference": multiInference, - "Runware TeaCache": teaCache, - "Runware DeepCache": deepCache, "Runware Lora Search": loraSearch, "Runware Embedding Search": embeddingSearch, "Runware VAE Search": vaeSearch, @@ -88,6 +85,7 @@ NODE_CLASS_MAPPINGS = { "Runware Audio Sections": RunwareAudioSections, "Runware ElevenLabs Provider Settings": RunwareElevenLabsProviderSettings, "Runware ElevenLabs Provider Settings Sections": RunwareElevenLabsProviderSettingsSections, + "Runware Accelerator Options": acceleratorOptions, } NODE_DISPLAY_NAME_MAPPINGS = { diff --git a/modules/acceleratorOptions.py b/modules/acceleratorOptions.py new file mode 100644 index 0000000..dd19115 --- /dev/null +++ b/modules/acceleratorOptions.py @@ -0,0 +1,143 @@ +from .utils import runwareUtils as rwUtils + +class acceleratorOptions: + @classmethod + def INPUT_TYPES(cls): + return { + "required": {}, + "optional": { + # FBCache parameters + "fbcache": ("BOOLEAN", { + "tooltip": "Enable Frame Buffer Cache for faster generation", + "default": None, + }), + "cacheDistance": ("FLOAT", { + "tooltip": "Cache distance parameter for FBCache", + "default": None, + "min": 0.0, + "max": 1.0, + "step": 0.01, + }), + + # TeaCache parameters + "teaCache": ("BOOLEAN", { + "tooltip": "Enable TeaCache for transformer-based models (Flux, SD3). Does not work with UNet models like SDXL or SD1.5. Particularly effective for iterative editing workflows.", + "default": None, + }), + "teaCacheDistance": ("FLOAT", { + "tooltip": "Controls TeaCache aggressiveness: 0.0 (conservative/quality) to 1.0 (aggressive/speed). Lower values maintain quality, higher values prioritize speed.", + "default": None, + "min": 0.0, + "max": 1.0, + "step": 0.01, + }), + + # DeepCache parameters + "deepCache": ("BOOLEAN", { + "tooltip": "Enable DeepCache for UNet-based models (SDXL, SD1.5). Not applicable to transformer models. Provides performance improvements for high-throughput scenarios.", + "default": None, + }), + "deepCacheInterval": ("INT", { + "tooltip": "Frequency of feature caching - steps between cache operations. Larger values = faster but may impact quality. Smaller values = better quality but slower.", + "default": None, + "min": 1, + "max": 20, + }), + "deepCacheBranchId": ("INT", { + "tooltip": "Network branch for caching (0=shallowest, deeper=more conservative). Lower IDs = aggressive caching/faster, higher IDs = conservative caching/better quality.", + "default": None, + "min": 0, + "max": 10, + }), + + # Cache step control parameters + "cacheStartStep": ("INT", { + "tooltip": "Inference step number where caching begins (0 to total steps). Alternative to cacheStartStepPercentage.", + "default": None, + "min": 0, + "max": 200, + }), + "cacheStartStepPercentage": ("INT", { + "tooltip": "Percentage of total steps where caching begins (0-99). Alternative to cacheStartStep.", + "default": None, + "min": 0, + "max": 99, + }), + "cacheEndStep": ("INT", { + "tooltip": "Inference step number where caching stops (must be > cacheStartStep). Alternative to cacheEndStepPercentage.", + "default": None, + "min": 1, + "max": 200, + }), + "cacheEndStepPercentage": ("INT", { + "tooltip": "Percentage of total steps where caching stops (must be > cacheStartStepPercentage). Alternative to cacheEndStep.", + "default": None, + "min": 1, + "max": 100, + }), + "cacheMaxConsecutiveSteps": ("INT", { + "tooltip": "Max consecutive steps using cached computations before forcing fresh computation. Prevents quality degradation from extended cache reuse.", + "default": None, + "min": 1, + "max": 5, + }), + }, + } + + DESCRIPTION = "Configure Runware accelerator options for faster image generation. Supports TeaCache (transformer models like Flux/SD3) and DeepCache (UNet models like SDXL/SD1.5) with fine-grained control over caching parameters and step ranges. Note: These caching methods work best with deterministic schedulers (Euler, DDIM) rather than stochastic schedulers." + FUNCTION = "acceleratorOptions" + RETURN_TYPES = ("RUNWAREACCELERATOR",) + RETURN_NAMES = ("Runware Accelerator",) + CATEGORY = "Runware" + + def acceleratorOptions(self, **kwargs): + # Get all optional parameters + fbcache = kwargs.get("fbcache") + cacheDistance = kwargs.get("cacheDistance") + teaCache = kwargs.get("teaCache") + teaCacheDistance = kwargs.get("teaCacheDistance") + deepCache = kwargs.get("deepCache") + deepCacheInterval = kwargs.get("deepCacheInterval") + deepCacheBranchId = kwargs.get("deepCacheBranchId") + cacheStartStep = kwargs.get("cacheStartStep") + cacheStartStepPercentage = kwargs.get("cacheStartStepPercentage") + cacheEndStep = kwargs.get("cacheEndStep") + cacheEndStepPercentage = kwargs.get("cacheEndStepPercentage") + cacheMaxConsecutiveSteps = kwargs.get("cacheMaxConsecutiveSteps") + + # Build accelerator options dictionary + acceleratorOptions = {} + + # FBCache options + if fbcache is not None: + acceleratorOptions["fbcache"] = fbcache + if cacheDistance is not None: + acceleratorOptions["cacheDistance"] = cacheDistance + + # TeaCache options + if teaCache is not None: + acceleratorOptions["teaCache"] = teaCache + if teaCacheDistance is not None: + acceleratorOptions["teaCacheDistance"] = teaCacheDistance + + # DeepCache options + if deepCache is not None: + acceleratorOptions["deepCache"] = deepCache + if deepCacheInterval is not None: + acceleratorOptions["deepCacheInterval"] = deepCacheInterval + if deepCacheBranchId is not None: + acceleratorOptions["deepCacheBranchId"] = deepCacheBranchId + + # Cache step control options + if cacheStartStep is not None: + acceleratorOptions["cacheStartStep"] = cacheStartStep + if cacheStartStepPercentage is not None: + acceleratorOptions["cacheStartStepPercentage"] = cacheStartStepPercentage + if cacheEndStep is not None: + acceleratorOptions["cacheEndStep"] = cacheEndStep + if cacheEndStepPercentage is not None: + acceleratorOptions["cacheEndStepPercentage"] = cacheEndStepPercentage + if cacheMaxConsecutiveSteps is not None: + acceleratorOptions["cacheMaxConsecutiveSteps"] = cacheMaxConsecutiveSteps + + return (acceleratorOptions,) diff --git a/modules/deepCache.py b/modules/deepCache.py deleted file mode 100644 index a002548..0000000 --- a/modules/deepCache.py +++ /dev/null @@ -1,45 +0,0 @@ -class deepCache: - @classmethod - def INPUT_TYPES(cls): - return { - "required": { - "DeepCache Interval": ( - "INT", - { - "tooltip": "Represents the frequency of feature caching, specified as the number of steps between each cache operation.\n\nA larger interval value will make inference faster but may impact quality. A smaller interval prioritizes quality over speed.", - "default": 3, - "min": 1, - "max": 5, - "step": 1, - }, - ), - "DeepCache BranchId": ( - "INT", - { - "tooltip": "Determines which branch of the network (ordered from the shallowest to the deepest layer) is responsible for executing the caching processes.\n\nLower branch IDs (e.g., 0) result in more aggressive caching for faster generation, while higher branch IDs produce more conservative caching with potentially higher quality results.", - "default": 0, - "min": 0, - "max": 5, - "step": 1, - }, - ), - }, - } - - DESCRIPTION = "Can Be connected to Runware Inference to accelerate image generation by reusing past computations.\n\nDeepCache feature, which speeds up diffusion-based image generation by caching internal feature maps from the neural network.\n\nDeepCache can provide significant performance improvements for high-throughput scenarios or when generating multiple similar images." - FUNCTION = "deepCache" - RETURN_TYPES = ("RUNWAREACCELERATOR",) - RETURN_NAMES = ("Runware Accelerator",) - CATEGORY = "Runware" - - def deepCache(self, **kwargs): - deepCacheInterval = kwargs.get("DeepCache Interval") - deepCacheBranchId = kwargs.get("DeepCache BranchId") - - return ( - { - "deepCache": True, - # "deepCacheInterval": deepCacheInterval, - "deepCacheBranchId": deepCacheBranchId, - }, - ) diff --git a/modules/imageInference.py b/modules/imageInference.py index 676da1a..bb88a12 100644 --- a/modules/imageInference.py +++ b/modules/imageInference.py @@ -129,7 +129,7 @@ class txt2img: }, "optional": { "Accelerator": ("RUNWAREACCELERATOR", { - "tooltip": "Connect a Runware Accelerator Node (TeaCache, DeepCache) to speed up the image generation process.", + "tooltip": "Connect a Runware Accelerator Options Node to configure caching and acceleration settings.", }), "Lora": ("RUNWARELORA", { "tooltip": "Connect a Runware Lora From Lora Search Node Or Lora Combine For Multiple Lora's Together.", @@ -260,7 +260,7 @@ class txt2img: genConfig[0]["promptWeighting"] = "sdEmbeds" else: genConfig[0]["promptWeighting"] = "compel" - if(runwareAccelerator is not None): + if (runwareAccelerator is not None): genConfig[0]["acceleratorOptions"] = runwareAccelerator if (runwareLora is not None): if (isinstance(runwareLora, list)): diff --git a/modules/teaCache.py b/modules/teaCache.py deleted file mode 100644 index c8b6185..0000000 --- a/modules/teaCache.py +++ /dev/null @@ -1,33 +0,0 @@ -class teaCache: - @classmethod - def INPUT_TYPES(cls): - return { - "required": { - "TeaCache Distance": ( - "FLOAT", - { - "tooltip": "Controls the aggressiveness of the TeaCache feature.\n\nValues range from 0.0 (most conservative) to 1.0 (most aggressive).\n\nLower values prioritize quality by being more selective about which computations to reuse, while higher values prioritize speed by reusing more computations.", - "default": 0.5, - "min": 0.0, - "max": 1.0, - "step": 0.1, - }, - ), - }, - } - - DESCRIPTION = "Can Be connected to Runware Inference to accelerate image generation by reusing past computations.\n\nTeaCache is specifically designed for transformer-based models such as Flux and SD3, and does not work with UNet models like SDXL or SD1.5." - FUNCTION = "teaCache" - RETURN_TYPES = ("RUNWAREACCELERATOR",) - RETURN_NAMES = ("Runware Accelerator",) - CATEGORY = "Runware" - - def teaCache(self, **kwargs): - teaCacheDistance = kwargs.get("TeaCache Distance") - - return ( - { - "teaCache": True, - "teaCacheDistance": round(teaCacheDistance, 2), - }, - )