commit 585f53d4022fed0cfef69a1bcec5dcced0dcf144 Author: Michael.Kupchik Date: Thu Nov 21 20:26:05 2024 +0000 Initial commit. diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..de46872 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +assets/video.mp4 filter=lfs diff=lfs merge=lfs -text diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..9eaf6f0 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# ComfyUI-LTXVideo +ComfyUI-LTXVideo is a collection of custom nodes for ComfyUI designed to integrate the LTXVideo diffusion model. These nodes enable workflows for text-to-video, image-to-video, and video-to-video generation. The main LTXVideo repository can be found [here](https://github.com/Lightricks/LTX-Video). + +## Installation + +1. Install ComfyUI +2. Clone this repository to `custom-nodes` folder in your ComfyUI installation directory. +3. Install the required packages: +```bash +cd custom_nodes/ComfyUI-LTXVideo && pip install -r requirements.txt +``` +4. Download [ltx-video-2b-v0.9.safetensors](https://huggingface.co/Lightricks/LTX-Video/blob/main/ltx-video-2b-v0.9.safetensors) from Hugging Face and place it under `models/checkpoints`. +5. Clone the text encoder model to `models/text_encoders`: +```bash +cd models/text_encoders && git clone https://huggingface.co/PixArt-alpha/PixArt-XL-2-1024-MS +``` + +## Example workflows + +Note that to run the example workflows, you need to have [ComfyUI-VideoHelperSuite](https://github.com/kosinkadink/ComfyUI-VideoHelperSuite) installed. + +### Text-to-video + +[Download workflow](assets/ltxvideo-t2v.json) +![workflow](assets/ltxvideo-t2v.png) + +### Image-to-video + +[Download workflow](assets/ltxvideo-i2v.json) +![workflow](assets/ltxvideo-i2v.png) + +### Video-to-video + +[Download workflow](assets/ltxvideo-v2v.json) +![workflow](assets/ltxvideo-v2v.png) diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e5d0e39 --- /dev/null +++ b/__init__.py @@ -0,0 +1,8 @@ +from .nodes_registry import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS + +from .transformer import LTXVModelConfigurator, LTXVShiftSigmas +from .t5_encoder import LTXVCLIPModelLoader +from .loader_node import LTXVLoader + +# Export so that ComfyUI can pick them up. +__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS'] diff --git a/assets/baloons.png b/assets/baloons.png new file mode 100644 index 0000000..65fca41 Binary files /dev/null and b/assets/baloons.png differ diff --git a/assets/ltxvideo-i2v.json b/assets/ltxvideo-i2v.json new file mode 100644 index 0000000..f9b6092 --- /dev/null +++ b/assets/ltxvideo-i2v.json @@ -0,0 +1,819 @@ +{ + "last_node_id": 108, + "last_link_id": 268, + "nodes": [ + { + "id": 105, + "type": "LTXVCLIPModelLoader", + "pos": [ + -458, + -122 + ], + "size": [ + 314.85308837890625, + 60.962398529052734 + ], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "clip", + "type": "CLIP", + "links": [ + 264, + 265 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "LTXVCLIPModelLoader" + }, + "widgets_values": [ + "PixArt-XL-2-1024-MS/text_encoder/model-00001-of-00002.safetensors" + ] + }, + { + "id": 87, + "type": "CLIPTextEncode", + "pos": [ + -27, + -245 + ], + "size": [ + 400, + 200 + ], + "flags": {}, + "order": 5, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 264 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 215 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "A group of colorful hot air balloons take off at dawn in Cappadocia, Turkey.\nDozens of balloons in various bright colors and patterns slowly rise into the pink and orange sky. Below them, the unique landscape of Cappadocia unfolds, with its distinctive \"fairy chimneys\" - tall, cone-shaped rock formations scattered across the valley. The rising sun casts long shadows across the terrain, highlighting the otherworldly topography." + ] + }, + { + "id": 36, + "type": "SamplerCustomAdvanced", + "pos": [ + 1107, + -259 + ], + "size": [ + 355.20001220703125, + 106 + ], + "flags": {}, + "order": 11, + "mode": 0, + "inputs": [ + { + "name": "noise", + "type": "NOISE", + "link": 72 + }, + { + "name": "guider", + "type": "GUIDER", + "link": 87, + "slot_index": 1 + }, + { + "name": "sampler", + "type": "SAMPLER", + "link": 70 + }, + { + "name": "sigmas", + "type": "SIGMAS", + "link": 263 + }, + { + "name": "latent_image", + "type": "LATENT", + "link": 258 + } + ], + "outputs": [ + { + "name": "output", + "type": "LATENT", + "links": [ + 78 + ], + "slot_index": 0, + "shape": 3 + }, + { + "name": "denoised_output", + "type": "LATENT", + "links": [], + "slot_index": 1, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "SamplerCustomAdvanced" + }, + "widgets_values": [] + }, + { + "id": 37, + "type": "RandomNoise", + "pos": [ + 765, + -259 + ], + "size": [ + 315, + 82 + ], + "flags": {}, + "order": 1, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "NOISE", + "type": "NOISE", + "links": [ + 72 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "RandomNoise" + }, + "widgets_values": [ + 42, + "fixed" + ] + }, + { + "id": 14, + "type": "KSamplerSelect", + "pos": [ + 768, + -132 + ], + "size": [ + 315, + 58 + ], + "flags": {}, + "order": 2, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "SAMPLER", + "type": "SAMPLER", + "links": [ + 70 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "KSamplerSelect" + }, + "widgets_values": [ + "euler" + ] + }, + { + "id": 104, + "type": "LTXVShiftSigmas", + "pos": [ + 770, + -19 + ], + "size": [ + 315, + 106 + ], + "flags": {}, + "order": 10, + "mode": 0, + "inputs": [ + { + "name": "sigmas", + "type": "SIGMAS", + "link": 262 + }, + { + "name": "sigma_shift", + "type": "FLOAT", + "link": 259, + "widget": { + "name": "sigma_shift" + } + } + ], + "outputs": [ + { + "name": "SIGMAS", + "type": "SIGMAS", + "links": [ + 263 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "LTXVShiftSigmas" + }, + "widgets_values": [ + 1.820833333, + true, + 0.1 + ] + }, + { + "id": 42, + "type": "CFGGuider", + "pos": [ + 776, + 133 + ], + "size": [ + 315, + 98 + ], + "flags": {}, + "order": 8, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 260 + }, + { + "name": "positive", + "type": "CONDITIONING", + "link": 215 + }, + { + "name": "negative", + "type": "CONDITIONING", + "link": 214 + } + ], + "outputs": [ + { + "name": "GUIDER", + "type": "GUIDER", + "links": [ + 87 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "CFGGuider" + }, + "widgets_values": [ + 4 + ] + }, + { + "id": 81, + "type": "BasicScheduler", + "pos": [ + 409, + -10 + ], + "size": [ + 315, + 106 + ], + "flags": {}, + "order": 9, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 261 + } + ], + "outputs": [ + { + "name": "SIGMAS", + "type": "SIGMAS", + "links": [ + 262 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "BasicScheduler" + }, + "widgets_values": [ + "normal", + 20, + 1 + ] + }, + { + "id": 8, + "type": "VAEDecode", + "pos": [ + 1491, + -252 + ], + "size": [ + 210, + 46 + ], + "flags": {}, + "order": 12, + "mode": 0, + "inputs": [ + { + "name": "samples", + "type": "LATENT", + "link": 78 + }, + { + "name": "vae", + "type": "VAE", + "link": 256, + "slot_index": 1 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 121 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "VAEDecode" + }, + "widgets_values": [] + }, + { + "id": 106, + "type": "LoadImage", + "pos": [ + -455, + -18 + ], + "size": [ + 315, + 314 + ], + "flags": {}, + "order": 3, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 268 + ], + "slot_index": 0 + }, + { + "name": "MASK", + "type": "MASK", + "links": null + } + ], + "properties": { + "Node name for S&R": "LoadImage" + }, + "widgets_values": [ + "baloons.png", + "image" + ] + }, + { + "id": 103, + "type": "LTXVModelConfigurator", + "pos": [ + -22, + 257 + ], + "size": [ + 378, + 242 + ], + "flags": {}, + "order": 7, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 254 + }, + { + "name": "vae", + "type": "VAE", + "link": 255 + }, + { + "name": "conditioning", + "type": "IMAGE", + "link": 268, + "shape": 7 + } + ], + "outputs": [ + { + "name": "model", + "type": "MODEL", + "links": [ + 260, + 261 + ], + "slot_index": 0 + }, + { + "name": "latent", + "type": "LATENT", + "links": [ + 258 + ], + "slot_index": 1 + }, + { + "name": "sigma_shift", + "type": "FLOAT", + "links": [ + 259 + ], + "slot_index": 2 + } + ], + "properties": { + "Node name for S&R": "LTXVModelConfigurator" + }, + "widgets_values": [ + "Custom", + 768, + 512, + 65, + 25, + 1, + true + ] + }, + { + "id": 60, + "type": "VHS_VideoCombine", + "pos": [ + 1197, + -104 + ], + "size": [ + 315, + 520.6666870117188 + ], + "flags": {}, + "order": 13, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 121 + }, + { + "name": "audio", + "type": "AUDIO", + "link": null, + "shape": 7 + }, + { + "name": "meta_batch", + "type": "VHS_BatchManager", + "link": null, + "shape": 7 + }, + { + "name": "vae", + "type": "VAE", + "link": null, + "shape": 7 + } + ], + "outputs": [ + { + "name": "Filenames", + "type": "VHS_FILENAMES", + "links": null, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "VHS_VideoCombine" + }, + "widgets_values": { + "frame_rate": 25, + "loop_count": 0, + "filename_prefix": "LTXVideo", + "format": "video/h264-mp4", + "pix_fmt": "yuv420p", + "crf": 19, + "save_metadata": true, + "pingpong": false, + "save_output": true, + "videopreview": { + "hidden": false, + "paused": false, + "params": { + "filename": "AnimateDiff_00006.mp4", + "subfolder": "", + "type": "output", + "format": "video/h264-mp4", + "frame_rate": 25 + } + } + } + }, + { + "id": 88, + "type": "CLIPTextEncode", + "pos": [ + -29, + 5 + ], + "size": [ + 400, + 200 + ], + "flags": {}, + "order": 6, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 265 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 214 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "worst quality, inconsistent motion, blurry, jittery, distorted, watermarks" + ] + }, + { + "id": 102, + "type": "LTXVLoader", + "pos": [ + -461, + -249 + ], + "size": [ + 315, + 78 + ], + "flags": {}, + "order": 4, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "model", + "type": "MODEL", + "links": [ + 254 + ], + "slot_index": 0 + }, + { + "name": "vae", + "type": "VAE", + "links": [ + 255, + 256 + ], + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "LTXVLoader" + }, + "widgets_values": [ + "ltx-video-2b-v0.9.safetensors" + ] + } + ], + "links": [ + [ + 70, + 14, + 0, + 36, + 2, + "SAMPLER" + ], + [ + 72, + 37, + 0, + 36, + 0, + "NOISE" + ], + [ + 78, + 36, + 0, + 8, + 0, + "LATENT" + ], + [ + 87, + 42, + 0, + 36, + 1, + "GUIDER" + ], + [ + 121, + 8, + 0, + 60, + 0, + "IMAGE" + ], + [ + 214, + 88, + 0, + 42, + 2, + "CONDITIONING" + ], + [ + 215, + 87, + 0, + 42, + 1, + "CONDITIONING" + ], + [ + 254, + 102, + 0, + 103, + 0, + "MODEL" + ], + [ + 255, + 102, + 1, + 103, + 1, + "VAE" + ], + [ + 256, + 102, + 1, + 8, + 1, + "VAE" + ], + [ + 258, + 103, + 1, + 36, + 4, + "LATENT" + ], + [ + 259, + 103, + 2, + 104, + 1, + "FLOAT" + ], + [ + 260, + 103, + 0, + 42, + 0, + "MODEL" + ], + [ + 261, + 103, + 0, + 81, + 0, + "MODEL" + ], + [ + 262, + 81, + 0, + 104, + 0, + "SIGMAS" + ], + [ + 263, + 104, + 0, + 36, + 3, + "SIGMAS" + ], + [ + 264, + 105, + 0, + 87, + 0, + "CLIP" + ], + [ + 265, + 105, + 0, + 88, + 0, + "CLIP" + ], + [ + 268, + 106, + 0, + 103, + 2, + "IMAGE" + ] + ], + "groups": [], + "config": {}, + "extra": { + "ds": { + "scale": 0.6115909044841471, + "offset": [ + 593.3581267347251, + 537.9664907705954 + ] + } + }, + "version": 0.4 +} \ No newline at end of file diff --git a/assets/ltxvideo-i2v.png b/assets/ltxvideo-i2v.png new file mode 100644 index 0000000..eea1053 Binary files /dev/null and b/assets/ltxvideo-i2v.png differ diff --git a/assets/ltxvideo-t2v.json b/assets/ltxvideo-t2v.json new file mode 100644 index 0000000..6b8fe1d --- /dev/null +++ b/assets/ltxvideo-t2v.json @@ -0,0 +1,773 @@ +{ + "last_node_id": 106, + "last_link_id": 266, + "nodes": [ + { + "id": 14, + "type": "KSamplerSelect", + "pos": [ + 397, + -104 + ], + "size": [ + 315, + 58 + ], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "SAMPLER", + "type": "SAMPLER", + "links": [ + 70 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "KSamplerSelect" + }, + "widgets_values": [ + "euler" + ] + }, + { + "id": 42, + "type": "CFGGuider", + "pos": [ + 397, + 153 + ], + "size": [ + 315, + 98 + ], + "flags": {}, + "order": 7, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 264 + }, + { + "name": "positive", + "type": "CONDITIONING", + "link": 215 + }, + { + "name": "negative", + "type": "CONDITIONING", + "link": 214 + } + ], + "outputs": [ + { + "name": "GUIDER", + "type": "GUIDER", + "links": [ + 87 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "CFGGuider" + }, + "widgets_values": [ + 4 + ] + }, + { + "id": 81, + "type": "BasicScheduler", + "pos": [ + 45, + -227 + ], + "size": [ + 315, + 106 + ], + "flags": {}, + "order": 8, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 265 + } + ], + "outputs": [ + { + "name": "SIGMAS", + "type": "SIGMAS", + "links": [ + 257 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "BasicScheduler" + }, + "widgets_values": [ + "normal", + 20, + 1 + ] + }, + { + "id": 103, + "type": "LTXVModelConfigurator", + "pos": [ + -392, + -230 + ], + "size": [ + 378, + 242 + ], + "flags": {}, + "order": 6, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 253 + }, + { + "name": "vae", + "type": "VAE", + "link": 254 + }, + { + "name": "conditioning", + "type": "IMAGE", + "link": null, + "shape": 7 + } + ], + "outputs": [ + { + "name": "model", + "type": "MODEL", + "links": [ + 264, + 265 + ], + "slot_index": 0 + }, + { + "name": "latent", + "type": "LATENT", + "links": [ + 255 + ], + "slot_index": 1 + }, + { + "name": "sigma_shift", + "type": "FLOAT", + "links": [ + 258 + ], + "slot_index": 2 + } + ], + "properties": { + "Node name for S&R": "LTXVModelConfigurator" + }, + "widgets_values": [ + "Custom", + 768, + 512, + 65, + 25, + 1, + true + ] + }, + { + "id": 104, + "type": "LTXVShiftSigmas", + "pos": [ + 397, + -260 + ], + "size": [ + 315, + 106 + ], + "flags": {}, + "order": 9, + "mode": 0, + "inputs": [ + { + "name": "sigmas", + "type": "SIGMAS", + "link": 257 + }, + { + "name": "sigma_shift", + "type": "FLOAT", + "link": 258, + "widget": { + "name": "sigma_shift" + } + } + ], + "outputs": [ + { + "name": "SIGMAS", + "type": "SIGMAS", + "links": [ + 259 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "LTXVShiftSigmas" + }, + "widgets_values": [ + 1.820833333, + true, + 0.1 + ] + }, + { + "id": 36, + "type": "SamplerCustomAdvanced", + "pos": [ + 777, + -54 + ], + "size": [ + 355.20001220703125, + 106 + ], + "flags": {}, + "order": 10, + "mode": 0, + "inputs": [ + { + "name": "noise", + "type": "NOISE", + "link": 72 + }, + { + "name": "guider", + "type": "GUIDER", + "link": 87, + "slot_index": 1 + }, + { + "name": "sampler", + "type": "SAMPLER", + "link": 70 + }, + { + "name": "sigmas", + "type": "SIGMAS", + "link": 259 + }, + { + "name": "latent_image", + "type": "LATENT", + "link": 255 + } + ], + "outputs": [ + { + "name": "output", + "type": "LATENT", + "links": [ + 78 + ], + "slot_index": 0, + "shape": 3 + }, + { + "name": "denoised_output", + "type": "LATENT", + "links": [], + "slot_index": 1, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "SamplerCustomAdvanced" + }, + "widgets_values": [] + }, + { + "id": 87, + "type": "CLIPTextEncode", + "pos": [ + -392, + 64 + ], + "size": [ + 378.8294372558594, + 191.98770141601562 + ], + "flags": {}, + "order": 4, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 262 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 215 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "A group of colorful hot air balloons take off at dawn in Cappadocia, Turkey.\nDozens of balloons in various bright colors and patterns slowly rise into the pink and orange sky. Below them, the unique landscape of Cappadocia unfolds, with its distinctive \"fairy chimneys\" - tall, cone-shaped rock formations scattered across the valley. The rising sun casts long shadows across the terrain, highlighting the otherworldly topography." + ] + }, + { + "id": 88, + "type": "CLIPTextEncode", + "pos": [ + -392, + 315 + ], + "size": [ + 377.8036804199219, + 195.38250732421875 + ], + "flags": {}, + "order": 5, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 263 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 214 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "worst quality, inconsistent motion, blurry, jittery, distorted, watermarks" + ] + }, + { + "id": 105, + "type": "LTXVCLIPModelLoader", + "pos": [ + -833, + -65 + ], + "size": [ + 317.6802978515625, + 58 + ], + "flags": {}, + "order": 1, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "clip", + "type": "CLIP", + "links": [ + 262, + 263 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "LTXVCLIPModelLoader" + }, + "widgets_values": [ + "PixArt-XL-2-1024-MS/text_encoder/model-00001-of-00002.safetensors" + ] + }, + { + "id": 8, + "type": "VAEDecode", + "pos": [ + 859, + 107 + ], + "size": [ + 210, + 46 + ], + "flags": {}, + "order": 11, + "mode": 0, + "inputs": [ + { + "name": "samples", + "type": "LATENT", + "link": 78 + }, + { + "name": "vae", + "type": "VAE", + "link": 261, + "slot_index": 1 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 266 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "VAEDecode" + }, + "widgets_values": [] + }, + { + "id": 37, + "type": "RandomNoise", + "pos": [ + 397, + 12 + ], + "size": [ + 315, + 82 + ], + "flags": {}, + "order": 2, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "NOISE", + "type": "NOISE", + "links": [ + 72 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "RandomNoise" + }, + "widgets_values": [ + 42, + "fixed" + ] + }, + { + "id": 106, + "type": "VHS_VideoCombine", + "pos": [ + 882, + 210 + ], + "size": [ + 219.3603515625, + 456.9068908691406 + ], + "flags": {}, + "order": 12, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 266 + }, + { + "name": "audio", + "type": "AUDIO", + "link": null, + "shape": 7 + }, + { + "name": "meta_batch", + "type": "VHS_BatchManager", + "link": null, + "shape": 7 + }, + { + "name": "vae", + "type": "VAE", + "link": null, + "shape": 7 + } + ], + "outputs": [ + { + "name": "Filenames", + "type": "VHS_FILENAMES", + "links": null + } + ], + "properties": { + "Node name for S&R": "VHS_VideoCombine" + }, + "widgets_values": { + "frame_rate": 25, + "loop_count": 0, + "filename_prefix": "LTXVideo", + "format": "video/h264-mp4", + "pix_fmt": "yuv420p", + "crf": 19, + "save_metadata": true, + "pingpong": false, + "save_output": true, + "videopreview": { + "hidden": false, + "paused": false, + "params": { + "filename": "AnimateDiff_00004.mp4", + "subfolder": "", + "type": "output", + "format": "video/h264-mp4", + "frame_rate": 25 + }, + "muted": false + } + } + }, + { + "id": 102, + "type": "LTXVLoader", + "pos": [ + -833, + -196 + ], + "size": [ + 315, + 78 + ], + "flags": {}, + "order": 3, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "model", + "type": "MODEL", + "links": [ + 253 + ], + "slot_index": 0 + }, + { + "name": "vae", + "type": "VAE", + "links": [ + 254, + 261 + ], + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "LTXVLoader" + }, + "widgets_values": [ + "ltx-video-2b-v0.9.safetensors" + ] + } + ], + "links": [ + [ + 70, + 14, + 0, + 36, + 2, + "SAMPLER" + ], + [ + 72, + 37, + 0, + 36, + 0, + "NOISE" + ], + [ + 78, + 36, + 0, + 8, + 0, + "LATENT" + ], + [ + 87, + 42, + 0, + 36, + 1, + "GUIDER" + ], + [ + 214, + 88, + 0, + 42, + 2, + "CONDITIONING" + ], + [ + 215, + 87, + 0, + 42, + 1, + "CONDITIONING" + ], + [ + 253, + 102, + 0, + 103, + 0, + "MODEL" + ], + [ + 254, + 102, + 1, + 103, + 1, + "VAE" + ], + [ + 255, + 103, + 1, + 36, + 4, + "LATENT" + ], + [ + 257, + 81, + 0, + 104, + 0, + "SIGMAS" + ], + [ + 258, + 103, + 2, + 104, + 1, + "FLOAT" + ], + [ + 259, + 104, + 0, + 36, + 3, + "SIGMAS" + ], + [ + 261, + 102, + 1, + 8, + 1, + "VAE" + ], + [ + 262, + 105, + 0, + 87, + 0, + "CLIP" + ], + [ + 263, + 105, + 0, + 88, + 0, + "CLIP" + ], + [ + 264, + 103, + 0, + 42, + 0, + "MODEL" + ], + [ + 265, + 103, + 0, + 81, + 0, + "MODEL" + ], + [ + 266, + 8, + 0, + 106, + 0, + "IMAGE" + ] + ], + "groups": [], + "config": {}, + "extra": { + "ds": { + "scale": 0.6115909044841471, + "offset": [ + 1005.5451653281583, + 472.87625895366426 + ] + } + }, + "version": 0.4 +} \ No newline at end of file diff --git a/assets/ltxvideo-t2v.png b/assets/ltxvideo-t2v.png new file mode 100644 index 0000000..9d4ca60 Binary files /dev/null and b/assets/ltxvideo-t2v.png differ diff --git a/assets/ltxvideo-v2v.json b/assets/ltxvideo-v2v.json new file mode 100644 index 0000000..7252170 --- /dev/null +++ b/assets/ltxvideo-v2v.json @@ -0,0 +1,914 @@ +{ + "last_node_id": 110, + "last_link_id": 271, + "nodes": [ + { + "id": 105, + "type": "LTXVCLIPModelLoader", + "pos": [ + -458, + -122 + ], + "size": [ + 314.85308837890625, + 60.962398529052734 + ], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "clip", + "type": "CLIP", + "links": [ + 264, + 265 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "LTXVCLIPModelLoader" + }, + "widgets_values": [ + "PixArt-XL-2-1024-MS/text_encoder/model-00001-of-00002.safetensors" + ] + }, + { + "id": 87, + "type": "CLIPTextEncode", + "pos": [ + -27, + -245 + ], + "size": [ + 400, + 200 + ], + "flags": {}, + "order": 5, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 264 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 215 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "A group of colorful hot air balloons take off at dawn in Cappadocia, Turkey.\nDozens of balloons in various bright colors and patterns slowly rise into the pink and orange sky. Below them, the unique landscape of Cappadocia unfolds, with its distinctive \"fairy chimneys\" - tall, cone-shaped rock formations scattered across the valley. The rising sun casts long shadows across the terrain, highlighting the otherworldly topography." + ] + }, + { + "id": 36, + "type": "SamplerCustomAdvanced", + "pos": [ + 1107, + -259 + ], + "size": [ + 355.20001220703125, + 106 + ], + "flags": {}, + "order": 12, + "mode": 0, + "inputs": [ + { + "name": "noise", + "type": "NOISE", + "link": 72 + }, + { + "name": "guider", + "type": "GUIDER", + "link": 87, + "slot_index": 1 + }, + { + "name": "sampler", + "type": "SAMPLER", + "link": 70 + }, + { + "name": "sigmas", + "type": "SIGMAS", + "link": 270 + }, + { + "name": "latent_image", + "type": "LATENT", + "link": 258 + } + ], + "outputs": [ + { + "name": "output", + "type": "LATENT", + "links": [ + 78 + ], + "slot_index": 0, + "shape": 3 + }, + { + "name": "denoised_output", + "type": "LATENT", + "links": [], + "slot_index": 1, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "SamplerCustomAdvanced" + }, + "widgets_values": [] + }, + { + "id": 14, + "type": "KSamplerSelect", + "pos": [ + 768, + -132 + ], + "size": [ + 315, + 58 + ], + "flags": {}, + "order": 1, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "SAMPLER", + "type": "SAMPLER", + "links": [ + 70 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "KSamplerSelect" + }, + "widgets_values": [ + "euler" + ] + }, + { + "id": 81, + "type": "BasicScheduler", + "pos": [ + 409, + -10 + ], + "size": [ + 315, + 106 + ], + "flags": {}, + "order": 9, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 261 + } + ], + "outputs": [ + { + "name": "SIGMAS", + "type": "SIGMAS", + "links": [ + 262 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "BasicScheduler" + }, + "widgets_values": [ + "normal", + 20, + 1 + ] + }, + { + "id": 8, + "type": "VAEDecode", + "pos": [ + 1491, + -252 + ], + "size": [ + 210, + 46 + ], + "flags": {}, + "order": 13, + "mode": 0, + "inputs": [ + { + "name": "samples", + "type": "LATENT", + "link": 78 + }, + { + "name": "vae", + "type": "VAE", + "link": 256, + "slot_index": 1 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 121 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "VAEDecode" + }, + "widgets_values": [] + }, + { + "id": 103, + "type": "LTXVModelConfigurator", + "pos": [ + -22, + 257 + ], + "size": [ + 378, + 242 + ], + "flags": {}, + "order": 7, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 254 + }, + { + "name": "vae", + "type": "VAE", + "link": 255 + }, + { + "name": "conditioning", + "type": "IMAGE", + "link": 271, + "shape": 7 + } + ], + "outputs": [ + { + "name": "model", + "type": "MODEL", + "links": [ + 260, + 261 + ], + "slot_index": 0 + }, + { + "name": "latent", + "type": "LATENT", + "links": [ + 258 + ], + "slot_index": 1 + }, + { + "name": "sigma_shift", + "type": "FLOAT", + "links": [ + 259 + ], + "slot_index": 2 + } + ], + "properties": { + "Node name for S&R": "LTXVModelConfigurator" + }, + "widgets_values": [ + "Custom", + 768, + 512, + 65, + 25, + 1, + true + ] + }, + { + "id": 60, + "type": "VHS_VideoCombine", + "pos": [ + 1197, + -104 + ], + "size": [ + 315, + 520.6666870117188 + ], + "flags": {}, + "order": 14, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 121 + }, + { + "name": "audio", + "type": "AUDIO", + "link": null, + "shape": 7 + }, + { + "name": "meta_batch", + "type": "VHS_BatchManager", + "link": null, + "shape": 7 + }, + { + "name": "vae", + "type": "VAE", + "link": null, + "shape": 7 + } + ], + "outputs": [ + { + "name": "Filenames", + "type": "VHS_FILENAMES", + "links": null, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "VHS_VideoCombine" + }, + "widgets_values": { + "frame_rate": 25, + "loop_count": 0, + "filename_prefix": "LTXVideo", + "format": "video/h264-mp4", + "pix_fmt": "yuv420p", + "crf": 19, + "save_metadata": true, + "pingpong": false, + "save_output": true, + "videopreview": { + "hidden": false, + "paused": false, + "params": { + "filename": "LTXVideo_00002.mp4", + "subfolder": "", + "type": "output", + "format": "video/h264-mp4", + "frame_rate": 25 + } + } + } + }, + { + "id": 88, + "type": "CLIPTextEncode", + "pos": [ + -29, + 5 + ], + "size": [ + 400, + 200 + ], + "flags": {}, + "order": 6, + "mode": 0, + "inputs": [ + { + "name": "clip", + "type": "CLIP", + "link": 265 + } + ], + "outputs": [ + { + "name": "CONDITIONING", + "type": "CONDITIONING", + "links": [ + 214 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "CLIPTextEncode" + }, + "widgets_values": [ + "worst quality, inconsistent motion, blurry, jittery, distorted, watermarks" + ] + }, + { + "id": 104, + "type": "LTXVShiftSigmas", + "pos": [ + 759, + -19 + ], + "size": [ + 315, + 106 + ], + "flags": {}, + "order": 10, + "mode": 0, + "inputs": [ + { + "name": "sigmas", + "type": "SIGMAS", + "link": 262 + }, + { + "name": "sigma_shift", + "type": "FLOAT", + "link": 259, + "widget": { + "name": "sigma_shift" + } + } + ], + "outputs": [ + { + "name": "SIGMAS", + "type": "SIGMAS", + "links": [ + 269 + ], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "LTXVShiftSigmas" + }, + "widgets_values": [ + 1.820833333, + true, + 0.1 + ] + }, + { + "id": 109, + "type": "SplitSigmas", + "pos": [ + 761, + 137 + ], + "size": [ + 315, + 78 + ], + "flags": {}, + "order": 11, + "mode": 0, + "inputs": [ + { + "name": "sigmas", + "type": "SIGMAS", + "link": 269 + } + ], + "outputs": [ + { + "name": "high_sigmas", + "type": "SIGMAS", + "links": null + }, + { + "name": "low_sigmas", + "type": "SIGMAS", + "links": [ + 270 + ], + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "SplitSigmas" + }, + "widgets_values": [ + 1 + ] + }, + { + "id": 42, + "type": "CFGGuider", + "pos": [ + 766, + 265 + ], + "size": [ + 315, + 98 + ], + "flags": {}, + "order": 8, + "mode": 0, + "inputs": [ + { + "name": "model", + "type": "MODEL", + "link": 260 + }, + { + "name": "positive", + "type": "CONDITIONING", + "link": 215 + }, + { + "name": "negative", + "type": "CONDITIONING", + "link": 214 + } + ], + "outputs": [ + { + "name": "GUIDER", + "type": "GUIDER", + "links": [ + 87 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "CFGGuider" + }, + "widgets_values": [ + 4 + ] + }, + { + "id": 37, + "type": "RandomNoise", + "pos": [ + 765, + -259 + ], + "size": [ + 315, + 82 + ], + "flags": {}, + "order": 2, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "NOISE", + "type": "NOISE", + "links": [ + 72 + ], + "slot_index": 0, + "shape": 3 + } + ], + "properties": { + "Node name for S&R": "RandomNoise" + }, + "widgets_values": [ + 43, + "fixed" + ] + }, + { + "id": 110, + "type": "VHS_LoadVideo", + "pos": [ + -442, + -10 + ], + "size": [ + 283.6130065917969, + 473.7097473144531 + ], + "flags": {}, + "order": 3, + "mode": 0, + "inputs": [ + { + "name": "meta_batch", + "type": "VHS_BatchManager", + "link": null, + "shape": 7 + }, + { + "name": "vae", + "type": "VAE", + "link": null, + "shape": 7 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [ + 271 + ], + "slot_index": 0 + }, + { + "name": "frame_count", + "type": "INT", + "links": null + }, + { + "name": "audio", + "type": "AUDIO", + "links": null + }, + { + "name": "video_info", + "type": "VHS_VIDEOINFO", + "links": null + } + ], + "properties": { + "Node name for S&R": "VHS_LoadVideo" + }, + "widgets_values": { + "video": "video.mp4", + "force_rate": 0, + "force_size": "Disabled", + "custom_width": 512, + "custom_height": 512, + "frame_load_cap": 0, + "skip_first_frames": 0, + "select_every_nth": 1, + "choose video to upload": "image", + "videopreview": { + "hidden": false, + "paused": false, + "params": { + "force_rate": 0, + "frame_load_cap": 0, + "skip_first_frames": 0, + "select_every_nth": 1, + "filename": "video.mp4", + "type": "input", + "format": "video/mp4" + }, + "muted": false + } + } + }, + { + "id": 102, + "type": "LTXVLoader", + "pos": [ + -461, + -249 + ], + "size": [ + 315, + 78 + ], + "flags": {}, + "order": 4, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "model", + "type": "MODEL", + "links": [ + 254 + ], + "slot_index": 0 + }, + { + "name": "vae", + "type": "VAE", + "links": [ + 255, + 256 + ], + "slot_index": 1 + } + ], + "properties": { + "Node name for S&R": "LTXVLoader" + }, + "widgets_values": [ + "ltx-video-2b-v0.9.safetensors" + ] + } + ], + "links": [ + [ + 70, + 14, + 0, + 36, + 2, + "SAMPLER" + ], + [ + 72, + 37, + 0, + 36, + 0, + "NOISE" + ], + [ + 78, + 36, + 0, + 8, + 0, + "LATENT" + ], + [ + 87, + 42, + 0, + 36, + 1, + "GUIDER" + ], + [ + 121, + 8, + 0, + 60, + 0, + "IMAGE" + ], + [ + 214, + 88, + 0, + 42, + 2, + "CONDITIONING" + ], + [ + 215, + 87, + 0, + 42, + 1, + "CONDITIONING" + ], + [ + 254, + 102, + 0, + 103, + 0, + "MODEL" + ], + [ + 255, + 102, + 1, + 103, + 1, + "VAE" + ], + [ + 256, + 102, + 1, + 8, + 1, + "VAE" + ], + [ + 258, + 103, + 1, + 36, + 4, + "LATENT" + ], + [ + 259, + 103, + 2, + 104, + 1, + "FLOAT" + ], + [ + 260, + 103, + 0, + 42, + 0, + "MODEL" + ], + [ + 261, + 103, + 0, + 81, + 0, + "MODEL" + ], + [ + 262, + 81, + 0, + 104, + 0, + "SIGMAS" + ], + [ + 264, + 105, + 0, + 87, + 0, + "CLIP" + ], + [ + 265, + 105, + 0, + 88, + 0, + "CLIP" + ], + [ + 269, + 104, + 0, + 109, + 0, + "SIGMAS" + ], + [ + 270, + 109, + 1, + 36, + 3, + "SIGMAS" + ], + [ + 271, + 110, + 0, + 103, + 2, + "IMAGE" + ] + ], + "groups": [], + "config": {}, + "extra": { + "ds": { + "scale": 0.6115909044841471, + "offset": [ + 595.203978662415, + 513.6446771351451 + ] + } + }, + "version": 0.4 +} \ No newline at end of file diff --git a/assets/ltxvideo-v2v.png b/assets/ltxvideo-v2v.png new file mode 100644 index 0000000..78c7c76 Binary files /dev/null and b/assets/ltxvideo-v2v.png differ diff --git a/assets/video.mp4 b/assets/video.mp4 new file mode 100644 index 0000000..4c42e35 --- /dev/null +++ b/assets/video.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:610240226d1f9f7e89e6d585176d952787d79523403d1c9a6c2feaba85e8ed35 +size 1538809 diff --git a/img2vid.py b/img2vid.py new file mode 100644 index 0000000..343779f --- /dev/null +++ b/img2vid.py @@ -0,0 +1,43 @@ +import comfy.model_base +import comfy.model_management +import comfy.supported_models_base +import comfy.utils +import comfy.model_patcher +import comfy.sd +import comfy.latent_formats +import nodes +import torch +from .nodes_registry import comfy_node + +from ltx_video.models.autoencoders.vae_encode import get_vae_size_scale_factor + + +def pad_tensor(tensor, target_len): + dim = 2 + repeat_factor = target_len - tensor.shape[dim] # Ceiling division + last_element = tensor.select(dim, -1).unsqueeze(dim) + padding = last_element.repeat(1, 1, repeat_factor, 1, 1) + return torch.cat([tensor, padding], dim=dim) + + +def encode_media_conditioning(init_media, vae, width, height, frames_number): + pixels = comfy.utils.common_upscale( + init_media.movedim(-1, 1), width, height, "bilinear", "center" + ).movedim(1, -1) + encode_pixels = pixels[:, :, :, :3] + init_latents = vae.encode(encode_pixels).float() + + video_scale_factor, _, _ = get_vae_size_scale_factor(vae.first_stage_model) + video_scale_factor = video_scale_factor if frames_number > 1 else 1 + target_len = (frames_number // video_scale_factor) + 1 + init_latents = init_latents[:, :, :target_len] + + init_image_frame_number = init_media.shape[0] + if init_image_frame_number == 1: + result = pad_tensor(init_latents, target_len) + elif init_image_frame_number % 8 != 1: + result = pad_tensor(init_latents, target_len) + else: + result = init_latents + + return result diff --git a/loader_node.py b/loader_node.py new file mode 100644 index 0000000..074dc85 --- /dev/null +++ b/loader_node.py @@ -0,0 +1,150 @@ +from pathlib import Path +import safetensors.torch +import torch + +import comfy +import comfy.model_management +import comfy.model_patcher +import folder_paths + + +from ltx_video.models.transformers.transformer3d import Transformer3DModel +from ltx_video.models.autoencoders.causal_video_autoencoder import CausalVideoAutoencoder +from ltx_video.models.autoencoders.vae_encode import get_vae_size_scale_factor +from ltx_video.models.transformers.symmetric_patchifier import SymmetricPatchifier + +from .model import LTXVTransformer3D, LTXVModel, LTXVModelConfig +from .vae import LTXVVAE + +from .nodes_registry import comfy_node + + +@comfy_node(name="LTXVLoader") +class LTXVLoader: + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "ckpt_name": ( + folder_paths.get_filename_list("checkpoints"), + {"tooltip": "The name of the checkpoint (model) to load."}, + ), + } + } + + RETURN_TYPES = ("MODEL", "VAE") + RETURN_NAMES = ("model", "vae") + FUNCTION = "load" + CATEGORY = "lightricks/LTXV" + TITLE = "LTXV Loader" + OUTPUT_NODE = False + + def load(self, ckpt_name): + load_device = comfy.model_management.get_torch_device() + offload_device = comfy.model_management.unet_offload_device() + + ckpt_path = Path(folder_paths.get_full_path("checkpoints", ckpt_name)) + + weights = safetensors.torch.load_file(ckpt_path, device=str(load_device)) + + vae = self._load_vae(weights) + num_latent_channels = vae.first_stage_model.config.latent_channels + + model = self._load_unet( + load_device, offload_device, weights, num_latent_channels + ) + return (model, vae) + + def _load_vae(self, weights): + vae_prefix = "vae." + vae = LTXVVAE.from_config_and_state_dict( + vae_class=CausalVideoAutoencoder, + config={ + "_class_name": "CausalVideoAutoencoder", + "dims": 3, + "in_channels": 3, + "out_channels": 3, + "latent_channels": 128, + "blocks": [ + ["res_x", 4], + ["compress_all", 1], + ["res_x_y", 1], + ["res_x", 3], + ["compress_all", 1], + ["res_x_y", 1], + ["res_x", 3], + ["compress_all", 1], + ["res_x", 3], + ["res_x", 4], + ], + "scaling_factor": 1.0, + "norm_layer": "pixel_norm", + "patch_size": 4, + "latent_log_var": "uniform", + "use_quant_conv": False, + "causal_decoder": False, + }, + state_dict={ + key.removeprefix(vae_prefix): value + for key, value in weights.items() + if key.startswith(vae_prefix) + }, + ) + return vae + + def _load_unet(self, load_device, offload_device, weights, num_latent_channels): + config = { + "_class_name": "Transformer3DModel", + "_diffusers_version": "0.25.1", + "_name_or_path": "PixArt-alpha/PixArt-XL-2-256x256", + "activation_fn": "gelu-approximate", + "attention_bias": True, + "attention_head_dim": 64, + "attention_type": "default", + "caption_channels": 4096, + "cross_attention_dim": 2048, + "double_self_attention": False, + "dropout": 0.0, + "in_channels": 128, + "norm_elementwise_affine": False, + "norm_eps": 1e-06, + "norm_num_groups": 32, + "num_attention_heads": 32, + "num_embeds_ada_norm": 1000, + "num_layers": 28, + "num_vector_embeds": None, + "only_cross_attention": False, + "out_channels": 128, + "project_to_2d_pos": True, + "upcast_attention": False, + "use_linear_projection": False, + "qk_norm": "rms_norm", + "standardization_norm": "rms_norm", + "positional_embedding_type": "rope", + "positional_embedding_theta": 10000.0, + "positional_embedding_max_pos": [20, 2048, 2048], + "timestep_scale_multiplier": 1000, + } + + transformer = Transformer3DModel.from_config(config) + unet_prefix = "model.diffusion_model." + transformer.load_state_dict( + { + key.removeprefix(unet_prefix): value + for key, value in weights.items() + if key.startswith(unet_prefix) + } + ) + transformer.to(torch.float32).to(load_device).eval() + + diffusion_model = LTXVTransformer3D(transformer, SymmetricPatchifier(1)) + model = LTXVModel( + LTXVModelConfig(num_latent_channels), + model_type=comfy.model_base.ModelType.FLOW, + device=comfy.model_management.get_torch_device(), + ) + model.diffusion_model = diffusion_model + + patcher = comfy.model_patcher.ModelPatcher(model, load_device, offload_device) + + return patcher diff --git a/model.py b/model.py new file mode 100644 index 0000000..cb8c288 --- /dev/null +++ b/model.py @@ -0,0 +1,171 @@ +from contextlib import nullcontext +import torch +import torch.nn as nn +import comfy.model_base +import comfy.model_management +import comfy.supported_models_base +import comfy.utils +import comfy.model_patcher +import comfy.sd +import comfy.latent_formats +import comfy.model_sampling +from comfy.ldm.modules.diffusionmodules.util import make_beta_schedule +import math + +from ltx_video.models.transformers.transformer3d import Transformer3DModel +from ltx_video.models.transformers.symmetric_patchifier import SymmetricPatchifier +from ltx_video.models.autoencoders.vae_encode import get_vae_size_scale_factor + + +class LTXVModelConfig: + def __init__(self, latent_channels): + self.unet_config = {} + self.unet_extra_config = {} + self.latent_format = comfy.latent_formats.LatentFormat() + self.latent_format.latent_channels = latent_channels + self.manual_cast_dtype = torch.float32 + self.sampling_settings = {"multiplier": 1.0} + self.memory_usage_factor = 1 + # denoiser is handled by extension + self.unet_config["disable_unet_model_creation"] = True + + +class LTXVSampling(torch.nn.Module, comfy.model_sampling.CONST): + def __init__(self, condition_mask): + super().__init__() + self.condition_mask = condition_mask + self.set_parameters(shift=1.0, multiplier=1) + + def set_parameters(self, shift=1.0, timesteps=1000, multiplier=1000): + self.shift = shift + self.multiplier = multiplier + ts = self.sigma((torch.arange(1, timesteps + 1, 1) / timesteps) * multiplier) + self.register_buffer("sigmas", ts) + + @property + def sigma_min(self): + return 0.0 + + @property + def sigma_max(self): + return 1.0 + + def timestep(self, sigma): + return sigma * self.multiplier + + def sigma(self, timestep): + return timestep + + def percent_to_sigma(self, percent): + if percent <= 0.0: + return 1.0 + if percent >= 1.0: + return 0.0 + return 1.0 - percent + + def noise_scaling(self, sigma, noise, latent_image, max_denoise=False): + self.condition_mask = self.condition_mask.to(latent_image.device) + scaled = latent_image * (1 - sigma) + noise * sigma + result = latent_image * self.condition_mask + scaled * (1 - self.condition_mask) + + return result + + def calculate_denoised(self, sigma, model_output, model_input): + sigma = sigma.view(sigma.shape[:1] + (1,) * (model_output.ndim - 1)) + result = model_input - model_output * sigma + # In order to d * dT to be zero in euler step, we need to set result equal to input in first latent frame. + result = result * (1 - self.condition_mask) + model_input * self.condition_mask + return result + + +class LTXVModel(comfy.model_base.BaseModel): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.model_sampling = LTXVSampling(torch.zeros([1])) + + +class LTXVTransformer3D(nn.Module): + def __init__( + self, transformer: Transformer3DModel, patchifier: SymmetricPatchifier + ): + super().__init__() + self.transformer = transformer + self.dtype = transformer.dtype + self.patchifier = patchifier + + def forward( + self, + latent, + timesteps, + context, + indices_grid, + img_hw=None, + aspect_ratio=None, + mixed_precision=True, + **kwargs, + ): + # infer mask from context padding, assumes padding vectors are all zero. + latent = latent.to(self.transformer.dtype) + latent_patchified = self.patchifier.patchify(latent) + context_mask = (context != 0).any(dim=2).float() + + l = latent_patchified + if mixed_precision: + context_manager = torch.autocast("cuda", dtype=torch.bfloat16) + else: + context_manager = nullcontext() + with context_manager: + noise_pred = self.transformer( + l.to(self.transformer.dtype).to(self.transformer.device), + indices_grid.to(self.transformer.device), + encoder_hidden_states=context.to(self.transformer.device), + encoder_attention_mask=context_mask.to(self.transformer.device).to( + torch.int64 + ), + timestep=timesteps, + return_dict=False, + )[0] + + result = self.patchifier.unpatchify( + latents=noise_pred, + output_height=latent.shape[3], + output_width=latent.shape[4], + output_num_frames=latent.shape[2], + out_channels=latent.shape[1] // math.prod(self.patchifier.patch_size), + ) + return result + + +class LTXVTransformer3DWrapper(nn.Module): + def __init__( + self, + transformer: LTXVTransformer3D, + patchifier: SymmetricPatchifier, + conditioning_mask, + indices_grid, + ): + super().__init__() + self.indices_grid = indices_grid + self.dtype = transformer.dtype + self.wrapped_transformer = transformer + self.patchifier = patchifier + self.conditioning_mask = conditioning_mask + self.conditioning_mask_patchified = patchifier.patchify( + self.conditioning_mask + ).squeeze(-1) + + def forward(self, x, timesteps, context, img_hw=None, aspect_ratio=None, **kwargs): + transformer_options = kwargs.get("transformer_options", {}) + mixed_precision = transformer_options.get("mixed_precision", False) + mask = self.conditioning_mask_patchified.to(x.device) + ndim_mask = mask.ndimension() + expanded_timesteps = timesteps.view(timesteps.size(0), *([1] * (ndim_mask - 1))) + timesteps_masked = expanded_timesteps * (1 - mask) + result = self.wrapped_transformer.forward( + x, + timesteps_masked, + context, + self.indices_grid, + mixed_precision=mixed_precision, + ) + return result diff --git a/nodes_registry.py b/nodes_registry.py new file mode 100644 index 0000000..598c077 --- /dev/null +++ b/nodes_registry.py @@ -0,0 +1,132 @@ +import re +from typing import Callable, Optional, Type + +from easy_nodes import initialize_easy_nodes + +NODE_CLASS_MAPPINGS = {} +NODE_DISPLAY_NAME_MAPPINGS = {} + +NODES_DISPLAY_NAME_PREFIX = "๐Ÿ…›๐Ÿ…ฃ๐Ÿ…ง" +EXPERIMENTAL_DISPLAY_NAME_PREFIX = "(Experimental ๐Ÿงช)" +DEPRECATED_DISPLAY_NAME_PREFIX = "(Deprecated ๐Ÿšซ)" +DEFAULT_CATEGORY_NAME = "Lightricks" + +initialize_easy_nodes(default_category=DEFAULT_CATEGORY_NAME, auto_register=True) + + +def register_node(node_class: Type, name: str, description: str) -> None: + """ + Register a ComfyUI node class to ComfyUI's global nodes' registry. + + Args: + node_class (Type): The class of the node to be registered. + name (str): The name of the node. + description (str): The short user-friendly description of the node. + + Raises: + ValueError: If `node_class` is not a class, or `class_name` or `display_name` is not a string. + """ + + if not isinstance(node_class, type): + raise ValueError("`node_class` must be a class") + + if not isinstance(name, str): + raise ValueError("`name` must be a string") + + if not isinstance(description, str): + raise ValueError("`description` must be a string") + + NODE_CLASS_MAPPINGS[name] = node_class + NODE_DISPLAY_NAME_MAPPINGS[name] = description + + +def comfy_node( + node_class: Optional[Type] = None, + name: Optional[str] = None, + description: Optional[str] = None, + experimental: bool = False, + deprecated: bool = False, + skip: bool = False, +) -> Callable: + """ + Decorator for registering a node class with optional name, description, and status flags. + + Args: + node_class (Type): The class of the node to be registered. + name (str, optional): The name of the class. If not provided, the class name will be used. + description (str, optional): The description of the class. + If not provided, an auto-formatted description will be used based on the class name. + experimental (bool): Flag indicating if the class is experimental. Defaults to False. + deprecated (bool): Flag indicating if the class is deprecated. Defaults to False. + skip (bool): Flag indicating if the node registration should be skipped. Defaults to False. + This is useful for conditionally registering nodes based on certain conditions + (e.g. unavailability of certain dependencies). + + Returns: + Callable: The decorator function. + + Raises: + ValueError: If `node_class` is not a class. + """ + + def decorator(node_class: Type) -> Type: + if skip: + return node_class + + if not isinstance(node_class, type): + raise ValueError("`node_class` must be a class") + + nonlocal name, description + if name is None: + name = node_class.__name__ + + # Remove possible "Node" suffix from the class name, e.g. "EditImageNode -> EditImage" + if name is not None and name.endswith("Node"): + name = name[:-4] + + description = _format_description(description, name, experimental, deprecated) + + register_node(node_class, name, description) + return node_class + + # If the decorator is used without parentheses + if node_class is None: + return decorator + else: + return decorator(node_class) + + +def _format_description( + description: str, class_name: str, experimental: bool, deprecated: bool +) -> str: + """Format nodes display name to a standard format""" + + # If description is not provided, auto-generate one based on the class name + if description is None: + description = _camel_case_to_spaces(class_name) + + # Strip the prefix if it's already there + prefix_len = len(NODES_DISPLAY_NAME_PREFIX) + if description.startswith(NODES_DISPLAY_NAME_PREFIX): + description = description[prefix_len:].lstrip() + + # Add the deprecated / experimental prefixes + if deprecated: + description = f"{DEPRECATED_DISPLAY_NAME_PREFIX} {description}" + elif experimental: + description = f"{EXPERIMENTAL_DISPLAY_NAME_PREFIX} {description}" + + # Add the prefix + description = f"{NODES_DISPLAY_NAME_PREFIX} {description}" + + return description + + +def _camel_case_to_spaces(text: str) -> str: + # Add space before each capital letter except the first one + spaced_text = re.sub(r"(?<=[a-z])(?=[A-Z])", " ", text) + # Handle sequences of uppercase letters followed by a lowercase letter + spaced_text = re.sub(r"(?<=[A-Z])(?=[A-Z][a-z])", " ", spaced_text) + # Handle sequences of uppercase letters not followed by a lowercase letter + spaced_text = re.sub(r"(?<=[A-Z])(?=[A-Z][A-Z][a-z])", " ", spaced_text) + return spaced_text diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2dd40c8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +comfyui-easynodes +ltx-video@git+https://github.com/Lightricks/LTX-Video.git@ltx-video-0.9 +huggingface_hub==0.25.2 diff --git a/t5_encoder.py b/t5_encoder.py new file mode 100644 index 0000000..3ffcb05 --- /dev/null +++ b/t5_encoder.py @@ -0,0 +1,143 @@ +import torch +import comfy.clip_model +import comfy.model_base +import comfy.model_management +import comfy.sd1_clip +import comfy.supported_models_base +import comfy.utils +import comfy.model_patcher +import comfy.sd +import comfy.latent_formats +import folder_paths +from pathlib import Path +from .nodes_registry import comfy_node + +from transformers import T5EncoderModel, T5Tokenizer + + +class LTXVTokenizer(comfy.sd1_clip.SDTokenizer): + def __init__(self, tokenizer_path: str): + self.tokenizer = T5Tokenizer.from_pretrained( + tokenizer_path, local_files_only=True + ) + + def tokenize_with_weights(self, text: str, return_word_ids: bool = False): + """ + Takes a prompt and converts it to a list of (token, weight, word id) elements. + Tokens can both be integer tokens and pre computed CLIP tensors. + Word id values are unique per word and embedding, where the id 0 is reserved for non word tokens. + Returned list has the dimensions NxM where M is the input size of CLIP + """ + text = text.lower().strip() + text_inputs = self.tokenizer( + text, + padding="max_length", # do_not_pad, longest, max_length + max_length=128, + truncation=True, + add_special_tokens=True, + return_tensors="pt", + ) + text_input_ids = text_inputs.input_ids + prompt_attention_mask = text_inputs.attention_mask + + out = { + "t5xxl": [ + (token, weight, i) + for i, (token, weight) in enumerate( + zip(text_input_ids[0], prompt_attention_mask[0]) + ) + ] + } + + if not return_word_ids: + out = {k: [(t, w) for t, w, _ in v] for k, v in out.items()} + + return out + + +class LTXVTextEncoderModel(torch.nn.Module): + def __init__( + self, encoder_path, dtype_t5=None, device="cpu", dtype=None, model_options={} + ): + super().__init__() + dtype_t5 = comfy.model_management.pick_weight_dtype(dtype_t5, dtype, device) + self.t5xxl = ( + T5EncoderModel.from_pretrained(encoder_path, local_files_only=True) + .to(dtype_t5) + .to(device) + ) + self.dtypes = set([dtype, dtype_t5]) + + def set_clip_options(self, options): + pass + + def reset_clip_options(self): + pass + + def encode_token_weights(self, token_weight_pairs): + token_weight_pairs_t5 = token_weight_pairs["t5xxl"] + text_input_ids = torch.tensor( + [[t[0] for t in token_weight_pairs_t5]], + device=self.t5xxl.device, + ) + prompt_attention_mask = torch.tensor( + [[w[1] for w in token_weight_pairs_t5]], + device=self.t5xxl.device, + ) + out = self.t5xxl(text_input_ids, attention_mask=prompt_attention_mask)[0] + out = out * prompt_attention_mask.unsqueeze(2) + return out, None, {"attention_mask": prompt_attention_mask} + + def load_sd(self, sd): + return self.t5xxl.load_state_dict(sd, strict=False) + + +def ltxv_clip(encoder_path, dtype_t5=None): + class LTXVTextEncoderModel_(LTXVTextEncoderModel): + def __init__(self, device="cpu", dtype=None, model_options={}): + super().__init__( + encoder_path=encoder_path, + dtype_t5=dtype_t5, + device=device, + dtype=dtype, + model_options=model_options, + ) + + return LTXVTextEncoderModel_ + + +def ltxv_tokenizer(tokenizer_path): + class LTXVTokenizer_(LTXVTokenizer): + def __init__(self, embedding_directory=None, tokenizer_data={}): + super().__init__(tokenizer_path) + + return LTXVTokenizer_ + + +@comfy_node(name="LTXVCLIPModelLoader", description="LTXV CLIP Model Loader") +class LTXVCLIPModelLoader: + @classmethod + def INPUT_TYPES(s): + return {"required": {"clip_path": ( + folder_paths.get_filename_list("text_encoders"), + {"tooltip": "The name of the text encoder model to load."}, + )}} + + RETURN_TYPES = ("CLIP",) + RETURN_NAMES = ("clip",) + FUNCTION = "load_model" + CATEGORY = "lightricks/LTXV" + TITLE = "LTXV Model Loader" + OUTPUT_NODE = False + + def load_model(self, clip_path): + path = Path(folder_paths.get_full_path("text_encoders", clip_path)) + tokenizer_path = path.parents[1] / "tokenizer" + encoder_path = path.parents[1] / "text_encoder" + + clip_target = comfy.supported_models_base.ClipTarget( + tokenizer=ltxv_tokenizer(tokenizer_path), + clip=ltxv_clip(encoder_path, dtype_t5=torch.bfloat16), + ) + + return (comfy.sd.CLIP(clip_target),) diff --git a/transformer.py b/transformer.py new file mode 100644 index 0000000..27a1bff --- /dev/null +++ b/transformer.py @@ -0,0 +1,272 @@ +import torch +import comfy.model_base +import comfy.model_management +import comfy.supported_models_base +import comfy.utils +import comfy.model_patcher +import comfy.sd +import comfy.latent_formats +from comfy.ldm.modules.diffusionmodules.util import make_beta_schedule +import folder_paths +import math +from pathlib import Path +from .nodes_registry import comfy_node + +from ltx_video.models.transformers.transformer3d import Transformer3DModel +from ltx_video.models.transformers.symmetric_patchifier import SymmetricPatchifier +from ltx_video.models.autoencoders.vae_encode import get_vae_size_scale_factor + +from .model import ( + LTXVTransformer3DWrapper, + LTXVTransformer3D, + LTXVModel, + LTXVModelConfig, + LTXVSampling, +) +from .img2vid import encode_media_conditioning + + +def get_normal_shift( + n_tokens: int, + min_tokens: int = 1024, + max_tokens: int = 4096, + min_shift: float = 0.95, + max_shift: float = 2.05, +) -> float: + m = (max_shift - min_shift) / (max_tokens - min_tokens) + b = min_shift - m * min_tokens + return m * n_tokens + b + + +@comfy_node(name="LTXVModelConfigurator") +class LTXVModelConfigurator: + @classmethod + def INPUT_TYPES(s): + PRESETS = [ + "Custom", + "1216x704 | 41", + "1088x704 | 49", + "1056x640 | 57", + "992x608 | 65", + "896x608 | 73", + "896x544 | 81", + "832x544 | 89", + "800x512 | 97", + "768x512 | 97", + "800x480 | 105", + "736x480 | 113", + "704x480 | 121", + "704x448 | 129", + "672x448 | 137", + "640x416 | 153", + "672x384 | 161", + "640x384 | 169", + "608x384 | 177", + "576x384 | 185", + "608x352 | 193", + "576x352 | 201", + "544x352 | 209", + "512x352 | 225", + "512x352 | 233", + "544x320 | 241", + "512x320 | 249", + "512x320 | 257", + ] + return { + "required": { + "model": ("MODEL",), + "vae": ("VAE",), + "preset": ( + PRESETS, + { + "default": "Custom", + "tooltip": "Preset resolution and frame count. Custom allows manual input.", + }, + ), + "width": ("INT", {"default": 768, "min": 1, "max": 10000}), + "height": ("INT", {"default": 512, "min": 1, "max": 10000}), + "frames_number": ("INT", {"default": 65, "min": 9, "max": 257, "step": 8, "tooltip": "Must be equal to N * 8 + 1"}), + "frame_rate": ("INT", {"default": 25, "min": 1, "max": 60}), + "batch": ("INT", {"default": 1, "min": 1, "max": 60}), + "mixed_precision": ("BOOLEAN", {"default": True}), + }, + "optional": {"conditioning": ("IMAGE",{"tooltip": "Optional conditioning image or video."})}, + } + + RETURN_TYPES = ("MODEL", "LATENT", "FLOAT") + RETURN_NAMES = ("model", "latent", "sigma_shift") + FUNCTION = "configure_sizes" + CATEGORY = "lightricks/LTXV" + TITLE = "LTXV Model Configurator" + OUTPUT_NODE = False + + def latent_shape_and_frame_rate( + self, vae, batch, height, width, frames_number, frame_rate + ): + video_scale_factor, vae_scale_factor, _ = get_vae_size_scale_factor( + vae.first_stage_model + ) + video_scale_factor = video_scale_factor if frames_number > 1 else 1 + + latent_height = height // vae_scale_factor + latent_width = width // vae_scale_factor + latent_channels = vae.first_stage_model.config.latent_channels + latent_num_frames = math.floor(frames_number / video_scale_factor) + 1 + latent_frame_rate = frame_rate / video_scale_factor + + latent_shape = [ + batch, + latent_channels, + latent_num_frames, + latent_height, + latent_width, + ] + return latent_shape, latent_frame_rate + + def indices_grid( + self, + latent_shape, + vae_scale_factor, + latent_frame_rate, + patchifier, + use_rope, + device, + ): + scale_grid = ( + (1 / latent_frame_rate, vae_scale_factor, vae_scale_factor) + if use_rope # self.wrapped_transformer.transformer.use_rope + else None + ) + + indices_grid = patchifier.get_grid( + orig_num_frames=latent_shape[2], + orig_height=latent_shape[3], + orig_width=latent_shape[4], + batch_size=latent_shape[0], + scale_grid=scale_grid, + device=device, + ) + + return indices_grid + + def configure_sizes( + self, + model, + vae, + preset, + width, + height, + frames_number, + frame_rate, + batch, + mixed_precision, + conditioning=None, + ): + load_device = comfy.model_management.get_torch_device() + offload_device = comfy.model_management.unet_offload_device() + if preset != "Custom": + preset = preset.split("|") + width, height = map(int, preset[0].strip().split("x")) + frames_number = int(preset[1].strip()) + latent_shape, latent_frame_rate = self.latent_shape_and_frame_rate( + vae, batch, height, width, frames_number, frame_rate + ) + mask_shape = [ + latent_shape[0], + 1, + latent_shape[2], + latent_shape[3], + latent_shape[4], + ] + conditioning_mask = torch.zeros(mask_shape, device=load_device) + if conditioning is not None: + latent = encode_media_conditioning( + conditioning, vae, width, height, frames_number + ) + conditioning_mask[:, :, 0] = 1.0 + else: + latent = torch.zeros(latent_shape, dtype=torch.float32) + + patchifier = SymmetricPatchifier(1) + _, vae_scale_factor, _ = get_vae_size_scale_factor(vae.first_stage_model) + use_rope = model.model.diffusion_model.transformer.use_rope + indices_grid = self.indices_grid( + latent_shape, + vae_scale_factor, + latent_frame_rate, + patchifier, + use_rope, + load_device, + ) + wrapper = LTXVTransformer3DWrapper( + transformer=model.model.diffusion_model, + patchifier=patchifier, + conditioning_mask=conditioning_mask, + indices_grid=indices_grid, + ) + model.model.diffusion_model.to(load_device) + new_model = LTXVModel( + LTXVModelConfig(vae.first_stage_model.config.latent_channels), + model_type=comfy.model_base.ModelType.FLOW, + device=comfy.model_management.get_torch_device(), + ) + new_model.model_sampling = LTXVSampling(wrapper.conditioning_mask) + new_model.diffusion_model = wrapper + + patcher = comfy.model_patcher.ModelPatcher( + new_model, load_device, offload_device + ) + patcher.model_options.setdefault("transformer_options", {})[ + "mixed_precision" + ] = mixed_precision + + num_latent_patches = latent_shape[2] * latent_shape[3] * latent_shape[4] + return (patcher, {"samples": latent}, get_normal_shift(num_latent_patches)) + + +@comfy_node(name="LTXVShiftSigmas") +class LTXVShiftSigmas: + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "sigmas": ("SIGMAS",), + "sigma_shift": ("FLOAT", {"default": 1.820833333}), + "stretch": ("BOOLEAN", { + "default": True, + "tooltip": "Stretch the sigmas to be in the range [terminal, 1]." + }), + "terminal": ( + "FLOAT", + { + "default": 0.1, "min": 0.0, "max": 0.99, "step": 0.01, + "tooltip": "The terminal value of the sigmas after stretching." + }, + ), + } + } + + RETURN_TYPES = ("SIGMAS",) + CATEGORY = "lightricks/LTXV" + + FUNCTION = "shift_sigmas" + DESCRIPTION = "Transforms sigmas to values where the model can focus on denoising high noise." + + def shift_sigmas(self, sigmas, sigma_shift, stretch, terminal): + power = 1 + sigmas = torch.where( + sigmas != 0, + math.exp(sigma_shift) / (math.exp(sigma_shift) + (1 / sigmas - 1) ** power), + 0, + ) + + # Stretch sigmas so that its final value matches the given terminal value. + if stretch: + non_zero_mask = sigmas != 0 + non_zero_sigmas = sigmas[non_zero_mask] + one_minus_z = 1.0 - non_zero_sigmas + scale_factor = one_minus_z[-1] / (1.0 - terminal) + stretched = 1.0 - (one_minus_z / scale_factor) + sigmas[non_zero_mask] = stretched + + return (sigmas,) diff --git a/vae.py b/vae.py new file mode 100644 index 0000000..0a39c20 --- /dev/null +++ b/vae.py @@ -0,0 +1,86 @@ +import torch +import comfy.model_base +import comfy.model_management +import comfy.supported_models_base +import comfy.utils +import comfy.model_patcher +import comfy.sd +import comfy.latent_formats +import folder_paths +from pathlib import Path +from .nodes_registry import comfy_node + +from ltx_video.models.autoencoders.video_autoencoder import VideoAutoencoder +from ltx_video.models.autoencoders.causal_video_autoencoder import CausalVideoAutoencoder +from ltx_video.models.autoencoders.vae_encode import ( + get_vae_size_scale_factor, + vae_decode, + vae_encode, +) +from ltx_video.models.transformers.symmetric_patchifier import SymmetricPatchifier +from diffusers.image_processor import VaeImageProcessor + + +class LTXVVAE(comfy.sd.VAE): + def __init__(self): + self.device = comfy.model_management.vae_device() + self.offload_device = comfy.model_management.vae_offload_device() + + @classmethod + def from_pretrained(cls, vae_class, model_path, dtype=torch.bfloat16): + instance = cls() + model = vae_class.from_pretrained( + pretrained_model_name_or_path=model_path, + revision=None, + torch_dtype=dtype, + load_in_8bit=False, + ) + instance._finalize_model(model) + return instance + + @classmethod + def from_config_and_state_dict( + cls, vae_class, config, state_dict, dtype=torch.bfloat16 + ): + instance = cls() + model = vae_class.from_config(config) + model.load_state_dict(state_dict) + model.to(dtype) + instance._finalize_model(model) + return instance + + def _finalize_model(self, model): + self.video_scale_factor, self.vae_scale_factor, _ = get_vae_size_scale_factor( + model + ) + self.image_processor = VaeImageProcessor(vae_scale_factor=self.vae_scale_factor) + self.first_stage_model = model.eval().to(self.device) + + # Assumes that the input samples have dimensions in following order + # (batch, channels, frames, height, width) + def decode(self, samples_in): + is_video = samples_in.shape[2] > 1 + result = vae_decode( + samples_in.to(self.device), + vae=self.first_stage_model, + is_video=is_video, + vae_per_channel_normalize=True, + ) + result = self.image_processor.postprocess( + result, output_type="pt", do_denormalize=[True] + ) + return ( + result.squeeze(0).permute(1, 2, 3, 0).to(torch.float32) + ) # .to(self.offload_device) + + # Underlying VAE expects b, c, n, h, w dimensions order and dtype specific dtype. + # However in Comfy the convension is n, h, w, c. + def encode(self, pixel_samples): + preprocessed = self.image_processor.preprocess( + pixel_samples.permute(3, 0, 1, 2) + ) + input = preprocessed.unsqueeze(0).to(torch.bfloat16).to(self.device) + latents = vae_encode( + input, self.first_stage_model, vae_per_channel_normalize=True + ).to(comfy.model_management.get_torch_device()) + return latents