From 2f605e0db3c459d4c86a8e35a9d096db653faf64 Mon Sep 17 00:00:00 2001 From: John Pollock Date: Thu, 9 Oct 2025 14:41:53 -0500 Subject: [PATCH] Add WanVideoVACEEncode and enhance WanVideoEncode for multi-GPU support - Implemented WanVideoVACEEncode class for encoding with VACE, including input parameters for width, height, number of frames, and strength. - Enhanced WanVideoEncode class to support multi-GPU encoding, with additional parameters for noise augmentation and latent strength. - Updated device management to ensure proper device context during encoding processes. --- __init__.py | 6 +- ...1_3B_control_lora_example_01_MultiGPU.json | 1274 +++++++++-------- wanvideo.py | 86 ++ 3 files changed, 786 insertions(+), 580 deletions(-) diff --git a/__init__.py b/__init__.py index a6df0d1..53c313c 100644 --- a/__init__.py +++ b/__init__.py @@ -222,6 +222,8 @@ from .wanvideo import ( WanVideoDecode, WanVideoModelLoader, WanVideoSampler, + WanVideoVACEEncode, + WanVideoEncode, ) from .wrappers import ( @@ -368,7 +370,9 @@ wanvideo_nodes = { "WanVideoImageToVideoEncodeMultiGPU": WanVideoImageToVideoEncode, "WanVideoDecodeMultiGPU": WanVideoDecode, "WanVideoModelLoaderMultiGPU": WanVideoModelLoader, - "WanVideoSamplerMultiGPU": WanVideoSampler + "WanVideoSamplerMultiGPU": WanVideoSampler, + "WanVideoVACEEncodeMultiGPU": WanVideoVACEEncode, + "WanVideoEncodeMultiGPU": WanVideoEncode, } register_and_count(["ComfyUI-WanVideoWrapper", "comfyui-wanvideowrapper"], wanvideo_nodes) diff --git a/examples/wannvideowrapper/wanvideo_1_3B_control_lora_example_01_MultiGPU.json b/examples/wannvideowrapper/wanvideo_1_3B_control_lora_example_01_MultiGPU.json index 9bf08bf..32ebe53 100755 --- a/examples/wannvideowrapper/wanvideo_1_3B_control_lora_example_01_MultiGPU.json +++ b/examples/wannvideowrapper/wanvideo_1_3B_control_lora_example_01_MultiGPU.json @@ -1,8 +1,8 @@ { "id": "04f1de76-e363-4c27-bec7-eb184ac6e476", "revision": 0, - "last_node_id": 111, - "last_link_id": 161, + "last_node_id": 114, + "last_link_id": 175, "nodes": [ { "id": 36, @@ -51,6 +51,8 @@ } ], "properties": { + "cnr_id": "ComfyUI-WanVideoWrapper", + "ver": "76ea2aa6a664edbd553799f78d6bafdd23e34dc6", "Node name for S&R": "WanVideoTorchCompileSettings" }, "widgets_values": [ @@ -111,56 +113,6 @@ "color": "#432", "bgcolor": "#653" }, - { - "id": 28, - "type": "WanVideoDecode", - "pos": [ - 1704.86572265625, - -604.0441284179688 - ], - "size": [ - 315, - 198 - ], - "flags": {}, - "order": 17, - "mode": 0, - "inputs": [ - { - "name": "vae", - "type": "WANVAE", - "link": 159 - }, - { - "name": "samples", - "type": "LATENT", - "link": 154 - } - ], - "outputs": [ - { - "name": "images", - "type": "IMAGE", - "slot_index": 0, - "links": [ - 145 - ] - } - ], - "properties": { - "Node name for S&R": "WanVideoDecode" - }, - "widgets_values": [ - false, - 272, - 272, - 144, - 128, - "default" - ], - "color": "#322", - "bgcolor": "#533" - }, { "id": 30, "type": "VHS_VideoCombine", @@ -208,6 +160,8 @@ } ], "properties": { + "cnr_id": "comfyui-videohelpersuite", + "ver": "08e8df15db24da292d4b7f943c460dc2ab442b24", "Node name for S&R": "VHS_VideoCombine" }, "widgets_values": { @@ -225,239 +179,17 @@ "hidden": false, "paused": false, "params": { - "filename": "WanVideoWrapper_I2V_00004.mp4", + "filename": "WanVideoWrapper_I2V_00002.mp4", "subfolder": "", "type": "output", "format": "video/h264-mp4", "frame_rate": 16, - "workflow": "WanVideoWrapper_I2V_00004.png", - "fullpath": "/home/johnj/ComfyUI/output/WanVideoWrapper_I2V_00004.mp4" + "workflow": "WanVideoWrapper_I2V_00002.png", + "fullpath": "/home/johnj/ComfyUI/output/WanVideoWrapper_I2V_00002.mp4" } } } }, - { - "id": 97, - "type": "VHS_LoadVideo", - "pos": [ - -257.8260498046875, - 26.503103256225586 - ], - "size": [ - 247.455078125, - 551.455078125 - ], - "flags": {}, - "order": 4, - "mode": 0, - "inputs": [ - { - "name": "meta_batch", - "shape": 7, - "type": "VHS_BatchManager", - "link": null - }, - { - "name": "vae", - "shape": 7, - "type": "VAE", - "link": null - } - ], - "outputs": [ - { - "name": "IMAGE", - "type": "IMAGE", - "slot_index": 0, - "links": [ - 147 - ] - }, - { - "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": "wolf_interpolated.mp4", - "force_rate": 0, - "custom_width": 0, - "custom_height": 0, - "frame_load_cap": 0, - "skip_first_frames": 0, - "select_every_nth": 1, - "format": "AnimateDiff", - "choose video to upload": "image", - "videopreview": { - "hidden": false, - "paused": false, - "params": { - "filename": "wolf_interpolated.mp4", - "type": "input", - "format": "video/mp4", - "force_rate": 0, - "custom_width": 0, - "custom_height": 0, - "frame_load_cap": 0, - "skip_first_frames": 0, - "select_every_nth": 1 - } - } - } - }, - { - "id": 95, - "type": "WanVideoEncode", - "pos": [ - 280.9074401855469, - -116.20671844482422 - ], - "size": [ - 315, - 242 - ], - "flags": {}, - "order": 14, - "mode": 0, - "inputs": [ - { - "name": "vae", - "type": "WANVAE", - "link": 158 - }, - { - "name": "image", - "type": "IMAGE", - "link": 148 - }, - { - "name": "mask", - "shape": 7, - "type": "MASK", - "link": null - } - ], - "outputs": [ - { - "name": "samples", - "type": "LATENT", - "links": [ - 132 - ] - } - ], - "properties": { - "Node name for S&R": "WanVideoEncode" - }, - "widgets_values": [ - false, - 272, - 272, - 144, - 128, - 0, - 1.0000000000000002 - ] - }, - { - "id": 104, - "type": "ImageBlur", - "pos": [ - 89.50601959228516, - 217.970947265625 - ], - "size": [ - 315, - 82 - ], - "flags": {}, - "order": 11, - "mode": 0, - "inputs": [ - { - "name": "image", - "type": "IMAGE", - "link": 147 - } - ], - "outputs": [ - { - "name": "IMAGE", - "type": "IMAGE", - "slot_index": 0, - "links": [ - 148, - 149 - ] - } - ], - "properties": { - "Node name for S&R": "ImageBlur" - }, - "widgets_values": [ - 4, - 1 - ] - }, - { - "id": 103, - "type": "ImageConcatMulti", - "pos": [ - 2055.855224609375, - -543.0326538085938 - ], - "size": [ - 315, - 150 - ], - "flags": {}, - "order": 18, - "mode": 0, - "inputs": [ - { - "name": "image_1", - "type": "IMAGE", - "link": 149 - }, - { - "name": "image_2", - "shape": 7, - "type": "IMAGE", - "link": 145 - } - ], - "outputs": [ - { - "name": "images", - "type": "IMAGE", - "slot_index": 0, - "links": [ - 146 - ] - } - ], - "properties": {}, - "widgets_values": [ - 2, - "right", - false, - null - ] - }, { "id": 33, "type": "Note", @@ -470,7 +202,7 @@ 88 ], "flags": {}, - "order": 5, + "order": 4, "mode": 0, "inputs": [], "outputs": [], @@ -499,7 +231,7 @@ { "name": "latents", "type": "LATENT", - "link": 132 + "link": 164 }, { "name": "fun_ref_image", @@ -519,6 +251,8 @@ } ], "properties": { + "cnr_id": "ComfyUI-WanVideoWrapper", + "ver": "76ea2aa6a664edbd553799f78d6bafdd23e34dc6", "Node name for S&R": "WanVideoControlEmbeds" }, "widgets_values": [ @@ -526,159 +260,6 @@ 0.7 ] }, - { - "id": 52, - "type": "WanVideoTeaCache", - "pos": [ - 1334.42626953125, - -588.2476196289062 - ], - "size": [ - 315, - 178 - ], - "flags": {}, - "order": 6, - "mode": 0, - "inputs": [], - "outputs": [ - { - "name": "cache_args", - "type": "CACHEARGS", - "links": [ - 153 - ] - } - ], - "properties": { - "Node name for S&R": "WanVideoTeaCache" - }, - "widgets_values": [ - 0.1, - 1, - -1, - "offload_device", - "true", - "e" - ] - }, - { - "id": 64, - "type": "WanVideoTorchCompileSettings", - "pos": [ - -276.8500671386719, - -1050.6326904296875 - ], - "size": [ - 390.5999755859375, - 202 - ], - "flags": {}, - "order": 7, - "mode": 0, - "inputs": [], - "outputs": [ - { - "name": "torch_compile_args", - "type": "WANCOMPILEARGS", - "slot_index": 0, - "links": [ - 157 - ] - } - ], - "properties": { - "Node name for S&R": "WanVideoTorchCompileSettings" - }, - "widgets_values": [ - "inductor", - false, - "default", - false, - 64, - true, - 128 - ] - }, - { - "id": 109, - "type": "WanVideoVAELoaderMultiGPU", - "pos": [ - -246.82862854003906, - -338.9017333984375 - ], - "size": [ - 368.710693359375, - 106 - ], - "flags": {}, - "order": 8, - "mode": 0, - "inputs": [ - { - "name": "compile_args", - "shape": 7, - "type": "WANCOMPILEARGS", - "link": null - } - ], - "outputs": [ - { - "name": "vae", - "type": "WANVAE", - "links": [ - 158, - 159 - ] - } - ], - "properties": { - "Node name for S&R": "WanVideoVAELoaderMultiGPU" - }, - "widgets_values": [ - "wan_2.1_vae.safetensors", - "cuda:0", - "bf16" - ], - "color": "#233", - "bgcolor": "#355" - }, - { - "id": 111, - "type": "LoadWanVideoT5TextEncoderMultiGPU", - "pos": [ - 334.64263916015625, - -356.91937255859375 - ], - "size": [ - 348.9195251464844, - 130 - ], - "flags": {}, - "order": 9, - "mode": 0, - "inputs": [], - "outputs": [ - { - "name": "wan_t5_model", - "type": "WANTEXTENCODER", - "links": [ - 161 - ] - } - ], - "properties": { - "Node name for S&R": "LoadWanVideoT5TextEncoderMultiGPU" - }, - "widgets_values": [ - "umt5-xxl-enc-bf16.safetensors", - "bf16", - "cuda:0", - "disabled" - ], - "color": "#233", - "bgcolor": "#355" - }, { "id": 110, "type": "WanVideoTextEncodeMultiGPU", @@ -691,7 +272,7 @@ 234 ], "flags": {}, - "order": 12, + "order": 11, "mode": 0, "inputs": [ { @@ -700,6 +281,12 @@ "type": "WANTEXTENCODER", "link": 161 }, + { + "name": "load_device", + "shape": 7, + "type": "MULTIGPUDEVICE", + "link": 166 + }, { "name": "model_to_offload", "shape": 7, @@ -717,18 +304,153 @@ } ], "properties": { + "cnr_id": "comfyui-multigpu", + "ver": "ba0a3a6e21b0a7f54bd24c51419a8e85b9217c3f", "Node name for S&R": "WanVideoTextEncodeMultiGPU" }, "widgets_values": [ "video of a wolf", "色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走", "cuda:0", - false, false ], "color": "#233", "bgcolor": "#355" }, + { + "id": 111, + "type": "LoadWanVideoT5TextEncoderMultiGPU", + "pos": [ + 278.705810546875, + -281.6587829589844 + ], + "size": [ + 348.9195251464844, + 150 + ], + "flags": {}, + "order": 5, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "wan_t5_model", + "type": "WANTEXTENCODER", + "links": [ + 161 + ] + }, + { + "name": "load_device", + "type": "MULTIGPUDEVICE", + "links": [ + 166 + ] + } + ], + "properties": { + "cnr_id": "comfyui-multigpu", + "ver": "ba0a3a6e21b0a7f54bd24c51419a8e85b9217c3f", + "Node name for S&R": "LoadWanVideoT5TextEncoderMultiGPU" + }, + "widgets_values": [ + "umt5-xxl-enc-bf16.safetensors", + "bf16", + "cuda:0", + "disabled" + ], + "color": "#233", + "bgcolor": "#355" + }, + { + "id": 64, + "type": "WanVideoTorchCompileSettings", + "pos": [ + -276.8500671386719, + -1050.6326904296875 + ], + "size": [ + 390.5999755859375, + 202 + ], + "flags": {}, + "order": 6, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "torch_compile_args", + "type": "WANCOMPILEARGS", + "slot_index": 0, + "links": [ + 168 + ] + } + ], + "properties": { + "cnr_id": "ComfyUI-WanVideoWrapper", + "ver": "76ea2aa6a664edbd553799f78d6bafdd23e34dc6", + "Node name for S&R": "WanVideoTorchCompileSettings" + }, + "widgets_values": [ + "inductor", + false, + "default", + false, + 64, + true, + 128 + ] + }, + { + "id": 98, + "type": "WanVideoLoraSelect", + "pos": [ + -161.7538604736328, + -680.8223876953125 + ], + "size": [ + 315, + 150 + ], + "flags": {}, + "order": 7, + "mode": 0, + "inputs": [ + { + "name": "prev_lora", + "shape": 7, + "type": "WANVIDLORA", + "link": null + }, + { + "name": "blocks", + "shape": 7, + "type": "SELECTEDBLOCKS", + "link": null + } + ], + "outputs": [ + { + "name": "lora", + "type": "WANVIDLORA", + "links": [ + 169 + ] + } + ], + "properties": { + "cnr_id": "ComfyUI-WanVideoWrapper", + "ver": "76ea2aa6a664edbd553799f78d6bafdd23e34dc6", + "Node name for S&R": "WanVideoLoraSelect" + }, + "widgets_values": [ + "wan2.1-1.3b-control-lora-tile-v1.1_comfy.safetensors", + 1, + false, + true + ] + }, { "id": 108, "type": "WanVideoSamplerMultiGPU", @@ -738,7 +460,7 @@ ], "size": [ 327.80859375, - 902 + 922 ], "flags": {}, "order": 16, @@ -747,7 +469,12 @@ { "name": "model", "type": "WANVIDEOMODEL", - "link": 155 + "link": 170 + }, + { + "name": "compute_device", + "type": "MULTIGPUDEVICE", + "link": 171 }, { "name": "image_embeds", @@ -850,7 +577,7 @@ "name": "samples", "type": "LATENT", "links": [ - 154 + 174 ] }, { @@ -860,6 +587,8 @@ } ], "properties": { + "cnr_id": "comfyui-multigpu", + "ver": "ba0a3a6e21b0a7f54bd24c51419a8e85b9217c3f", "Node name for S&R": "WanVideoSamplerMultiGPU" }, "widgets_values": [ @@ -882,25 +611,410 @@ "bgcolor": "#355" }, { - "id": 107, - "type": "WanVideoModelLoaderMultiGPU", + "id": 109, + "type": "WanVideoVAELoaderMultiGPU", "pos": [ - 295.29010009765625, - -723.5640258789062 + 689.3143310546875, + -934.9156494140625 ], "size": [ - 400.63916015625, - 274 + 368.710693359375, + 126 ], "flags": {}, - "order": 13, + "order": 8, "mode": 0, "inputs": [ { "name": "compile_args", "shape": 7, "type": "WANCOMPILEARGS", - "link": 157 + "link": null + } + ], + "outputs": [ + { + "name": "vae", + "type": "WANVAE", + "links": [ + 162, + 172 + ] + }, + { + "name": "load_device", + "type": "MULTIGPUDEVICE", + "links": [ + 163, + 173 + ] + } + ], + "properties": { + "cnr_id": "comfyui-multigpu", + "ver": "ba0a3a6e21b0a7f54bd24c51419a8e85b9217c3f", + "Node name for S&R": "WanVideoVAELoaderMultiGPU" + }, + "widgets_values": [ + "wan_2.1_vae.safetensors", + "cuda:0", + "bf16" + ], + "color": "#233", + "bgcolor": "#355" + }, + { + "id": 97, + "type": "VHS_LoadVideo", + "pos": [ + -854.7728271484375, + -166.42774963378906 + ], + "size": [ + 247.455078125, + 551.455078125 + ], + "flags": {}, + "order": 9, + "mode": 0, + "inputs": [ + { + "name": "meta_batch", + "shape": 7, + "type": "VHS_BatchManager", + "link": null + }, + { + "name": "vae", + "shape": 7, + "type": "VAE", + "link": null + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "slot_index": 0, + "links": [ + 147 + ] + }, + { + "name": "frame_count", + "type": "INT", + "links": null + }, + { + "name": "audio", + "type": "AUDIO", + "links": null + }, + { + "name": "video_info", + "type": "VHS_VIDEOINFO", + "links": null + } + ], + "properties": { + "cnr_id": "comfyui-videohelpersuite", + "ver": "08e8df15db24da292d4b7f943c460dc2ab442b24", + "Node name for S&R": "VHS_LoadVideo" + }, + "widgets_values": { + "video": "wolf_interpolated.mp4", + "force_rate": 0, + "custom_width": 0, + "custom_height": 0, + "frame_load_cap": 0, + "skip_first_frames": 0, + "select_every_nth": 1, + "format": "AnimateDiff", + "choose video to upload": "image", + "videopreview": { + "hidden": false, + "paused": false, + "params": { + "filename": "wolf_interpolated.mp4", + "type": "input", + "format": "video/mp4", + "force_rate": 0, + "custom_width": 0, + "custom_height": 0, + "frame_load_cap": 0, + "skip_first_frames": 0, + "select_every_nth": 1 + } + } + } + }, + { + "id": 103, + "type": "ImageConcatMulti", + "pos": [ + 1796.8583984375, + -624.5692138671875 + ], + "size": [ + 315, + 150 + ], + "flags": {}, + "order": 18, + "mode": 0, + "inputs": [ + { + "name": "image_1", + "type": "IMAGE", + "link": 149 + }, + { + "name": "image_2", + "shape": 7, + "type": "IMAGE", + "link": 175 + } + ], + "outputs": [ + { + "name": "images", + "type": "IMAGE", + "slot_index": 0, + "links": [ + 146 + ] + } + ], + "properties": { + "cnr_id": "comfyui-kjnodes", + "ver": "3fcd22f2fe2be69c3229f192362b91888277cbcb" + }, + "widgets_values": [ + 2, + "right", + false, + null + ] + }, + { + "id": 52, + "type": "WanVideoTeaCache", + "pos": [ + 784.0582885742188, + 198.33489990234375 + ], + "size": [ + 315, + 178 + ], + "flags": {}, + "order": 10, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "cache_args", + "type": "CACHEARGS", + "links": [ + 153 + ] + } + ], + "properties": { + "cnr_id": "ComfyUI-WanVideoWrapper", + "ver": "76ea2aa6a664edbd553799f78d6bafdd23e34dc6", + "Node name for S&R": "WanVideoTeaCache" + }, + "widgets_values": [ + 0.1, + 1, + -1, + "offload_device", + "true", + "e" + ] + }, + { + "id": 104, + "type": "ImageBlur", + "pos": [ + -336.56787109375, + -98.77837371826172 + ], + "size": [ + 315, + 82 + ], + "flags": {}, + "order": 13, + "mode": 0, + "inputs": [ + { + "name": "image", + "type": "IMAGE", + "link": 147 + } + ], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "slot_index": 0, + "links": [ + 149, + 165 + ] + } + ], + "properties": { + "cnr_id": "comfy-core", + "ver": "0.3.64", + "Node name for S&R": "ImageBlur" + }, + "widgets_values": [ + 4, + 1 + ] + }, + { + "id": 112, + "type": "WanVideoEncodeMultiGPU", + "pos": [ + 169.56695556640625, + 108.46249389648438 + ], + "size": [ + 271.0992126464844, + 262 + ], + "flags": {}, + "order": 14, + "mode": 0, + "inputs": [ + { + "name": "vae", + "type": "WANVAE", + "link": 162 + }, + { + "name": "load_device", + "type": "MULTIGPUDEVICE", + "link": 163 + }, + { + "name": "image", + "type": "IMAGE", + "link": 165 + }, + { + "name": "mask", + "shape": 7, + "type": "MASK", + "link": null + } + ], + "outputs": [ + { + "name": "samples", + "type": "LATENT", + "links": [ + 164 + ] + } + ], + "properties": { + "cnr_id": "comfyui-multigpu", + "ver": "ba0a3a6e21b0a7f54bd24c51419a8e85b9217c3f", + "Node name for S&R": "WanVideoEncodeMultiGPU" + }, + "widgets_values": [ + false, + 272, + 272, + 144, + 128, + 0, + 1 + ], + "color": "#008181", + "bgcolor": "rgba(24,24,27,.9)" + }, + { + "id": 114, + "type": "WanVideoDecodeMultiGPU", + "pos": [ + 1679.09765625, + -978.121826171875 + ], + "size": [ + 271.8716735839844, + 218 + ], + "flags": {}, + "order": 17, + "mode": 0, + "inputs": [ + { + "name": "vae", + "type": "WANVAE", + "link": 172 + }, + { + "name": "load_device", + "type": "MULTIGPUDEVICE", + "link": 173 + }, + { + "name": "samples", + "type": "LATENT", + "link": 174 + } + ], + "outputs": [ + { + "name": "images", + "type": "IMAGE", + "links": [ + 175 + ] + } + ], + "properties": { + "cnr_id": "comfyui-multigpu", + "ver": "ba0a3a6e21b0a7f54bd24c51419a8e85b9217c3f", + "Node name for S&R": "WanVideoDecodeMultiGPU" + }, + "widgets_values": [ + false, + 272, + 272, + 144, + 128, + "default" + ], + "color": "#008181", + "bgcolor": "rgba(24,24,27,.9)" + }, + { + "id": 113, + "type": "WanVideoModelLoaderMultiGPU", + "pos": [ + 304.0582275390625, + -755.562255859375 + ], + "size": [ + 325.787109375, + 342 + ], + "flags": {}, + "order": 12, + "mode": 0, + "inputs": [ + { + "name": "compile_args", + "shape": 7, + "type": "WANCOMPILEARGS", + "link": 168 }, { "name": "block_swap_args", @@ -912,7 +1026,7 @@ "name": "lora", "shape": 7, "type": "WANVIDLORA", - "link": 156 + "link": 169 }, { "name": "vram_management_args", @@ -921,7 +1035,7 @@ "link": null }, { - "name": "vace_model", + "name": "extra_model", "shape": 7, "type": "VACEPATH", "link": null @@ -937,6 +1051,12 @@ "shape": 7, "type": "MULTITALKMODEL", "link": null + }, + { + "name": "fantasyportrait_model", + "shape": 7, + "type": "FANTASYPORTRAITMODEL", + "link": null } ], "outputs": [ @@ -944,88 +1064,36 @@ "name": "model", "type": "WANVIDEOMODEL", "links": [ - 155 + 170 + ] + }, + { + "name": "compute_device", + "type": "MULTIGPUDEVICE", + "links": [ + 171 ] } ], "properties": { + "cnr_id": "comfyui-multigpu", + "ver": "ba0a3a6e21b0a7f54bd24c51419a8e85b9217c3f", "Node name for S&R": "WanVideoModelLoaderMultiGPU" }, "widgets_values": [ - "wan2.1_t2v_1.3B_bf16.safetensors", + "Wan2_1-T2V-1_3B_bf16.safetensors", "bf16", "disabled", + "offload_device", "cuda:1", - "sdpa" + "sdpa", + "default" ], - "color": "#233", - "bgcolor": "#355" - }, - { - "id": 98, - "type": "WanVideoLoraSelect", - "pos": [ - -161.7538604736328, - -680.8223876953125 - ], - "size": [ - 315, - 150 - ], - "flags": {}, - "order": 10, - "mode": 0, - "inputs": [ - { - "name": "prev_lora", - "shape": 7, - "type": "WANVIDLORA", - "link": null - }, - { - "name": "blocks", - "shape": 7, - "type": "SELECTEDBLOCKS", - "link": null - } - ], - "outputs": [ - { - "name": "lora", - "type": "WANVIDLORA", - "links": [ - 156 - ] - } - ], - "properties": { - "Node name for S&R": "WanVideoLoraSelect" - }, - "widgets_values": [ - "wan2.1-1.3b-control-lora-tile-v1.1_comfy.safetensors", - 1, - false, - true - ] + "color": "#008181", + "bgcolor": "rgba(24,24,27,.9)" } ], "links": [ - [ - 132, - 95, - 0, - 96, - 0, - "LATENT" - ], - [ - 145, - 28, - 0, - 103, - 1, - "IMAGE" - ], [ 146, 103, @@ -1042,14 +1110,6 @@ 0, "IMAGE" ], - [ - 148, - 104, - 0, - 95, - 1, - "IMAGE" - ], [ 149, 104, @@ -1063,7 +1123,7 @@ 96, 0, 108, - 1, + 2, "WANVIDIMAGE_EMBEDS" ], [ @@ -1071,63 +1131,15 @@ 52, 0, 108, - 6, + 7, "CACHEARGS" ], - [ - 154, - 108, - 0, - 28, - 1, - "LATENT" - ], - [ - 155, - 107, - 0, - 108, - 0, - "WANVIDEOMODEL" - ], - [ - 156, - 98, - 0, - 107, - 2, - "WANVIDLORA" - ], - [ - 157, - 64, - 0, - 107, - 0, - "WANCOMPILEARGS" - ], - [ - 158, - 109, - 0, - 95, - 0, - "WANVAE" - ], - [ - 159, - 109, - 0, - 28, - 0, - "WANVAE" - ], [ 160, 110, 0, 108, - 2, + 3, "WANVIDEOTEXTEMBEDS" ], [ @@ -1137,18 +1149,123 @@ 110, 0, "WANTEXTENCODER" + ], + [ + 162, + 109, + 0, + 112, + 0, + "WANVAE" + ], + [ + 163, + 109, + 1, + 112, + 1, + "MULTIGPUDEVICE" + ], + [ + 164, + 112, + 0, + 96, + 0, + "LATENT" + ], + [ + 165, + 104, + 0, + 112, + 2, + "IMAGE" + ], + [ + 166, + 111, + 1, + 110, + 1, + "MULTIGPUDEVICE" + ], + [ + 168, + 64, + 0, + 113, + 0, + "WANCOMPILEARGS" + ], + [ + 169, + 98, + 0, + 113, + 2, + "WANVIDLORA" + ], + [ + 170, + 113, + 0, + 108, + 0, + "WANVIDEOMODEL" + ], + [ + 171, + 113, + 1, + 108, + 1, + "MULTIGPUDEVICE" + ], + [ + 172, + 109, + 0, + 114, + 0, + "WANVAE" + ], + [ + 173, + 109, + 1, + 114, + 1, + "MULTIGPUDEVICE" + ], + [ + 174, + 108, + 0, + 114, + 2, + "LATENT" + ], + [ + 175, + 114, + 0, + 103, + 1, + "IMAGE" ] ], "groups": [], "config": {}, "extra": { "ds": { - "scale": 0.814027493868451, + "scale": 0.5559917313492605, "offset": [ - 714.8717021081054, - 1253.694882650272 + 1542.2773971567624, + 1325.1448841491515 ] }, + "frontendVersion": "1.27.10", "node_versions": { "ComfyUI-WanVideoWrapper": "5a2383621a05825d0d0437781afcb8552d9590fd", "ComfyUI-VideoHelperSuite": "0a75c7958fe320efcb052f1d9f8451fd20c730a8", @@ -1158,8 +1275,7 @@ "VHS_latentpreview": false, "VHS_latentpreviewrate": 0, "VHS_MetadataImage": true, - "VHS_KeepIntermediate": true, - "frontendVersion": "1.25.11" + "VHS_KeepIntermediate": true }, "version": 0.4 } \ No newline at end of file diff --git a/wanvideo.py b/wanvideo.py index 7bda09b..f4164dd 100644 --- a/wanvideo.py +++ b/wanvideo.py @@ -546,3 +546,89 @@ class WanVideoDecode: return original_decode.decode(vae[0], samples, enable_vae_tiling, tile_x, tile_y, tile_stride_x, tile_stride_y, normalization) finally: decode_module.device = original_module_device + + +class WanVideoVACEEncode: + @classmethod + def INPUT_TYPES(s): + return {"required": { + "vae": ("WANVAE",), + "load_device": ("MULTIGPUDEVICE",), + "width": ("INT", {"default": 832, "min": 64, "max": 8096, "step": 8, "tooltip": "Width of the image to encode"}), + "height": ("INT", {"default": 480, "min": 64, "max": 8096, "step": 8, "tooltip": "Height of the image to encode"}), + "num_frames": ("INT", {"default": 81, "min": 1, "max": 10000, "step": 4, "tooltip": "Number of frames to encode"}), + "strength": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.001}), + "vace_start_percent": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "Start percent of the steps to apply VACE"}), + "vace_end_percent": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "End percent of the steps to apply VACE"}), + }, + "optional": { + "input_frames": ("IMAGE",), + "ref_images": ("IMAGE",), + "input_masks": ("MASK",), + "prev_vace_embeds": ("WANVIDIMAGE_EMBEDS",), + "tiled_vae": ("BOOLEAN", {"default": False, "tooltip": "Use tiled VAE encoding for reduced memory use"}), + }, + } + + RETURN_TYPES = ("WANVIDIMAGE_EMBEDS", ) + RETURN_NAMES = ("vace_embeds",) + FUNCTION = "process" + CATEGORY = "multigpu/WanVideoWrapper" + + def process(self, vae, load_device, width, height, num_frames, strength, vace_start_percent, vace_end_percent, input_frames=None, ref_images=None, input_masks=None, prev_vace_embeds=None, tiled_vae=False): + from . import set_current_device + + original_encode = NODE_CLASS_MAPPINGS["WanVideoVACEEncode"]() + encode_module = inspect.getmodule(original_encode) + original_module_device = encode_module.device + + set_current_device(load_device) + compute_device_to_be_patched = mm.get_torch_device() + encode_module.device = compute_device_to_be_patched + + try: + return original_encode.process(vae[0], width, height, num_frames, strength, vace_start_percent, vace_end_percent, input_frames, ref_images, input_masks, prev_vace_embeds, tiled_vae) + finally: + encode_module.device = original_module_device + + +class WanVideoEncode: + @classmethod + def INPUT_TYPES(s): + return {"required": { + "vae": ("WANVAE",), + "load_device": ("MULTIGPUDEVICE",), + "image": ("IMAGE",), + "enable_vae_tiling": ("BOOLEAN", {"default": False, "tooltip": "Drastically reduces memory use but may introduce seams"}), + "tile_x": ("INT", {"default": 272, "min": 64, "max": 2048, "step": 1, "tooltip": "Tile size in pixels, smaller values use less VRAM, may introduce more seams"}), + "tile_y": ("INT", {"default": 272, "min": 64, "max": 2048, "step": 1, "tooltip": "Tile size in pixels, smaller values use less VRAM, may introduce more seams"}), + "tile_stride_x": ("INT", {"default": 144, "min": 32, "max": 2048, "step": 32, "tooltip": "Tile stride in pixels, smaller values use less VRAM, may introduce more seams"}), + "tile_stride_y": ("INT", {"default": 128, "min": 32, "max": 2048, "step": 32, "tooltip": "Tile stride height in pixels, smaller values use less VRAM, may introduce more seams"}), + }, + "optional": { + "noise_aug_strength": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 10.0, "step": 0.001, "tooltip": "Strength of noise augmentation, helpful for leapfusion I2V where some noise can add motion and give sharper results"}), + "latent_strength": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.001, "tooltip": "Additional latent multiplier, helpful for leapfusion I2V where lower values allow for more motion"}), + "mask": ("MASK", ), + } + } + + RETURN_TYPES = ("LATENT",) + RETURN_NAMES = ("samples",) + FUNCTION = "encode" + CATEGORY = "multigpu/WanVideoWrapper" + + def encode(self, vae, load_device, image, enable_vae_tiling, tile_x, tile_y, tile_stride_x, tile_stride_y, noise_aug_strength=0.0, latent_strength=1.0, mask=None): + from . import set_current_device + + original_encode = NODE_CLASS_MAPPINGS["WanVideoEncode"]() + encode_module = inspect.getmodule(original_encode) + original_module_device = encode_module.device + + set_current_device(load_device) + compute_device_to_be_patched = mm.get_torch_device() + encode_module.device = compute_device_to_be_patched + + try: + return original_encode.encode(vae[0], image, enable_vae_tiling, tile_x, tile_y, tile_stride_x, tile_stride_y, noise_aug_strength, latent_strength, mask) + finally: + encode_module.device = original_module_device