├── example.png ├── workflow.zip ├── __init__.py ├── pyproject.toml ├── .github └── workflows │ └── publish.yml ├── README.md ├── .gitignore ├── workflow.json ├── LICENSE └── nodes.py /example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrzjason/ComfyUI-LoaderUtils/HEAD/example.png -------------------------------------------------------------------------------- /workflow.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lrzjason/ComfyUI-LoaderUtils/HEAD/workflow.zip -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS 2 | 3 | __all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS'] -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "loaderutils" 3 | description = "" 4 | version = "1.0.4" 5 | license = {file = "LICENSE"} 6 | 7 | [project.urls] 8 | Repository = "https://github.com/lrzjason/ComfyUI-LoaderUtils" 9 | # Used by Comfy Registry https://comfyregistry.org 10 | 11 | [tool.comfy] 12 | PublisherId = "lrzjason" 13 | DisplayName = "ComfyUI-LoaderUtils" 14 | Icon = "" 15 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish to Comfy registry 2 | on: 3 | workflow_dispatch: 4 | push: 5 | branches: 6 | - main 7 | - master 8 | paths: 9 | - "pyproject.toml" 10 | 11 | jobs: 12 | publish-node: 13 | name: Publish Custom Node to registry 14 | runs-on: ubuntu-latest 15 | # if this is a forked repository. Skipping the workflow. 16 | if: github.event.repository.fork == false 17 | steps: 18 | - name: Check out code 19 | uses: actions/checkout@v4 20 | - name: Publish Custom Node 21 | uses: Comfy-Org/publish-node-action@main 22 | with: 23 | ## Add your own personal access token to your Github Repository secrets and reference it here. 24 | personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }} 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ComfyUI Loader Utils - Adjust Model Loading Order 2 | 3 | ## The Problem: Comfyui load models at the start at once 4 | 5 | Solution: Added an optional "Any" Parameter to loader node 6 | 7 | This custom loader module addresses these issues by: 8 | 9 | 1. **Flexible Node Connections**: Added an optional "any" parameter to all loader nodes, allowing them to connect to any output type 10 | 2. **Controlled Loading Order**: Users can strategically place loader nodes after other nodes, optimizing the model loading sequence 11 | 3. **Memory Management**: Enables better VRAM management by controlling when and which models are loaded 12 | 4. **Sequential Loading**: Models are loaded only when needed, in a controlled sequence 13 | 14 | ## Features 15 | 16 | - All standard ComfyUI loader nodes included with "_Any" suffix 17 | - Optional "any" parameter for flexible connections 18 | - Maintains all original functionality and parameters 19 | - Compatible with existing ComfyUI workflows 20 | 21 | ## Available Loader Nodes 22 | 23 | - `CheckpointLoader_Any` - Advanced checkpoint loading 24 | - `CheckpointLoaderSimple_Any` - Simple checkpoint loading 25 | - `DiffusersLoader_Any` - Diffusers model loading 26 | - `unCLIPCheckpointLoader_Any` - unCLIP checkpoint loading 27 | - `LoraLoader_Any` - LoRA model loading 28 | - `LoraLoaderModelOnly_Any` - LoRA model only loading 29 | - `VAELoader_Any` - VAE model loading 30 | - `ControlNetLoader_Any` - ControlNet model loading 31 | - `DiffControlNetLoader_Any` - Diffusion ControlNet loading 32 | - `UNETLoader_Any` - UNET model loading 33 | - `CLIPLoader_Any` - CLIP model loading 34 | - `DualCLIPLoader_Any` - Dual CLIP model loading 35 | - `CLIPVisionLoader_Any` - CLIP vision model loading 36 | - `StyleModelLoader_Any` - Style model loading 37 | - `GLIGENLoader_Any` - GLIGEN model loading 38 | 39 | ## Benefits for Low VRAM Users 40 | 41 | - **Reduced Memory Footprint**: Load models only when needed 42 | - **Flexible Sequencing**: Arrange loading order based on available memory 43 | - **Improved Workflow Stability**: More predictable memory usage 44 | 45 | ## Usage 46 | 47 | The "_Any" suffix nodes can be used exactly like their original counterparts, with the added benefit that they can accept connections from any node type via the optional "any" parameter. This enables better workflow design for memory-constrained environments. 48 | 49 | ## Example 50 | 51 | Here's an example workflow showing how the loader nodes with "any" parameter can be used to optimize memory management: 52 | 53 | ![Example Workflow](example.png) 54 | 55 | The workflow file is also available as `workflow.json` in this repository. 56 | 57 | ## Memory Management Benefits 58 | 59 | The key advantage of these loader nodes is that you can control WHEN models are loaded by connecting them strategically in your workflow. In the example above: 60 | 61 | 1. The UNETLoader_Any is connected after the CLIPTextEncode nodes, allowing them to run before the heavy UNET model is loaded 62 | 2. The VAELoader_Any is connected after sampling, allowing you to load the VAE only when needed for decoding 63 | 64 | Simply use these nodes in place of the standard loader nodes, and strategically connect them to control when models are loaded into memory. 65 | 66 | ## Contact 67 | - **Twitter**: [@Lrzjason](https://twitter.com/Lrzjason) 68 | - **Email**: lrzjason@gmail.com 69 | - **QQ Group**: 866612947 70 | - **Wechatid**: fkdeai 71 | - **Civitai**: [xiaozhijason](https://civitai.com/user/xiaozhijason) 72 | 73 | ## Sponsors me for more open source projects: 74 |
75 | 76 | 77 | 81 | 85 | 86 |
78 |

Buy me a coffee:

79 | Buy Me a Coffee QR 80 |
82 |

WeChat:

83 | WeChat QR 84 |
87 |
88 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[codz] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py.cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # UV 98 | # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | #uv.lock 102 | 103 | # poetry 104 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 105 | # This is especially recommended for binary packages to ensure reproducibility, and is more 106 | # commonly ignored for libraries. 107 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 108 | #poetry.lock 109 | #poetry.toml 110 | 111 | # pdm 112 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 113 | # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python. 114 | # https://pdm-project.org/en/latest/usage/project/#working-with-version-control 115 | #pdm.lock 116 | #pdm.toml 117 | .pdm-python 118 | .pdm-build/ 119 | 120 | # pixi 121 | # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control. 122 | #pixi.lock 123 | # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one 124 | # in the .venv directory. It is recommended not to include this directory in version control. 125 | .pixi 126 | 127 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 128 | __pypackages__/ 129 | 130 | # Celery stuff 131 | celerybeat-schedule 132 | celerybeat.pid 133 | 134 | # SageMath parsed files 135 | *.sage.py 136 | 137 | # Environments 138 | .env 139 | .envrc 140 | .venv 141 | env/ 142 | venv/ 143 | ENV/ 144 | env.bak/ 145 | venv.bak/ 146 | 147 | # Spyder project settings 148 | .spyderproject 149 | .spyproject 150 | 151 | # Rope project settings 152 | .ropeproject 153 | 154 | # mkdocs documentation 155 | /site 156 | 157 | # mypy 158 | .mypy_cache/ 159 | .dmypy.json 160 | dmypy.json 161 | 162 | # Pyre type checker 163 | .pyre/ 164 | 165 | # pytype static type analyzer 166 | .pytype/ 167 | 168 | # Cython debug symbols 169 | cython_debug/ 170 | 171 | # PyCharm 172 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 173 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 174 | # and can be added to the global gitignore or merged into this file. For a more nuclear 175 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 176 | #.idea/ 177 | 178 | # Abstra 179 | # Abstra is an AI-powered process automation framework. 180 | # Ignore directories containing user credentials, local state, and settings. 181 | # Learn more at https://abstra.io/docs 182 | .abstra/ 183 | 184 | # Visual Studio Code 185 | # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore 186 | # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore 187 | # and can be added to the global gitignore or merged into this file. However, if you prefer, 188 | # you could uncomment the following to ignore the entire vscode folder 189 | # .vscode/ 190 | 191 | # Ruff stuff: 192 | .ruff_cache/ 193 | 194 | # PyPI configuration file 195 | .pypirc 196 | 197 | # Cursor 198 | # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to 199 | # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data 200 | # refer to https://docs.cursor.com/context/ignore-files 201 | .cursorignore 202 | .cursorindexingignore 203 | 204 | # Marimo 205 | marimo/_static/ 206 | marimo/_lsp/ 207 | __marimo__/ 208 | -------------------------------------------------------------------------------- /workflow.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "92112d97-bb64-4b44-86f2-ea5691ef8f6e", 3 | "revision": 0, 4 | "last_node_id": 31, 5 | "last_link_id": 59, 6 | "nodes": [ 7 | { 8 | "id": 13, 9 | "type": "EmptySD3LatentImage", 10 | "pos": [ 11 | 530, 12 | 620 13 | ], 14 | "size": [ 15 | 315, 16 | 106 17 | ], 18 | "flags": {}, 19 | "order": 0, 20 | "mode": 0, 21 | "inputs": [], 22 | "outputs": [ 23 | { 24 | "name": "LATENT", 25 | "type": "LATENT", 26 | "slot_index": 0, 27 | "links": [ 28 | 17 29 | ] 30 | } 31 | ], 32 | "properties": { 33 | "Node name for S&R": "EmptySD3LatentImage" 34 | }, 35 | "widgets_values": [ 36 | 1024, 37 | 1024, 38 | 1 39 | ] 40 | }, 41 | { 42 | "id": 7, 43 | "type": "CLIPTextEncode", 44 | "pos": [ 45 | 420, 46 | 400 47 | ], 48 | "size": [ 49 | 425.27801513671875, 50 | 180.6060791015625 51 | ], 52 | "flags": {}, 53 | "order": 3, 54 | "mode": 0, 55 | "inputs": [ 56 | { 57 | "name": "clip", 58 | "type": "CLIP", 59 | "link": 44 60 | } 61 | ], 62 | "outputs": [ 63 | { 64 | "name": "CONDITIONING", 65 | "type": "CONDITIONING", 66 | "slot_index": 0, 67 | "links": [ 68 | 6 69 | ] 70 | } 71 | ], 72 | "title": "CLIP Text Encode (Negative Prompt)", 73 | "properties": { 74 | "Node name for S&R": "CLIPTextEncode" 75 | }, 76 | "widgets_values": [ 77 | "blurry ugly bad" 78 | ], 79 | "color": "#322", 80 | "bgcolor": "#533" 81 | }, 82 | { 83 | "id": 8, 84 | "type": "VAEDecode", 85 | "pos": [ 86 | 1826.5691087769542, 87 | 192.4670427207268 88 | ], 89 | "size": [ 90 | 210, 91 | 46 92 | ], 93 | "flags": {}, 94 | "order": 7, 95 | "mode": 0, 96 | "inputs": [ 97 | { 98 | "name": "samples", 99 | "type": "LATENT", 100 | "link": 51 101 | }, 102 | { 103 | "name": "vae", 104 | "type": "VAE", 105 | "link": 56 106 | } 107 | ], 108 | "outputs": [ 109 | { 110 | "name": "IMAGE", 111 | "type": "IMAGE", 112 | "slot_index": 0, 113 | "links": [ 114 | 57 115 | ] 116 | } 117 | ], 118 | "properties": { 119 | "Node name for S&R": "VAEDecode" 120 | }, 121 | "widgets_values": [] 122 | }, 123 | { 124 | "id": 6, 125 | "type": "CLIPTextEncode", 126 | "pos": [ 127 | 420, 128 | 190 129 | ], 130 | "size": [ 131 | 423.83001708984375, 132 | 177.11770629882812 133 | ], 134 | "flags": {}, 135 | "order": 2, 136 | "mode": 0, 137 | "inputs": [ 138 | { 139 | "name": "clip", 140 | "type": "CLIP", 141 | "link": 43 142 | } 143 | ], 144 | "outputs": [ 145 | { 146 | "name": "CONDITIONING", 147 | "type": "CONDITIONING", 148 | "slot_index": 0, 149 | "links": [ 150 | 4, 151 | 58 152 | ] 153 | } 154 | ], 155 | "title": "CLIP Text Encode (Positive Prompt)", 156 | "properties": { 157 | "Node name for S&R": "CLIPTextEncode" 158 | }, 159 | "widgets_values": [ 160 | "cute anime style girl with massive fluffy fennec ears and a big fluffy tail blonde messy long hair blue eyes wearing a maid outfit with a long black gold leaf pattern dress and a white apron, it is a postcard held by a hand in front of a beautiful realistic city at sunset and there is cursive writing that says \"ZImage, Now in ComfyUI\"" 161 | ], 162 | "color": "#232", 163 | "bgcolor": "#353" 164 | }, 165 | { 166 | "id": 31, 167 | "type": "UNETLoader_Any", 168 | "pos": [ 169 | 870.373060989916, 170 | 44.22078072939189 171 | ], 172 | "size": [ 173 | 270, 174 | 82 175 | ], 176 | "flags": {}, 177 | "order": 4, 178 | "mode": 0, 179 | "inputs": [ 180 | { 181 | "name": "any", 182 | "shape": 7, 183 | "type": "*", 184 | "link": 58 185 | } 186 | ], 187 | "outputs": [ 188 | { 189 | "name": "MODEL", 190 | "type": "MODEL", 191 | "links": [ 192 | 59 193 | ] 194 | } 195 | ], 196 | "properties": { 197 | "Node name for S&R": "UNETLoader_Any" 198 | }, 199 | "widgets_values": [ 200 | "z_image_turbo_bf16.safetensors", 201 | "default" 202 | ] 203 | }, 204 | { 205 | "id": 18, 206 | "type": "CLIPLoader", 207 | "pos": [ 208 | 71.06591455854638, 209 | 187.51018103026595 210 | ], 211 | "size": [ 212 | 270, 213 | 106 214 | ], 215 | "flags": {}, 216 | "order": 1, 217 | "mode": 0, 218 | "inputs": [], 219 | "outputs": [ 220 | { 221 | "name": "CLIP", 222 | "type": "CLIP", 223 | "links": [ 224 | 43, 225 | 44 226 | ] 227 | } 228 | ], 229 | "properties": { 230 | "Node name for S&R": "CLIPLoader" 231 | }, 232 | "widgets_values": [ 233 | "qwen_3_4b.safetensors", 234 | "lumina2", 235 | "default" 236 | ] 237 | }, 238 | { 239 | "id": 3, 240 | "type": "KSampler", 241 | "pos": [ 242 | 1173.4596288445618, 243 | 191.58377677523364 244 | ], 245 | "size": [ 246 | 315, 247 | 474 248 | ], 249 | "flags": {}, 250 | "order": 5, 251 | "mode": 0, 252 | "inputs": [ 253 | { 254 | "name": "model", 255 | "type": "MODEL", 256 | "link": 59 257 | }, 258 | { 259 | "name": "positive", 260 | "type": "CONDITIONING", 261 | "link": 4 262 | }, 263 | { 264 | "name": "negative", 265 | "type": "CONDITIONING", 266 | "link": 6 267 | }, 268 | { 269 | "name": "latent_image", 270 | "type": "LATENT", 271 | "link": 17 272 | } 273 | ], 274 | "outputs": [ 275 | { 276 | "name": "LATENT", 277 | "type": "LATENT", 278 | "slot_index": 0, 279 | "links": [ 280 | 51, 281 | 55 282 | ] 283 | } 284 | ], 285 | "properties": { 286 | "Node name for S&R": "KSampler" 287 | }, 288 | "widgets_values": [ 289 | 804224263771352, 290 | "fixed", 291 | 9, 292 | 1, 293 | "euler", 294 | "simple", 295 | 1 296 | ] 297 | }, 298 | { 299 | "id": 29, 300 | "type": "VAELoader_Any", 301 | "pos": [ 302 | 1523.6789375434823, 303 | 297.7258811414354 304 | ], 305 | "size": [ 306 | 270, 307 | 58 308 | ], 309 | "flags": {}, 310 | "order": 6, 311 | "mode": 0, 312 | "inputs": [ 313 | { 314 | "name": "any", 315 | "shape": 7, 316 | "type": "*", 317 | "link": 55 318 | } 319 | ], 320 | "outputs": [ 321 | { 322 | "name": "VAE", 323 | "type": "VAE", 324 | "links": [ 325 | 56 326 | ] 327 | } 328 | ], 329 | "properties": { 330 | "Node name for S&R": "VAELoader_Any" 331 | }, 332 | "widgets_values": [ 333 | "ae.safetensors" 334 | ] 335 | }, 336 | { 337 | "id": 30, 338 | "type": "PreviewImage", 339 | "pos": [ 340 | 2063.0748519590647, 341 | 197.21731342238334 342 | ], 343 | "size": [ 344 | 366.7024979539101, 345 | 459.3014762944291 346 | ], 347 | "flags": {}, 348 | "order": 8, 349 | "mode": 0, 350 | "inputs": [ 351 | { 352 | "name": "images", 353 | "type": "IMAGE", 354 | "link": 57 355 | } 356 | ], 357 | "outputs": [], 358 | "properties": { 359 | "Node name for S&R": "PreviewImage" 360 | }, 361 | "widgets_values": [] 362 | } 363 | ], 364 | "links": [ 365 | [ 366 | 4, 367 | 6, 368 | 0, 369 | 3, 370 | 1, 371 | "CONDITIONING" 372 | ], 373 | [ 374 | 6, 375 | 7, 376 | 0, 377 | 3, 378 | 2, 379 | "CONDITIONING" 380 | ], 381 | [ 382 | 17, 383 | 13, 384 | 0, 385 | 3, 386 | 3, 387 | "LATENT" 388 | ], 389 | [ 390 | 43, 391 | 18, 392 | 0, 393 | 6, 394 | 0, 395 | "CLIP" 396 | ], 397 | [ 398 | 44, 399 | 18, 400 | 0, 401 | 7, 402 | 0, 403 | "CLIP" 404 | ], 405 | [ 406 | 51, 407 | 3, 408 | 0, 409 | 8, 410 | 0, 411 | "LATENT" 412 | ], 413 | [ 414 | 55, 415 | 3, 416 | 0, 417 | 29, 418 | 0, 419 | "*" 420 | ], 421 | [ 422 | 56, 423 | 29, 424 | 0, 425 | 8, 426 | 1, 427 | "VAE" 428 | ], 429 | [ 430 | 57, 431 | 8, 432 | 0, 433 | 30, 434 | 0, 435 | "IMAGE" 436 | ], 437 | [ 438 | 58, 439 | 6, 440 | 0, 441 | 31, 442 | 0, 443 | "*" 444 | ], 445 | [ 446 | 59, 447 | 31, 448 | 0, 449 | 3, 450 | 0, 451 | "MODEL" 452 | ] 453 | ], 454 | "groups": [], 455 | "config": {}, 456 | "extra": { 457 | "ds": { 458 | "scale": 0.5730855330116982, 459 | "offset": [ 460 | 297.7596222557897, 461 | 269.5194773903112 462 | ] 463 | }, 464 | "frontendVersion": "1.33.10" 465 | }, 466 | "version": 0.4 467 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /nodes.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | import torch 3 | 4 | 5 | import os 6 | import sys 7 | import json 8 | import hashlib 9 | import inspect 10 | import traceback 11 | import math 12 | import time 13 | import random 14 | import logging 15 | 16 | from PIL import Image, ImageOps, ImageSequence 17 | from PIL.PngImagePlugin import PngInfo 18 | 19 | import numpy as np 20 | import safetensors.torch 21 | 22 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy")) 23 | 24 | import comfy.sd 25 | import comfy.utils 26 | import comfy.controlnet 27 | 28 | import comfy.clip_vision 29 | 30 | import comfy.model_management 31 | 32 | import folder_paths 33 | from comfy.comfy_types.node_typing import IO 34 | 35 | def before_node_execution(): 36 | comfy.model_management.throw_exception_if_processing_interrupted() 37 | 38 | def interrupt_processing(value=True): 39 | comfy.model_management.interrupt_current_processing(value) 40 | 41 | MAX_RESOLUTION=16384 42 | 43 | 44 | class CheckpointLoader_Any: 45 | @classmethod 46 | def INPUT_TYPES(s): 47 | return {"required": { "config_name": (folder_paths.get_filename_list("configs"), ), 48 | "ckpt_name": (folder_paths.get_filename_list("checkpoints"), )}, 49 | "optional": {"any": (IO.ANY, {})}} 50 | RETURN_TYPES = ("MODEL", "CLIP", "VAE") 51 | FUNCTION = "load_checkpoint" 52 | 53 | CATEGORY = "advanced/loaders" 54 | DEPRECATED = True 55 | 56 | def load_checkpoint(self, config_name, ckpt_name, any=None): 57 | config_path = folder_paths.get_full_path("configs", config_name) 58 | ckpt_path = folder_paths.get_full_path_or_raise("checkpoints", ckpt_name) 59 | return comfy.sd.load_checkpoint(config_path, ckpt_path, output_vae=True, output_clip=True, embedding_directory=folder_paths.get_folder_paths("embeddings")) 60 | 61 | 62 | class CheckpointLoaderSimple_Any: 63 | @classmethod 64 | def INPUT_TYPES(s): 65 | return { 66 | "required": { 67 | "ckpt_name": (folder_paths.get_filename_list("checkpoints"), {"tooltip": "The name of the checkpoint (model) to load."}), 68 | }, 69 | "optional": {"any": (IO.ANY, {})} 70 | } 71 | RETURN_TYPES = ("MODEL", "CLIP", "VAE") 72 | OUTPUT_TOOLTIPS = ("The model used for denoising latents.", 73 | "The CLIP model used for encoding text prompts.", 74 | "The VAE model used for encoding and decoding images to and from latent space.") 75 | FUNCTION = "load_checkpoint" 76 | 77 | CATEGORY = "loaders" 78 | DESCRIPTION = "Loads a diffusion model checkpoint, diffusion models are used to denoise latents." 79 | 80 | def load_checkpoint(self, ckpt_name, any=None): 81 | ckpt_path = folder_paths.get_full_path_or_raise("checkpoints", ckpt_name) 82 | out = comfy.sd.load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, embedding_directory=folder_paths.get_folder_paths("embeddings")) 83 | return out[:3] 84 | 85 | 86 | class unCLIPCheckpointLoader_Any: 87 | @classmethod 88 | def INPUT_TYPES(s): 89 | return {"required": { "ckpt_name": (folder_paths.get_filename_list("checkpoints"), ), 90 | }, 91 | "optional": {"any": (IO.ANY, {})}} 92 | RETURN_TYPES = ("MODEL", "CLIP", "VAE", "CLIP_VISION") 93 | FUNCTION = "load_checkpoint" 94 | 95 | CATEGORY = "loaders" 96 | 97 | def load_checkpoint(self, ckpt_name, any=None, output_vae=True, output_clip=True): 98 | ckpt_path = folder_paths.get_full_path_or_raise("checkpoints", ckpt_name) 99 | out = comfy.sd.load_checkpoint_guess_config(ckpt_path, output_vae=True, output_clip=True, output_clipvision=True, embedding_directory=folder_paths.get_folder_paths("embeddings")) 100 | return out 101 | 102 | 103 | class LoraLoader_Any: 104 | def __init__(self): 105 | self.loaded_lora = None 106 | 107 | @classmethod 108 | def INPUT_TYPES(s): 109 | return { 110 | "required": { 111 | "model": ("MODEL", {"tooltip": "The diffusion model the LoRA will be applied to."}), 112 | "clip": ("CLIP", {"tooltip": "The CLIP model the LoRA will be applied to."}), 113 | "lora_name": (folder_paths.get_filename_list("loras"), {"tooltip": "The name of the LoRA."}), 114 | "strength_model": ("FLOAT", {"default": 1.0, "min": -100.0, "max": 100.0, "step": 0.01, "tooltip": "How strongly to modify the diffusion model. This value can be negative."}), 115 | "strength_clip": ("FLOAT", {"default": 1.0, "min": -100.0, "max": 100.0, "step": 0.01, "tooltip": "How strongly to modify the CLIP model. This value can be negative."}), 116 | }, 117 | "optional": {"any": (IO.ANY, {})} 118 | } 119 | 120 | RETURN_TYPES = ("MODEL", "CLIP") 121 | OUTPUT_TOOLTIPS = ("The modified diffusion model.", "The modified CLIP model.") 122 | FUNCTION = "load_lora" 123 | 124 | CATEGORY = "loaders" 125 | DESCRIPTION = "LoRAs are used to modify diffusion and CLIP models, altering the way in which latents are denoised such as applying styles. Multiple LoRA nodes can be linked together." 126 | 127 | def load_lora(self, model, clip, lora_name, strength_model, strength_clip, any=None): 128 | if strength_model == 0 and strength_clip == 0: 129 | return (model, clip) 130 | 131 | lora_path = folder_paths.get_full_path_or_raise("loras", lora_name) 132 | lora = None 133 | if self.loaded_lora is not None: 134 | if self.loaded_lora[0] == lora_path: 135 | lora = self.loaded_lora[1] 136 | else: 137 | self.loaded_lora = None 138 | 139 | if lora is None: 140 | lora = comfy.utils.load_torch_file(lora_path, safe_load=True) 141 | self.loaded_lora = (lora_path, lora) 142 | 143 | new_model, new_clip = comfy.sd.load_lora_for_models(model, clip, lora, strength_model, strength_clip) 144 | return (new_model, new_clip) 145 | 146 | 147 | class LoraLoaderModelOnly_Any(LoraLoader_Any): 148 | @classmethod 149 | def INPUT_TYPES(s): 150 | return { 151 | "required": { 152 | "model": ("MODEL",), 153 | "lora_name": (folder_paths.get_filename_list("loras"), ), 154 | "strength_model": ("FLOAT", {"default": 1.0, "min": -100.0, "max": 100.0, "step": 0.01}), 155 | }, 156 | "optional": {"any": (IO.ANY, {})} 157 | } 158 | 159 | RETURN_TYPES = ("MODEL",) 160 | FUNCTION = "load_lora_model_only" 161 | 162 | def load_lora_model_only(self, model, lora_name, strength_model, any=None): 163 | return (self.load_lora(model, None, lora_name, strength_model, 0, any)[0],) 164 | 165 | 166 | class VAELoader_Any: 167 | video_taes = ["taehv", "lighttaew2_2", "lighttaew2_1", "lighttaehy1_5"] 168 | image_taes = ["taesd", "taesdxl", "taesd3", "taef1"] 169 | @staticmethod 170 | def vae_list(s): 171 | vaes = folder_paths.get_filename_list("vae") 172 | approx_vaes = folder_paths.get_filename_list("vae_approx") 173 | sdxl_taesd_enc = False 174 | sdxl_taesd_dec = False 175 | sd1_taesd_enc = False 176 | sd1_taesd_dec = False 177 | sd3_taesd_enc = False 178 | sd3_taesd_dec = False 179 | f1_taesd_enc = False 180 | f1_taesd_dec = False 181 | 182 | for v in approx_vaes: 183 | if v.startswith("taesd_decoder."): 184 | sd1_taesd_dec = True 185 | elif v.startswith("taesd_encoder."): 186 | sd1_taesd_enc = True 187 | elif v.startswith("taesdxl_decoder."): 188 | sdxl_taesd_dec = True 189 | elif v.startswith("taesdxl_encoder."): 190 | sdxl_taesd_enc = True 191 | elif v.startswith("taesd3_decoder."): 192 | sd3_taesd_dec = True 193 | elif v.startswith("taesd3_encoder."): 194 | sd3_taesd_enc = True 195 | elif v.startswith("taef1_encoder."): 196 | f1_taesd_dec = True 197 | elif v.startswith("taef1_decoder."): 198 | f1_taesd_enc = True 199 | else: 200 | for tae in s.video_taes: 201 | if v.startswith(tae): 202 | vaes.append(v) 203 | 204 | if sd1_taesd_dec and sd1_taesd_enc: 205 | vaes.append("taesd") 206 | if sdxl_taesd_dec and sdxl_taesd_enc: 207 | vaes.append("taesdxl") 208 | if sd3_taesd_dec and sd3_taesd_enc: 209 | vaes.append("taesd3") 210 | if f1_taesd_dec and f1_taesd_enc: 211 | vaes.append("taef1") 212 | vaes.append("pixel_space") 213 | return vaes 214 | 215 | @staticmethod 216 | def load_taesd(name): 217 | sd = {} 218 | approx_vaes = folder_paths.get_filename_list("vae_approx") 219 | 220 | encoder = next(filter(lambda a: a.startswith("{}_encoder.".format(name)), approx_vaes)) 221 | decoder = next(filter(lambda a: a.startswith("{}_decoder.".format(name)), approx_vaes)) 222 | 223 | enc = comfy.utils.load_torch_file(folder_paths.get_full_path_or_raise("vae_approx", encoder)) 224 | for k in enc: 225 | sd["taesd_encoder.{}".format(k)] = enc[k] 226 | 227 | dec = comfy.utils.load_torch_file(folder_paths.get_full_path_or_raise("vae_approx", decoder)) 228 | for k in dec: 229 | sd["taesd_decoder.{}".format(k)] = dec[k] 230 | 231 | if name == "taesd": 232 | sd["vae_scale"] = torch.tensor(0.18215) 233 | sd["vae_shift"] = torch.tensor(0.0) 234 | elif name == "taesdxl": 235 | sd["vae_scale"] = torch.tensor(0.13025) 236 | sd["vae_shift"] = torch.tensor(0.0) 237 | elif name == "taesd3": 238 | sd["vae_scale"] = torch.tensor(1.5305) 239 | sd["vae_shift"] = torch.tensor(0.0609) 240 | elif name == "taef1": 241 | sd["vae_scale"] = torch.tensor(0.3611) 242 | sd["vae_shift"] = torch.tensor(0.1159) 243 | return sd 244 | 245 | @classmethod 246 | def INPUT_TYPES(s): 247 | return {"required": { "vae_name": (s.vae_list(s), )}, "optional": {"any": (IO.ANY, {})}} 248 | RETURN_TYPES = ("VAE",) 249 | FUNCTION = "load_vae" 250 | 251 | CATEGORY = "loaders" 252 | 253 | #TODO: scale factor? 254 | def load_vae(self, vae_name, any=None): 255 | if vae_name == "pixel_space": 256 | sd = {} 257 | sd["pixel_space_vae"] = torch.tensor(1.0) 258 | elif vae_name in self.image_taes: 259 | sd = self.load_taesd(vae_name) 260 | else: 261 | if os.path.splitext(vae_name)[0] in self.video_taes: 262 | vae_path = folder_paths.get_full_path_or_raise("vae_approx", vae_name) 263 | else: 264 | vae_path = folder_paths.get_full_path_or_raise("vae", vae_name) 265 | sd = comfy.utils.load_torch_file(vae_path) 266 | vae = comfy.sd.VAE(sd=sd) 267 | vae.throw_exception_if_invalid() 268 | return (vae,) 269 | 270 | 271 | class ControlNetLoader_Any: 272 | @classmethod 273 | def INPUT_TYPES(s): 274 | return {"required": { "control_net_name": (folder_paths.get_filename_list("controlnet"), )}, "optional": {"any": (IO.ANY, {})}} 275 | 276 | RETURN_TYPES = ("CONTROL_NET",) 277 | FUNCTION = "load_controlnet" 278 | 279 | CATEGORY = "loaders" 280 | 281 | def load_controlnet(self, control_net_name, any=None): 282 | controlnet_path = folder_paths.get_full_path_or_raise("controlnet", control_net_name) 283 | controlnet = comfy.controlnet.load_controlnet(controlnet_path) 284 | if controlnet is None: 285 | raise RuntimeError("ERROR: controlnet file is invalid and does not contain a valid controlnet model.") 286 | return (controlnet,) 287 | 288 | 289 | class DiffControlNetLoader_Any: 290 | @classmethod 291 | def INPUT_TYPES(s): 292 | return {"required": { "model": ("MODEL",), 293 | "control_net_name": (folder_paths.get_filename_list("controlnet"), )}, 294 | "optional": {"any": (IO.ANY, {})}} 295 | 296 | RETURN_TYPES = ("CONTROL_NET",) 297 | FUNCTION = "load_controlnet" 298 | 299 | CATEGORY = "loaders" 300 | 301 | def load_controlnet(self, model, control_net_name, any=None): 302 | controlnet_path = folder_paths.get_full_path_or_raise("controlnet", control_net_name) 303 | controlnet = comfy.controlnet.load_controlnet(controlnet_path, model) 304 | return (controlnet,) 305 | 306 | class UNETLoader_Any: 307 | @classmethod 308 | def INPUT_TYPES(s): 309 | return {"required": { "unet_name": (folder_paths.get_filename_list("unet"), ), 310 | "weight_dtype": (["default", "fp8_e4m3fn", "fp8_e4m3fn_fast", "fp8_e5m2"],) 311 | }, 312 | "optional": {"any": (IO.ANY, {})} 313 | } 314 | RETURN_TYPES = ("MODEL",) 315 | FUNCTION = "load_unet" 316 | 317 | CATEGORY = "advanced/loaders" 318 | 319 | def load_unet(self, unet_name, weight_dtype, any=None): 320 | model_options = {} 321 | if weight_dtype == "fp8_e4m3fn": 322 | model_options["dtype"] = torch.float8_e4m3fn 323 | elif weight_dtype == "fp8_e4m3fn_fast": 324 | model_options["dtype"] = torch.float8_e4m3fn 325 | model_options["fp8_optimizations"] = True 326 | elif weight_dtype == "fp8_e5m2": 327 | model_options["dtype"] = torch.float8_e5m2 328 | 329 | unet_path = folder_paths.get_full_path_or_raise("diffusion_models", unet_name) 330 | model = comfy.sd.load_diffusion_model(unet_path, model_options=model_options) 331 | return (model,) 332 | 333 | class CLIPLoader_Any: 334 | @classmethod 335 | def INPUT_TYPES(s): 336 | return {"required": { "clip_name": (folder_paths.get_filename_list("text_encoders"), ), 337 | "type": (["stable_diffusion", "stable_cascade", "sd3", "stable_audio", "mochi", "cosmos", "lumina2", "wan", "hidream", "omnigen2"], ), 338 | }, 339 | "optional": { 340 | "device": (["default", "cpu"], {"advanced": True}), 341 | "any": (IO.ANY, {}) 342 | }} 343 | RETURN_TYPES = ("CLIP",) 344 | FUNCTION = "load_clip" 345 | 346 | CATEGORY = "advanced/loaders" 347 | 348 | DESCRIPTION = "[Recipes]\n\nstable_diffusion: clip-l\nstable_cascade: clip-g\nsd3: t5 xxl/ clip-g / clip-l\nstable_audio: t5 base\nmochi: t5 xxl\ncosmos: old t5 xxl\nlumina2: gemma 2 2B\nwan: umt5 xxl\n hidream: llama-3.1 (Recommend) or t5\nomnigen2: qwen vl 2.5 3B" 349 | 350 | def load_clip(self, clip_name, type, any=None, device="default"): 351 | clip_type = getattr(comfy.sd.CLIPType, type.upper(), comfy.sd.CLIPType.STABLE_DIFFUSION) 352 | 353 | model_options = {} 354 | if device == "cpu": 355 | model_options["load_device"] = model_options["offload_device"] = torch.device("cpu") 356 | 357 | clip_path = folder_paths.get_full_path_or_raise("text_encoders", clip_name) 358 | clip = comfy.sd.load_clip(ckpt_paths=[clip_path], embedding_directory=folder_paths.get_folder_paths("embeddings"), clip_type=clip_type, model_options=model_options) 359 | return (clip,) 360 | 361 | 362 | class DualCLIPLoader_Any: 363 | @classmethod 364 | def INPUT_TYPES(s): 365 | return {"required": { "clip_name1": (folder_paths.get_filename_list("text_encoders"), ), 366 | "clip_name2": (folder_paths.get_filename_list("text_encoders"), ), 367 | "type": (["sdxl", "sd3", "flux", "hidream", "hunyuan_image"], ), 368 | }, 369 | "optional": { 370 | "device": (["default", "cpu"], {"advanced": True}), 371 | "any": (IO.ANY, {}) 372 | }} 373 | RETURN_TYPES = ("CLIP",) 374 | FUNCTION = "load_clip" 375 | 376 | CATEGORY = "advanced/loaders" 377 | 378 | DESCRIPTION = "[Recipes]\n\nsdxl: clip-l, clip-g\nsd3: clip-l, clip-g / clip-l, t5 / clip-g, t5\nflux: clip-l, t5\nhidream: at least one of t5 or llama, recommended t5 and llama\nhunyuan_image: qwen2.5vl 7b and byt5 small" 379 | 380 | def load_clip(self, clip_name1, clip_name2, type, any=None, device="default"): 381 | clip_type = getattr(comfy.sd.CLIPType, type.upper(), comfy.sd.CLIPType.STABLE_DIFFUSION) 382 | 383 | clip_path1 = folder_paths.get_full_path_or_raise("text_encoders", clip_name1) 384 | clip_path2 = folder_paths.get_full_path_or_raise("text_encoders", clip_name2) 385 | 386 | model_options = {} 387 | if device == "cpu": 388 | model_options["load_device"] = model_options["offload_device"] = torch.device("cpu") 389 | 390 | clip = comfy.sd.load_clip(ckpt_paths=[clip_path1, clip_path2], embedding_directory=folder_paths.get_folder_paths("embeddings"), clip_type=clip_type, model_options=model_options) 391 | return (clip,) 392 | 393 | 394 | class CLIPVisionLoader_Any: 395 | @classmethod 396 | def INPUT_TYPES(s): 397 | return {"required": { "clip_name": (folder_paths.get_filename_list("clip_vision"), ), 398 | }, 399 | "optional": {"any": (IO.ANY, {})}} 400 | RETURN_TYPES = ("CLIP_VISION",) 401 | FUNCTION = "load_clip" 402 | 403 | CATEGORY = "loaders" 404 | 405 | def load_clip(self, clip_name, any=None): 406 | clip_path = folder_paths.get_full_path_or_raise("clip_vision", clip_name) 407 | clip_vision = comfy.clip_vision.load(clip_path) 408 | return (clip_vision,) 409 | 410 | 411 | class StyleModelLoader_Any: 412 | @classmethod 413 | def INPUT_TYPES(s): 414 | return {"required": { "style_model_name": (folder_paths.get_filename_list("style_models"), )}, "optional": {"any": (IO.ANY, {})}} 415 | 416 | RETURN_TYPES = ("STYLE_MODEL",) 417 | FUNCTION = "load_style_model" 418 | 419 | CATEGORY = "loaders" 420 | 421 | def load_style_model(self, style_model_name, any=None): 422 | style_model_path = folder_paths.get_full_path_or_raise("style_models", style_model_name) 423 | style_model = comfy.sd.load_style_model(style_model_path) 424 | return (style_model,) 425 | 426 | 427 | class GLIGENLoader_Any: 428 | @classmethod 429 | def INPUT_TYPES(s): 430 | return {"required": { "gligen_name": (folder_paths.get_filename_list("gligen"), ), }, "optional": {"any": (IO.ANY, {})}} 431 | 432 | RETURN_TYPES = ("GLIGEN",) 433 | FUNCTION = "load_gligen" 434 | 435 | CATEGORY = "loaders" 436 | 437 | def load_gligen(self, gligen_name, any=None): 438 | gligen_path = folder_paths.get_full_path_or_raise("gligen", gligen_name) 439 | gligen = comfy.sd.load_gligen(gligen_path) 440 | return (gligen,) 441 | 442 | 443 | 444 | NODE_CLASS_MAPPINGS = { 445 | "CheckpointLoader_Any": CheckpointLoader_Any, 446 | "CheckpointLoaderSimple_Any": CheckpointLoaderSimple_Any, 447 | "unCLIPCheckpointLoader_Any": unCLIPCheckpointLoader_Any, 448 | "LoraLoader_Any": LoraLoader_Any, 449 | "LoraLoaderModelOnly_Any": LoraLoaderModelOnly_Any, 450 | "VAELoader_Any": VAELoader_Any, 451 | "ControlNetLoader_Any": ControlNetLoader_Any, 452 | "DiffControlNetLoader_Any": DiffControlNetLoader_Any, 453 | "UNETLoader_Any": UNETLoader_Any, 454 | "CLIPLoader_Any": CLIPLoader_Any, 455 | "DualCLIPLoader_Any": DualCLIPLoader_Any, 456 | "CLIPVisionLoader_Any": CLIPVisionLoader_Any, 457 | "StyleModelLoader_Any": StyleModelLoader_Any, 458 | "GLIGENLoader_Any": GLIGENLoader_Any, 459 | } 460 | 461 | NODE_DISPLAY_NAME_MAPPINGS = { 462 | "CheckpointLoader_Any": "Load Checkpoint With Config (Any)", 463 | "CheckpointLoaderSimple_Any": "Load Checkpoint (Any)", 464 | "unCLIPCheckpointLoader_Any": "Load unCLIP Checkpoint (Any)", 465 | "LoraLoader_Any": "Load LoRA (Any)", 466 | "LoraLoaderModelOnly_Any": "Load LoRA for Model Only (Any)", 467 | "VAELoader_Any": "Load VAE (Any)", 468 | "ControlNetLoader_Any": "Load ControlNet Model (Any)", 469 | "DiffControlNetLoader_Any": "Load ControlNet Model (diff) (Any)", 470 | "UNETLoader_Any": "Load Diffusion Model (Any)", 471 | "CLIPLoader_Any": "Load CLIP (Any)", 472 | "DualCLIPLoader_Any": "Load Dual CLIP (Any)", 473 | "CLIPVisionLoader_Any": "Load CLIP Vision (Any)", 474 | "StyleModelLoader_Any": "Load Style Model (Any)", 475 | "GLIGENLoader_Any": "Load GLIGEN (Any)", 476 | } --------------------------------------------------------------------------------