Instructions to use hipinis/20260718 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use hipinis/20260718 with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf hipinis/20260718:Q8_0 # Run inference directly in the terminal: llama cli -hf hipinis/20260718:Q8_0
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf hipinis/20260718:Q8_0 # Run inference directly in the terminal: llama cli -hf hipinis/20260718:Q8_0
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf hipinis/20260718:Q8_0 # Run inference directly in the terminal: ./llama-cli -hf hipinis/20260718:Q8_0
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf hipinis/20260718:Q8_0 # Run inference directly in the terminal: ./build/bin/llama-cli -hf hipinis/20260718:Q8_0
Use Docker
docker model run hf.co/hipinis/20260718:Q8_0
- LM Studio
- Jan
- Ollama
How to use hipinis/20260718 with Ollama:
ollama run hf.co/hipinis/20260718:Q8_0
- Unsloth Desktop
- Pi
How to use hipinis/20260718 with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf hipinis/20260718:Q8_0
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "hipinis/20260718:Q8_0" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use hipinis/20260718 with Docker Model Runner:
docker model run hf.co/hipinis/20260718:Q8_0
- Lemonade
How to use hipinis/20260718 with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull hipinis/20260718:Q8_0
Run and chat with the model
lemonade run user.20260718-Q8_0
List all available models
lemonade list
- Hermes Agent
How to use hipinis/20260718 with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf hipinis/20260718:Q8_0
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default hipinis/20260718:Q8_0
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use hipinis/20260718 with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf hipinis/20260718:Q8_0
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "hipinis/20260718:Q8_0" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
Upload 230 files
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +1 -0
- custom_nodes/ComfyUI-WanVideoWrapper/.gitattributes +2 -0
- custom_nodes/ComfyUI-WanVideoWrapper/.gitignore +14 -0
- custom_nodes/ComfyUI-WanVideoWrapper/FlashVSR/LQ_proj_model.py +157 -0
- custom_nodes/ComfyUI-WanVideoWrapper/FlashVSR/TCDecoder.py +261 -0
- custom_nodes/ComfyUI-WanVideoWrapper/FlashVSR/__pycache__/flashvsr_nodes.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/FlashVSR/flashvsr_nodes.py +71 -0
- custom_nodes/ComfyUI-WanVideoWrapper/HuMo/__pycache__/nodes.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/HuMo/audio_proj.py +87 -0
- custom_nodes/ComfyUI-WanVideoWrapper/HuMo/nodes.py +287 -0
- custom_nodes/ComfyUI-WanVideoWrapper/HuMo/whisper_config.json +50 -0
- custom_nodes/ComfyUI-WanVideoWrapper/LICENSE +201 -0
- custom_nodes/ComfyUI-WanVideoWrapper/LongCat/__pycache__/nodes.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/LongCat/layers.py +212 -0
- custom_nodes/ComfyUI-WanVideoWrapper/LongCat/longcat_i2v_testing.json +1292 -0
- custom_nodes/ComfyUI-WanVideoWrapper/LongCat/nodes.py +308 -0
- custom_nodes/ComfyUI-WanVideoWrapper/LongVie2/__pycache__/nodes.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/LongVie2/modules.py +199 -0
- custom_nodes/ComfyUI-WanVideoWrapper/LongVie2/nodes.py +88 -0
- custom_nodes/ComfyUI-WanVideoWrapper/MTV/__pycache__/mtv.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/MTV/__pycache__/nodes.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/MTV/data/mean.npy +3 -0
- custom_nodes/ComfyUI-WanVideoWrapper/MTV/data/std.npy +3 -0
- custom_nodes/ComfyUI-WanVideoWrapper/MTV/draw_pose.py +213 -0
- custom_nodes/ComfyUI-WanVideoWrapper/MTV/motion4d/__init__.py +1 -0
- custom_nodes/ComfyUI-WanVideoWrapper/MTV/motion4d/__pycache__/__init__.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/MTV/motion4d/__pycache__/vqvae.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/MTV/motion4d/vqvae.py +329 -0
- custom_nodes/ComfyUI-WanVideoWrapper/MTV/mtv.py +193 -0
- custom_nodes/ComfyUI-WanVideoWrapper/MTV/nodes.py +340 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/__pycache__/mel_converter.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/__pycache__/nodes_ovi.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/audio_model_layers.py +48 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/LICENSE +21 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/__init__.py +1 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/__pycache__/__init__.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/__pycache__/activations.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/__pycache__/bigvgan.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/__pycache__/models.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/__pycache__/utils.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/activations.py +120 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/alias_free_torch/__init__.py +6 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/alias_free_torch/__pycache__/__init__.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/alias_free_torch/__pycache__/act.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/alias_free_torch/__pycache__/filter.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/alias_free_torch/__pycache__/resample.cpython-313.pyc +0 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/alias_free_torch/act.py +28 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/alias_free_torch/filter.py +95 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/alias_free_torch/resample.py +49 -0
- custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/bigvgan.py +62 -0
.gitattributes
CHANGED
|
@@ -656,3 +656,4 @@ custom_nodes/ComfyUI-WanVideoWrapper/example_workflows/example_inputs/MTV_crafte
|
|
| 656 |
custom_nodes/ComfyUI-WanVideoWrapper/example_workflows/example_inputs/wolf_interpolated.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 657 |
custom_nodes/ComfyUI-WanVideoWrapper/example_workflows/example_inputs/woman.jpg filter=lfs diff=lfs merge=lfs -text
|
| 658 |
custom_nodes/ComfyUI-WanVideoWrapper/example_workflows/example_inputs/woman.wav filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 656 |
custom_nodes/ComfyUI-WanVideoWrapper/example_workflows/example_inputs/wolf_interpolated.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 657 |
custom_nodes/ComfyUI-WanVideoWrapper/example_workflows/example_inputs/woman.jpg filter=lfs diff=lfs merge=lfs -text
|
| 658 |
custom_nodes/ComfyUI-WanVideoWrapper/example_workflows/example_inputs/woman.wav filter=lfs diff=lfs merge=lfs -text
|
| 659 |
+
custom_nodes/ComfyUI-WanVideoWrapper/wanvideo/modules/__pycache__/model.cpython-313.pyc filter=lfs diff=lfs merge=lfs -text
|
custom_nodes/ComfyUI-WanVideoWrapper/.gitattributes
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Auto detect text files and perform LF normalization
|
| 2 |
+
* text=auto
|
custom_nodes/ComfyUI-WanVideoWrapper/.gitignore
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
output/
|
| 2 |
+
*__pycache__/
|
| 3 |
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from einops import rearrange
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
import torch.nn as nn
|
| 5 |
+
import torch.nn.functional as F
|
| 6 |
+
|
| 7 |
+
CACHE_T = 2
|
| 8 |
+
|
| 9 |
+
class RMS_norm(nn.Module):
|
| 10 |
+
|
| 11 |
+
def __init__(self, dim, channel_first=True, images=True, bias=False):
|
| 12 |
+
super().__init__()
|
| 13 |
+
broadcastable_dims = (1, 1, 1) if not images else (1, 1)
|
| 14 |
+
shape = (dim, *broadcastable_dims) if channel_first else (dim,)
|
| 15 |
+
|
| 16 |
+
self.channel_first = channel_first
|
| 17 |
+
self.scale = dim**0.5
|
| 18 |
+
self.gamma = nn.Parameter(torch.ones(shape))
|
| 19 |
+
self.bias = nn.Parameter(torch.zeros(shape)) if bias else 0.
|
| 20 |
+
|
| 21 |
+
def forward(self, x):
|
| 22 |
+
return F.normalize(
|
| 23 |
+
x, dim=(1 if self.channel_first else
|
| 24 |
+
-1)) * self.scale * self.gamma + self.bias
|
| 25 |
+
|
| 26 |
+
class CausalConv3d(nn.Conv3d):
|
| 27 |
+
"""
|
| 28 |
+
Causal 3d convolusion.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
def __init__(self, *args, **kwargs):
|
| 32 |
+
super().__init__(*args, **kwargs)
|
| 33 |
+
self._padding = (self.padding[2], self.padding[2], self.padding[1],
|
| 34 |
+
self.padding[1], 2 * self.padding[0], 0)
|
| 35 |
+
self.padding = (0, 0, 0)
|
| 36 |
+
|
| 37 |
+
def forward(self, x, cache_x=None):
|
| 38 |
+
padding = list(self._padding)
|
| 39 |
+
if cache_x is not None and self._padding[4] > 0:
|
| 40 |
+
cache_x = cache_x.to(x.device)
|
| 41 |
+
x = torch.cat([cache_x, x], dim=2)
|
| 42 |
+
padding[4] -= cache_x.shape[2]
|
| 43 |
+
x = F.pad(x, padding, mode='replicate')
|
| 44 |
+
|
| 45 |
+
return super().forward(x)
|
| 46 |
+
|
| 47 |
+
class PixelShuffle3d(nn.Module):
|
| 48 |
+
def __init__(self, ff, hh, ww):
|
| 49 |
+
super().__init__()
|
| 50 |
+
self.ff = ff
|
| 51 |
+
self.hh = hh
|
| 52 |
+
self.ww = ww
|
| 53 |
+
|
| 54 |
+
def forward(self, x):
|
| 55 |
+
# x: (B, C, F, H, W)
|
| 56 |
+
return rearrange(x,
|
| 57 |
+
'b c (f ff) (h hh) (w ww) -> b (c ff hh ww) f h w',
|
| 58 |
+
ff=self.ff, hh=self.hh, ww=self.ww)
|
| 59 |
+
|
| 60 |
+
class Buffer_LQ4x_Proj(nn.Module):
|
| 61 |
+
|
| 62 |
+
def __init__(self, in_dim, out_dim, layer_num=30):
|
| 63 |
+
super().__init__()
|
| 64 |
+
self.ff = 1
|
| 65 |
+
self.hh = 16
|
| 66 |
+
self.ww = 16
|
| 67 |
+
self.hidden_dim1 = 2048
|
| 68 |
+
self.hidden_dim2 = 3072
|
| 69 |
+
self.layer_num = layer_num
|
| 70 |
+
|
| 71 |
+
self.pixel_shuffle = PixelShuffle3d(self.ff, self.hh, self.ww)
|
| 72 |
+
|
| 73 |
+
self.conv1 = CausalConv3d(in_dim*self.ff*self.hh*self.ww, self.hidden_dim1, (4, 3, 3), stride=(2, 1, 1), padding=(1, 1, 1)) # f -> f/2 h -> h w -> w
|
| 74 |
+
self.norm1 = RMS_norm(self.hidden_dim1, images=False)
|
| 75 |
+
self.act1 = nn.SiLU()
|
| 76 |
+
|
| 77 |
+
self.conv2 = CausalConv3d(self.hidden_dim1, self.hidden_dim2, (4, 3, 3), stride=(2, 1, 1), padding=(1, 1, 1)) # f -> f/2 h -> h w -> w
|
| 78 |
+
self.norm2 = RMS_norm(self.hidden_dim2, images=False)
|
| 79 |
+
self.act2 = nn.SiLU()
|
| 80 |
+
|
| 81 |
+
self.linear_layers = nn.ModuleList([nn.Linear(self.hidden_dim2, out_dim) for _ in range(layer_num)])
|
| 82 |
+
|
| 83 |
+
self.clip_idx = 0
|
| 84 |
+
|
| 85 |
+
def forward(self, video):
|
| 86 |
+
self.clear_cache()
|
| 87 |
+
# x: (B, C, F, H, W)
|
| 88 |
+
|
| 89 |
+
t = video.shape[2]
|
| 90 |
+
iter_ = 1 + (t - 1) // 4
|
| 91 |
+
first_frame = video[:, :, :1, :, :].repeat(1, 1, 3, 1, 1)
|
| 92 |
+
video = torch.cat([first_frame, video], dim=2)
|
| 93 |
+
|
| 94 |
+
out_x = []
|
| 95 |
+
for i in range(iter_):
|
| 96 |
+
x = self.pixel_shuffle(video[:,:,i*4:(i+1)*4,:,:])
|
| 97 |
+
cache1_x = x[:, :, -CACHE_T:, :, :].clone()
|
| 98 |
+
self.cache['conv1'] = cache1_x
|
| 99 |
+
x = self.conv1(x, self.cache['conv1'])
|
| 100 |
+
x = self.norm1(x)
|
| 101 |
+
x = self.act1(x)
|
| 102 |
+
cache2_x = x[:, :, -CACHE_T:, :, :].clone()
|
| 103 |
+
self.cache['conv2'] = cache2_x
|
| 104 |
+
if i == 0:
|
| 105 |
+
continue
|
| 106 |
+
x = self.conv2(x, self.cache['conv2'])
|
| 107 |
+
x = self.norm2(x)
|
| 108 |
+
x = self.act2(x)
|
| 109 |
+
out_x.append(x)
|
| 110 |
+
out_x = torch.cat(out_x, dim = 2)
|
| 111 |
+
|
| 112 |
+
out_x = rearrange(out_x, 'b c f h w -> b (f h w) c')
|
| 113 |
+
outputs = []
|
| 114 |
+
for i in range(self.layer_num):
|
| 115 |
+
outputs.append(self.linear_layers[i](out_x))
|
| 116 |
+
self.clear_cache()
|
| 117 |
+
return outputs
|
| 118 |
+
|
| 119 |
+
def clear_cache(self):
|
| 120 |
+
self.cache = {}
|
| 121 |
+
self.cache['conv1'] = None
|
| 122 |
+
self.cache['conv2'] = None
|
| 123 |
+
self.clip_idx = 0
|
| 124 |
+
|
| 125 |
+
def stream_forward(self, video_clip):
|
| 126 |
+
if self.clip_idx == 0:
|
| 127 |
+
# self.clear_cache()
|
| 128 |
+
first_frame = video_clip[:, :, :1, :, :].repeat(1, 1, 3, 1, 1)
|
| 129 |
+
video_clip = torch.cat([first_frame, video_clip], dim=2)
|
| 130 |
+
x = self.pixel_shuffle(video_clip)
|
| 131 |
+
cache1_x = x[:, :, -CACHE_T:, :, :].clone()
|
| 132 |
+
self.cache['conv1'] = cache1_x
|
| 133 |
+
x = self.conv1(x, self.cache['conv1'])
|
| 134 |
+
x = self.norm1(x)
|
| 135 |
+
x = self.act1(x)
|
| 136 |
+
cache2_x = x[:, :, -CACHE_T:, :, :].clone()
|
| 137 |
+
self.cache['conv2'] = cache2_x
|
| 138 |
+
self.clip_idx += 1
|
| 139 |
+
return None
|
| 140 |
+
else:
|
| 141 |
+
x = self.pixel_shuffle(video_clip)
|
| 142 |
+
cache1_x = x[:, :, -CACHE_T:, :, :].clone()
|
| 143 |
+
self.cache['conv1'] = cache1_x
|
| 144 |
+
x = self.conv1(x, self.cache['conv1'])
|
| 145 |
+
x = self.norm1(x)
|
| 146 |
+
x = self.act1(x)
|
| 147 |
+
cache2_x = x[:, :, -CACHE_T:, :, :].clone()
|
| 148 |
+
self.cache['conv2'] = cache2_x
|
| 149 |
+
x = self.conv2(x, self.cache['conv2'])
|
| 150 |
+
x = self.norm2(x)
|
| 151 |
+
x = self.act2(x)
|
| 152 |
+
out_x = rearrange(x, 'b c f h w -> b (f h w) c')
|
| 153 |
+
outputs = []
|
| 154 |
+
for i in range(self.layer_num):
|
| 155 |
+
outputs.append(self.linear_layers[i](out_x))
|
| 156 |
+
self.clip_idx += 1
|
| 157 |
+
return outputs
|
custom_nodes/ComfyUI-WanVideoWrapper/FlashVSR/TCDecoder.py
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Tiny AutoEncoder for Hunyuan Video (Decoder-only, pruned)
|
| 3 |
+
- Encoder removed
|
| 4 |
+
- Transplant/widening helpers removed
|
| 5 |
+
- Deepening (IdentityConv2d+ReLU) is now built into the decoder structure itself
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import torch
|
| 9 |
+
import torch.nn as nn
|
| 10 |
+
import torch.nn.functional as F
|
| 11 |
+
from tqdm.auto import tqdm
|
| 12 |
+
from collections import namedtuple
|
| 13 |
+
from einops import rearrange
|
| 14 |
+
import torch.nn.init as init
|
| 15 |
+
|
| 16 |
+
DecoderResult = namedtuple("DecoderResult", ("frame", "memory"))
|
| 17 |
+
TWorkItem = namedtuple("TWorkItem", ("input_tensor", "block_index"))
|
| 18 |
+
|
| 19 |
+
# ----------------------------
|
| 20 |
+
# Utility / building blocks
|
| 21 |
+
# ----------------------------
|
| 22 |
+
|
| 23 |
+
class IdentityConv2d(nn.Conv2d):
|
| 24 |
+
"""Same-shape Conv2d initialized to identity (Dirac)."""
|
| 25 |
+
def __init__(self, C, kernel_size=3, bias=False):
|
| 26 |
+
pad = kernel_size // 2
|
| 27 |
+
super().__init__(C, C, kernel_size, padding=pad, bias=bias)
|
| 28 |
+
with torch.no_grad():
|
| 29 |
+
init.dirac_(self.weight)
|
| 30 |
+
if self.bias is not None:
|
| 31 |
+
self.bias.zero_()
|
| 32 |
+
|
| 33 |
+
def conv(n_in, n_out, **kwargs):
|
| 34 |
+
return nn.Conv2d(n_in, n_out, 3, padding=1, **kwargs)
|
| 35 |
+
|
| 36 |
+
class Clamp(nn.Module):
|
| 37 |
+
def forward(self, x):
|
| 38 |
+
return torch.tanh(x / 3) * 3
|
| 39 |
+
|
| 40 |
+
class MemBlock(nn.Module):
|
| 41 |
+
def __init__(self, n_in, n_out):
|
| 42 |
+
super().__init__()
|
| 43 |
+
self.conv = nn.Sequential(
|
| 44 |
+
conv(n_in * 2, n_out), nn.ReLU(inplace=True),
|
| 45 |
+
conv(n_out, n_out), nn.ReLU(inplace=True),
|
| 46 |
+
conv(n_out, n_out)
|
| 47 |
+
)
|
| 48 |
+
self.skip = nn.Conv2d(n_in, n_out, 1, bias=False) if n_in != n_out else nn.Identity()
|
| 49 |
+
self.act = nn.ReLU(inplace=True)
|
| 50 |
+
def forward(self, x, past):
|
| 51 |
+
return self.act(self.conv(torch.cat([x, past], 1)) + self.skip(x))
|
| 52 |
+
|
| 53 |
+
class TPool(nn.Module):
|
| 54 |
+
def __init__(self, n_f, stride):
|
| 55 |
+
super().__init__()
|
| 56 |
+
self.stride = stride
|
| 57 |
+
self.conv = nn.Conv2d(n_f*stride, n_f, 1, bias=False)
|
| 58 |
+
def forward(self, x):
|
| 59 |
+
_NT, C, H, W = x.shape
|
| 60 |
+
return self.conv(x.reshape(-1, self.stride * C, H, W))
|
| 61 |
+
|
| 62 |
+
class TGrow(nn.Module):
|
| 63 |
+
def __init__(self, n_f, stride):
|
| 64 |
+
super().__init__()
|
| 65 |
+
self.stride = stride
|
| 66 |
+
self.conv = nn.Conv2d(n_f, n_f*stride, 1, bias=False)
|
| 67 |
+
def forward(self, x):
|
| 68 |
+
_NT, C, H, W = x.shape
|
| 69 |
+
x = self.conv(x)
|
| 70 |
+
return x.reshape(-1, C, H, W)
|
| 71 |
+
|
| 72 |
+
class PixelShuffle3d(nn.Module):
|
| 73 |
+
def __init__(self, ff, hh, ww):
|
| 74 |
+
super().__init__()
|
| 75 |
+
self.ff = ff
|
| 76 |
+
self.hh = hh
|
| 77 |
+
self.ww = ww
|
| 78 |
+
def forward(self, x):
|
| 79 |
+
# x: (B, C, F, H, W)
|
| 80 |
+
B, C, F, H, W = x.shape
|
| 81 |
+
if F % self.ff != 0:
|
| 82 |
+
first_frame = x[:, :, 0:1, :, :].repeat(1, 1, self.ff - F % self.ff, 1, 1)
|
| 83 |
+
x = torch.cat([first_frame, x], dim=2)
|
| 84 |
+
return rearrange(
|
| 85 |
+
x,
|
| 86 |
+
'b c (f ff) (h hh) (w ww) -> b (c ff hh ww) f h w',
|
| 87 |
+
ff=self.ff, hh=self.hh, ww=self.ww
|
| 88 |
+
).transpose(1, 2)
|
| 89 |
+
|
| 90 |
+
# ----------------------------
|
| 91 |
+
# Generic NTCHW graph executor (kept; used by decoder)
|
| 92 |
+
# ----------------------------
|
| 93 |
+
|
| 94 |
+
def apply_model_with_memblocks(model, x, parallel, show_progress_bar, mem=None):
|
| 95 |
+
"""
|
| 96 |
+
Apply a sequential model with memblocks to the given input.
|
| 97 |
+
Args:
|
| 98 |
+
- model: nn.Sequential of blocks to apply
|
| 99 |
+
- x: input data, of dimensions NTCHW
|
| 100 |
+
- parallel: if True, parallelize over timesteps (fast but uses O(T) memory)
|
| 101 |
+
if False, each timestep will be processed sequentially (slow but uses O(1) memory)
|
| 102 |
+
- show_progress_bar: if True, enables tqdm progressbar display
|
| 103 |
+
|
| 104 |
+
Returns NTCHW tensor of output data.
|
| 105 |
+
"""
|
| 106 |
+
assert x.ndim == 5, f"TAEHV operates on NTCHW tensors, but got {x.ndim}-dim tensor"
|
| 107 |
+
N, T, C, H, W = x.shape
|
| 108 |
+
if parallel:
|
| 109 |
+
x = x.reshape(N*T, C, H, W)
|
| 110 |
+
for b in tqdm(model, disable=not show_progress_bar):
|
| 111 |
+
if isinstance(b, MemBlock):
|
| 112 |
+
NT, C, H, W = x.shape
|
| 113 |
+
T = NT // N
|
| 114 |
+
_x = x.reshape(N, T, C, H, W)
|
| 115 |
+
mem = F.pad(_x, (0,0,0,0,0,0,1,0), value=0)[:,:T].reshape(x.shape)
|
| 116 |
+
x = b(x, mem)
|
| 117 |
+
else:
|
| 118 |
+
x = b(x)
|
| 119 |
+
NT, C, H, W = x.shape
|
| 120 |
+
T = NT // N
|
| 121 |
+
x = x.view(N, T, C, H, W)
|
| 122 |
+
else:
|
| 123 |
+
out = []
|
| 124 |
+
work_queue = [TWorkItem(xt, 0) for t, xt in enumerate(x.reshape(N, T * C, H, W).chunk(T, dim=1))]
|
| 125 |
+
progress_bar = tqdm(range(T), disable=not show_progress_bar)
|
| 126 |
+
while work_queue:
|
| 127 |
+
xt, i = work_queue.pop(0)
|
| 128 |
+
if i == 0:
|
| 129 |
+
progress_bar.update(1)
|
| 130 |
+
if i == len(model):
|
| 131 |
+
out.append(xt)
|
| 132 |
+
else:
|
| 133 |
+
b = model[i]
|
| 134 |
+
if isinstance(b, MemBlock):
|
| 135 |
+
if mem[i] is None:
|
| 136 |
+
xt_new = b(xt, xt * 0)
|
| 137 |
+
mem[i] = xt
|
| 138 |
+
else:
|
| 139 |
+
xt_new = b(xt, mem[i])
|
| 140 |
+
mem[i].copy_(xt)
|
| 141 |
+
work_queue.insert(0, TWorkItem(xt_new, i+1))
|
| 142 |
+
elif isinstance(b, TPool):
|
| 143 |
+
if mem[i] is None:
|
| 144 |
+
mem[i] = []
|
| 145 |
+
mem[i].append(xt)
|
| 146 |
+
if len(mem[i]) > b.stride:
|
| 147 |
+
raise ValueError("TPool internal state invalid.")
|
| 148 |
+
elif len(mem[i]) == b.stride:
|
| 149 |
+
N_, C_, H_, W_ = xt.shape
|
| 150 |
+
xt = b(torch.cat(mem[i], 1).view(N_*b.stride, C_, H_, W_))
|
| 151 |
+
mem[i] = []
|
| 152 |
+
work_queue.insert(0, TWorkItem(xt, i+1))
|
| 153 |
+
elif isinstance(b, TGrow):
|
| 154 |
+
xt = b(xt)
|
| 155 |
+
NT, C_, H_, W_ = xt.shape
|
| 156 |
+
for xt_next in reversed(xt.view(N, b.stride*C_, H_, W_).chunk(b.stride, 1)):
|
| 157 |
+
work_queue.insert(0, TWorkItem(xt_next, i+1))
|
| 158 |
+
else:
|
| 159 |
+
xt = b(xt)
|
| 160 |
+
work_queue.insert(0, TWorkItem(xt, i+1))
|
| 161 |
+
progress_bar.close()
|
| 162 |
+
x = torch.stack(out, 1)
|
| 163 |
+
return x, mem
|
| 164 |
+
|
| 165 |
+
# ----------------------------
|
| 166 |
+
# Decoder-only TAEHV
|
| 167 |
+
# ----------------------------
|
| 168 |
+
|
| 169 |
+
class TAEHV(nn.Module):
|
| 170 |
+
image_channels = 3
|
| 171 |
+
def __init__(
|
| 172 |
+
self,
|
| 173 |
+
decoder_time_upscale=(True, True),
|
| 174 |
+
decoder_space_upscale=(True, True, True),
|
| 175 |
+
channels = [256, 128, 64, 64],
|
| 176 |
+
latent_channels = 16,
|
| 177 |
+
dtype=torch.float32
|
| 178 |
+
):
|
| 179 |
+
"""Initialize TAEHV (decoder-only) with built-in deepening after every ReLU.
|
| 180 |
+
Deepening config: how_many_each=1, k=3 (fixed as requested).
|
| 181 |
+
"""
|
| 182 |
+
super().__init__()
|
| 183 |
+
self.dtype = dtype
|
| 184 |
+
self.latent_channels = latent_channels
|
| 185 |
+
n_f = channels
|
| 186 |
+
self.frames_to_trim = 2**sum(decoder_time_upscale) - 1
|
| 187 |
+
|
| 188 |
+
# Build the decoder "skeleton"
|
| 189 |
+
base_decoder = nn.Sequential(
|
| 190 |
+
Clamp(), conv(self.latent_channels, n_f[0]), nn.ReLU(inplace=True),
|
| 191 |
+
|
| 192 |
+
MemBlock(n_f[0], n_f[0]), MemBlock(n_f[0], n_f[0]), MemBlock(n_f[0], n_f[0]),
|
| 193 |
+
nn.Upsample(scale_factor=2 if decoder_space_upscale[0] else 1),
|
| 194 |
+
TGrow(n_f[0], 1),
|
| 195 |
+
conv(n_f[0], n_f[1], bias=False),
|
| 196 |
+
|
| 197 |
+
MemBlock(n_f[1], n_f[1]), MemBlock(n_f[1], n_f[1]), MemBlock(n_f[1], n_f[1]),
|
| 198 |
+
nn.Upsample(scale_factor=2 if decoder_space_upscale[1] else 1),
|
| 199 |
+
TGrow(n_f[1], 2 if decoder_time_upscale[0] else 1),
|
| 200 |
+
conv(n_f[1], n_f[2], bias=False),
|
| 201 |
+
|
| 202 |
+
MemBlock(n_f[2], n_f[2]), MemBlock(n_f[2], n_f[2]), MemBlock(n_f[2], n_f[2]),
|
| 203 |
+
nn.Upsample(scale_factor=2 if decoder_space_upscale[2] else 1),
|
| 204 |
+
TGrow(n_f[2], 2 if decoder_time_upscale[1] else 1),
|
| 205 |
+
conv(n_f[2], n_f[3], bias=False),
|
| 206 |
+
|
| 207 |
+
nn.ReLU(inplace=True), conv(n_f[3], TAEHV.image_channels),
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
# Inline deepening: insert (IdentityConv2d(k=3) + ReLU) after every ReLU
|
| 211 |
+
self.decoder = self._apply_identity_deepen(base_decoder, how_many_each=1, k=3)
|
| 212 |
+
|
| 213 |
+
self.pixel_shuffle = PixelShuffle3d(4, 8, 8)
|
| 214 |
+
|
| 215 |
+
# Initialize decoder mem state
|
| 216 |
+
self.clean_mem()
|
| 217 |
+
|
| 218 |
+
@staticmethod
|
| 219 |
+
def _apply_identity_deepen(decoder: nn.Sequential, how_many_each=1, k=3) -> nn.Sequential:
|
| 220 |
+
"""Return a new Sequential where every nn.ReLU is followed by how_many_each*(IdentityConv2d(k)+ReLU)."""
|
| 221 |
+
new_layers = []
|
| 222 |
+
for b in decoder:
|
| 223 |
+
new_layers.append(b)
|
| 224 |
+
if isinstance(b, nn.ReLU):
|
| 225 |
+
# Deduce channel count from preceding layer
|
| 226 |
+
C = None
|
| 227 |
+
if len(new_layers) >= 2 and isinstance(new_layers[-2], nn.Conv2d):
|
| 228 |
+
C = new_layers[-2].out_channels
|
| 229 |
+
elif len(new_layers) >= 2 and isinstance(new_layers[-2], MemBlock):
|
| 230 |
+
C = new_layers[-2].conv[-1].out_channels
|
| 231 |
+
if C is not None:
|
| 232 |
+
for _ in range(how_many_each):
|
| 233 |
+
new_layers.append(IdentityConv2d(C, kernel_size=k, bias=False))
|
| 234 |
+
new_layers.append(nn.ReLU(inplace=True))
|
| 235 |
+
return nn.Sequential(*new_layers)
|
| 236 |
+
|
| 237 |
+
def decode_video(self, x, parallel=False, show_progress_bar=False, cond=None):
|
| 238 |
+
"""Decode a sequence of frames from latents.
|
| 239 |
+
x: NTCHW latent tensor; returns NTCHW RGB in ~[0, 1].
|
| 240 |
+
"""
|
| 241 |
+
trim_flag = self.mem[-8] is None # keeps original relative check
|
| 242 |
+
|
| 243 |
+
if cond is not None:
|
| 244 |
+
shuffled = self.pixel_shuffle(cond.to(x))
|
| 245 |
+
x = torch.cat([shuffled[:, :x.shape[1]], x], dim=2)
|
| 246 |
+
|
| 247 |
+
x, self.mem = apply_model_with_memblocks(self.decoder, x, parallel, show_progress_bar, mem=self.mem)
|
| 248 |
+
self.clean_mem()
|
| 249 |
+
|
| 250 |
+
if trim_flag:
|
| 251 |
+
return x[:, self.frames_to_trim:]
|
| 252 |
+
|
| 253 |
+
return x
|
| 254 |
+
|
| 255 |
+
def clean_mem(self):
|
| 256 |
+
self.mem = [None] * len(self.decoder)
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def build_tcdecoder(new_channels = [512, 256, 128, 128], device="cuda", dtype=torch.bfloat16, new_latent_channels=None):
|
| 260 |
+
big = TAEHV(channels=new_channels, latent_channels=new_latent_channels, dtype=dtype).to(device).to(dtype)
|
| 261 |
+
return big
|
custom_nodes/ComfyUI-WanVideoWrapper/FlashVSR/__pycache__/flashvsr_nodes.cpython-313.pyc
ADDED
|
Binary file (3.47 kB). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/FlashVSR/flashvsr_nodes.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import folder_paths
|
| 2 |
+
import torch
|
| 3 |
+
|
| 4 |
+
from comfy.utils import load_torch_file
|
| 5 |
+
import comfy.model_management as mm
|
| 6 |
+
device = mm.get_torch_device()
|
| 7 |
+
offload_device = mm.unet_offload_device()
|
| 8 |
+
|
| 9 |
+
class WanVideoAddFlashVSRInput:
|
| 10 |
+
@classmethod
|
| 11 |
+
def INPUT_TYPES(s):
|
| 12 |
+
return {"required": {
|
| 13 |
+
"embeds": ("WANVIDIMAGE_EMBEDS",),
|
| 14 |
+
"images": ("IMAGE", {"tooltip": "Low-res video frames to enhance"}),
|
| 15 |
+
"strength": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 2.0, "step": 0.01, "tooltip": "Strength to apply the FlashVSR latent"}),
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
RETURN_TYPES = ("WANVIDIMAGE_EMBEDS",)
|
| 20 |
+
RETURN_NAMES = ("image_embeds",)
|
| 21 |
+
FUNCTION = "add"
|
| 22 |
+
CATEGORY = "WanVideoWrapper"
|
| 23 |
+
|
| 24 |
+
def add(self, embeds, images, strength):
|
| 25 |
+
updated = dict(embeds)
|
| 26 |
+
updated["flashvsr_LQ_images"] = images
|
| 27 |
+
updated["flashvsr_strength"] = strength
|
| 28 |
+
return (updated,)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class WanVideoFlashVSRDecoderLoader:
|
| 32 |
+
@classmethod
|
| 33 |
+
def INPUT_TYPES(s):
|
| 34 |
+
return {
|
| 35 |
+
"required": {
|
| 36 |
+
"model_name": (folder_paths.get_filename_list("vae"), {"tooltip": "These models are loaded from 'ComfyUI/models/vae'"}),
|
| 37 |
+
},
|
| 38 |
+
"optional": {
|
| 39 |
+
"precision": (["fp16", "fp32", "bf16"],
|
| 40 |
+
{"default": "bf16"}
|
| 41 |
+
),
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
RETURN_TYPES = ("WANVAE",)
|
| 46 |
+
RETURN_NAMES = ("vae", )
|
| 47 |
+
FUNCTION = "loadmodel"
|
| 48 |
+
CATEGORY = "WanVideoWrapper"
|
| 49 |
+
DESCRIPTION = "Loads Wan VAE model from 'ComfyUI/models/vae'"
|
| 50 |
+
|
| 51 |
+
def loadmodel(self, model_name, precision):
|
| 52 |
+
from .TCDecoder import build_tcdecoder
|
| 53 |
+
dtype = {"bf16": torch.bfloat16, "fp16": torch.float16, "fp32": torch.float32}[precision]
|
| 54 |
+
model_path = folder_paths.get_full_path("vae", model_name)
|
| 55 |
+
sd = load_torch_file(model_path, safe_load=True)
|
| 56 |
+
|
| 57 |
+
TCDecoder = build_tcdecoder(new_channels=[512, 256, 128, 128], new_latent_channels=16+768, dtype=dtype)
|
| 58 |
+
TCDecoder.load_state_dict(sd, strict=True)
|
| 59 |
+
TCDecoder.to(dtype)
|
| 60 |
+
|
| 61 |
+
return (TCDecoder,)
|
| 62 |
+
|
| 63 |
+
NODE_CLASS_MAPPINGS = {
|
| 64 |
+
"WanVideoAddFlashVSRInput": WanVideoAddFlashVSRInput,
|
| 65 |
+
"WanVideoFlashVSRDecoderLoader": WanVideoFlashVSRDecoderLoader,
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
NODE_DISPLAY_NAME_MAPPINGS = {
|
| 69 |
+
"WanVideoAddFlashVSRInput": "WanVideo Add FlashVSR Input",
|
| 70 |
+
"WanVideoFlashVSRDecoderLoader": "WanVideo FlashVSR Decoder Loader",
|
| 71 |
+
}
|
custom_nodes/ComfyUI-WanVideoWrapper/HuMo/__pycache__/nodes.cpython-313.pyc
ADDED
|
Binary file (14.7 kB). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/HuMo/audio_proj.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from einops import rearrange
|
| 3 |
+
from torch import nn
|
| 4 |
+
from einops import rearrange
|
| 5 |
+
|
| 6 |
+
class WanRMSNorm(nn.Module):
|
| 7 |
+
|
| 8 |
+
def __init__(self, dim, eps=1e-5):
|
| 9 |
+
super().__init__()
|
| 10 |
+
self.dim = dim
|
| 11 |
+
self.eps = eps
|
| 12 |
+
self.weight = nn.Parameter(torch.ones(dim))
|
| 13 |
+
|
| 14 |
+
def forward(self, x):
|
| 15 |
+
r"""
|
| 16 |
+
Args:
|
| 17 |
+
x(Tensor): Shape [B, L, C]
|
| 18 |
+
"""
|
| 19 |
+
return self._norm(x.to(self.weight.dtype)) * self.weight
|
| 20 |
+
|
| 21 |
+
def _norm(self, x):
|
| 22 |
+
return x * (torch.rsqrt(x.pow(2).mean(dim=-1, keepdim=True) + self.eps)).to(x.dtype)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class DummyAdapterLayer(nn.Module):
|
| 26 |
+
def __init__(self, layer):
|
| 27 |
+
super().__init__()
|
| 28 |
+
self.layer = layer
|
| 29 |
+
|
| 30 |
+
def forward(self, *args, **kwargs):
|
| 31 |
+
return self.layer(*args, **kwargs)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class AudioProjModel(nn.Module):
|
| 35 |
+
def __init__(
|
| 36 |
+
self,
|
| 37 |
+
seq_len=5,
|
| 38 |
+
blocks=13, # add a new parameter blocks
|
| 39 |
+
channels=768, # add a new parameter channels
|
| 40 |
+
intermediate_dim=512,
|
| 41 |
+
output_dim=1536,
|
| 42 |
+
context_tokens=16,
|
| 43 |
+
):
|
| 44 |
+
super().__init__()
|
| 45 |
+
|
| 46 |
+
self.seq_len = seq_len
|
| 47 |
+
self.blocks = blocks
|
| 48 |
+
self.channels = channels
|
| 49 |
+
self.input_dim = seq_len * blocks * channels # update input_dim to be the product of blocks and channels.
|
| 50 |
+
self.intermediate_dim = intermediate_dim
|
| 51 |
+
self.context_tokens = context_tokens
|
| 52 |
+
self.output_dim = output_dim
|
| 53 |
+
|
| 54 |
+
# define multiple linear layers
|
| 55 |
+
self.audio_proj_glob_1 = DummyAdapterLayer(nn.Linear(self.input_dim, intermediate_dim))
|
| 56 |
+
self.audio_proj_glob_2 = DummyAdapterLayer(nn.Linear(intermediate_dim, intermediate_dim))
|
| 57 |
+
self.audio_proj_glob_3 = DummyAdapterLayer(nn.Linear(intermediate_dim, context_tokens * output_dim))
|
| 58 |
+
|
| 59 |
+
self.audio_proj_glob_norm = DummyAdapterLayer(nn.LayerNorm(output_dim))
|
| 60 |
+
|
| 61 |
+
self.initialize_weights()
|
| 62 |
+
|
| 63 |
+
def initialize_weights(self):
|
| 64 |
+
# Initialize transformer layers:
|
| 65 |
+
def _basic_init(module):
|
| 66 |
+
if isinstance(module, nn.Linear):
|
| 67 |
+
torch.nn.init.xavier_uniform_(module.weight)
|
| 68 |
+
if module.bias is not None:
|
| 69 |
+
nn.init.constant_(module.bias, 0)
|
| 70 |
+
|
| 71 |
+
self.apply(_basic_init)
|
| 72 |
+
|
| 73 |
+
def forward(self, audio_embeds):
|
| 74 |
+
video_length = audio_embeds.shape[1]
|
| 75 |
+
audio_embeds = rearrange(audio_embeds, "bz f w b c -> (bz f) w b c")
|
| 76 |
+
batch_size, window_size, blocks, channels = audio_embeds.shape
|
| 77 |
+
audio_embeds = audio_embeds.view(batch_size, window_size * blocks * channels)
|
| 78 |
+
|
| 79 |
+
audio_embeds = torch.relu(self.audio_proj_glob_1(audio_embeds))
|
| 80 |
+
audio_embeds = torch.relu(self.audio_proj_glob_2(audio_embeds))
|
| 81 |
+
|
| 82 |
+
context_tokens = self.audio_proj_glob_3(audio_embeds).reshape(batch_size, self.context_tokens, self.output_dim)
|
| 83 |
+
|
| 84 |
+
context_tokens = self.audio_proj_glob_norm(context_tokens.to(self.audio_proj_glob_norm.layer.weight.dtype)).to(audio_embeds.dtype)
|
| 85 |
+
context_tok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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import folder_paths
|
| 2 |
+
import torch
|
| 3 |
+
import torch.nn.functional as F
|
| 4 |
+
import os
|
| 5 |
+
import json
|
| 6 |
+
import torchaudio
|
| 7 |
+
|
| 8 |
+
from comfy.utils import load_torch_file, common_upscale
|
| 9 |
+
import comfy.model_management as mm
|
| 10 |
+
|
| 11 |
+
from accelerate import init_empty_weights
|
| 12 |
+
from ..utils import set_module_tensor_to_device, log
|
| 13 |
+
from ..nodes import WanVideoEncodeLatentBatch
|
| 14 |
+
|
| 15 |
+
script_directory = os.path.dirname(os.path.abspath(__file__))
|
| 16 |
+
device = mm.get_torch_device()
|
| 17 |
+
offload_device = mm.unet_offload_device()
|
| 18 |
+
|
| 19 |
+
def linear_interpolation_fps(features, input_fps, output_fps, output_len=None):
|
| 20 |
+
features = features.transpose(1, 2) # [1, C, T]
|
| 21 |
+
seq_len = features.shape[2] / float(input_fps)
|
| 22 |
+
if output_len is None:
|
| 23 |
+
output_len = int(seq_len * output_fps)
|
| 24 |
+
output_features = F.interpolate(features, size=output_len, align_corners=True, mode='linear')
|
| 25 |
+
return output_features.transpose(1, 2)
|
| 26 |
+
|
| 27 |
+
def get_audio_emb_window(audio_emb, frame_num, frame0_idx, audio_shift=2):
|
| 28 |
+
zero_audio_embed = torch.zeros((audio_emb.shape[1], audio_emb.shape[2]), dtype=audio_emb.dtype, device=audio_emb.device)
|
| 29 |
+
zero_audio_embed_3 = torch.zeros((3, audio_emb.shape[1], audio_emb.shape[2]), dtype=audio_emb.dtype, device=audio_emb.device)
|
| 30 |
+
iter_ = 1 + (frame_num - 1) // 4
|
| 31 |
+
audio_emb_wind = []
|
| 32 |
+
for lt_i in range(iter_):
|
| 33 |
+
if lt_i == 0:
|
| 34 |
+
st = frame0_idx + lt_i - 2
|
| 35 |
+
ed = frame0_idx + lt_i + 3
|
| 36 |
+
wind_feat = torch.stack([
|
| 37 |
+
audio_emb[i] if (0 <= i < audio_emb.shape[0]) else zero_audio_embed
|
| 38 |
+
for i in range(st, ed)
|
| 39 |
+
], dim=0)
|
| 40 |
+
wind_feat = torch.cat((zero_audio_embed_3, wind_feat), dim=0)
|
| 41 |
+
else:
|
| 42 |
+
st = frame0_idx + 1 + 4 * (lt_i - 1) - audio_shift
|
| 43 |
+
ed = frame0_idx + 1 + 4 * lt_i + audio_shift
|
| 44 |
+
wind_feat = torch.stack([
|
| 45 |
+
audio_emb[i] if (0 <= i < audio_emb.shape[0]) else zero_audio_embed
|
| 46 |
+
for i in range(st, ed)
|
| 47 |
+
], dim=0)
|
| 48 |
+
audio_emb_wind.append(wind_feat)
|
| 49 |
+
audio_emb_wind = torch.stack(audio_emb_wind, dim=0)
|
| 50 |
+
|
| 51 |
+
return audio_emb_wind, ed - audio_shift
|
| 52 |
+
|
| 53 |
+
class WhisperModelLoader:
|
| 54 |
+
@classmethod
|
| 55 |
+
def INPUT_TYPES(s):
|
| 56 |
+
return {
|
| 57 |
+
"required": {
|
| 58 |
+
"model": (folder_paths.get_filename_list("audio_encoders"), {"tooltip": "These models are loaded from the 'ComfyUI/models/audio_encoders' folder",}),
|
| 59 |
+
"base_precision": (["fp32", "bf16", "fp16"], {"default": "fp16"}),
|
| 60 |
+
"load_device": (["main_device", "offload_device"], {"default": "main_device", "tooltip": "Initial device to load the model to, NOT recommended with the larger models unless you have 48GB+ VRAM"}),
|
| 61 |
+
},
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
RETURN_TYPES = ("WHISPERMODEL",)
|
| 65 |
+
RETURN_NAMES = ("whisper_model", )
|
| 66 |
+
FUNCTION = "loadmodel"
|
| 67 |
+
CATEGORY = "WanVideoWrapper"
|
| 68 |
+
|
| 69 |
+
def loadmodel(self, model, base_precision, load_device):
|
| 70 |
+
from transformers import WhisperConfig, WhisperModel, WhisperFeatureExtractor
|
| 71 |
+
|
| 72 |
+
base_dtype = {"fp8_e4m3fn": torch.float8_e4m3fn, "fp8_e4m3fn_fast": torch.float8_e4m3fn, "bf16": torch.bfloat16, "fp16": torch.float16, "fp16_fast": torch.float16, "fp32": torch.float32}[base_precision]
|
| 73 |
+
|
| 74 |
+
if load_device == "offload_device":
|
| 75 |
+
transformer_load_device = offload_device
|
| 76 |
+
else:
|
| 77 |
+
transformer_load_device = device
|
| 78 |
+
|
| 79 |
+
config_path = os.path.join(script_directory, "whisper_config.json")
|
| 80 |
+
whisper_config = WhisperConfig(**json.load(open(config_path)))
|
| 81 |
+
|
| 82 |
+
with init_empty_weights():
|
| 83 |
+
whisper = WhisperModel(whisper_config).eval()
|
| 84 |
+
whisper.decoder = None # we only need the encoder
|
| 85 |
+
|
| 86 |
+
feature_extractor_config = {
|
| 87 |
+
"chunk_length": 30,
|
| 88 |
+
"feature_extractor_type": "WhisperFeatureExtractor",
|
| 89 |
+
"feature_size": 128,
|
| 90 |
+
"hop_length": 160,
|
| 91 |
+
"n_fft": 400,
|
| 92 |
+
"n_samples": 480000,
|
| 93 |
+
"nb_max_frames": 3000,
|
| 94 |
+
"padding_side": "right",
|
| 95 |
+
"padding_value": 0.0,
|
| 96 |
+
"processor_class": "WhisperProcessor",
|
| 97 |
+
"return_attention_mask": False,
|
| 98 |
+
"sampling_rate": 16000
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
feature_extractor = WhisperFeatureExtractor(**feature_extractor_config)
|
| 102 |
+
|
| 103 |
+
model_path = folder_paths.get_full_path_or_raise("audio_encoders", model)
|
| 104 |
+
sd = load_torch_file(model_path, device=transformer_load_device, safe_load=True)
|
| 105 |
+
|
| 106 |
+
for name, param in whisper.named_parameters():
|
| 107 |
+
key = "model." + name
|
| 108 |
+
value=sd[key]
|
| 109 |
+
set_module_tensor_to_device(whisper, name, device=offload_device, dtype=base_dtype, value=value)
|
| 110 |
+
|
| 111 |
+
whisper_model = {
|
| 112 |
+
"feature_extractor": feature_extractor,
|
| 113 |
+
"model": whisper,
|
| 114 |
+
"dtype": base_dtype,
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
return (whisper_model,)
|
| 118 |
+
|
| 119 |
+
class HuMoEmbeds:
|
| 120 |
+
@classmethod
|
| 121 |
+
def INPUT_TYPES(s):
|
| 122 |
+
return {"required": {
|
| 123 |
+
"num_frames": ("INT", {"default": 81, "min": -1, "max": 10000, "step": 1, "tooltip": "The total frame count to generate."}),
|
| 124 |
+
"width": ("INT", {"default": 832, "min": 64, "max": 4096, "step": 16}),
|
| 125 |
+
"height": ("INT", {"default": 480, "min": 64, "max": 4096, "step": 16}),
|
| 126 |
+
"audio_scale": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 100.0, "step": 0.01, "tooltip": "Strength of the audio conditioning"}),
|
| 127 |
+
"audio_cfg_scale": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 100.0, "step": 0.01, "tooltip": "When not 1.0, an extra model pass without audio conditioning is done: slower inference but more motion is allowed"}),
|
| 128 |
+
"audio_start_percent": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "The percent of the video to start applying audio conditioning"}),
|
| 129 |
+
"audio_end_percent": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "The percent of the video to stop applying audio conditioning"})
|
| 130 |
+
},
|
| 131 |
+
"optional" : {
|
| 132 |
+
"whisper_model": ("WHISPERMODEL",),
|
| 133 |
+
"vae": ("WANVAE", ),
|
| 134 |
+
"reference_images": ("IMAGE", {"tooltip": "reference images for the humo model"}),
|
| 135 |
+
"audio": ("AUDIO",),
|
| 136 |
+
"tiled_vae": ("BOOLEAN", {"default": False, "tooltip": "Use tiled VAE encoding for reduced memory use"}),
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
RETURN_TYPES = ("WANVIDIMAGE_EMBEDS", )
|
| 141 |
+
RETURN_NAMES = ("image_embeds", )
|
| 142 |
+
FUNCTION = "process"
|
| 143 |
+
CATEGORY = "WanVideoWrapper"
|
| 144 |
+
|
| 145 |
+
def process(self, num_frames, width, height, audio_scale, audio_cfg_scale, audio_start_percent, audio_end_percent, whisper_model=None, vae=None, reference_images=None, audio=None, tiled_vae=False):
|
| 146 |
+
if reference_images is not None and vae is None:
|
| 147 |
+
raise ValueError("VAE is required when reference images are provided")
|
| 148 |
+
if whisper_model is None and audio is not None:
|
| 149 |
+
raise ValueError("Whisper model is required when audio is provided")
|
| 150 |
+
model = whisper_model["model"]
|
| 151 |
+
feature_extractor = whisper_model["feature_extractor"]
|
| 152 |
+
dtype = whisper_model["dtype"]
|
| 153 |
+
|
| 154 |
+
sampling_rate = 16000
|
| 155 |
+
|
| 156 |
+
if audio is not None:
|
| 157 |
+
audio_input = audio["waveform"][0]
|
| 158 |
+
sample_rate = audio["sample_rate"]
|
| 159 |
+
|
| 160 |
+
if sample_rate != sampling_rate:
|
| 161 |
+
audio_input = torchaudio.functional.resample(audio_input, sample_rate, sampling_rate)
|
| 162 |
+
if audio_input.shape[1] == 2:
|
| 163 |
+
audio_input = audio_input.mean(dim=0, keepdim=False)
|
| 164 |
+
else:
|
| 165 |
+
audio_input = audio_input[0]
|
| 166 |
+
|
| 167 |
+
model.to(device)
|
| 168 |
+
audio_len = len(audio_input) // 640
|
| 169 |
+
|
| 170 |
+
# feature extraction
|
| 171 |
+
audio_features = []
|
| 172 |
+
window = 750*640
|
| 173 |
+
for i in range(0, len(audio_input), window):
|
| 174 |
+
audio_feature = feature_extractor(audio_input[i:i+window], sampling_rate=sampling_rate, return_tensors="pt").input_features
|
| 175 |
+
audio_features.append(audio_feature)
|
| 176 |
+
audio_features = torch.cat(audio_features, dim=-1).to(device, dtype)
|
| 177 |
+
|
| 178 |
+
# preprocess
|
| 179 |
+
window = 3000
|
| 180 |
+
audio_prompts = []
|
| 181 |
+
for i in range(0, audio_features.shape[-1], window):
|
| 182 |
+
audio_prompt = model.encoder(audio_features[:,:,i:i+window], output_hidden_states=True).hidden_states
|
| 183 |
+
audio_prompt = torch.stack(audio_prompt, dim=2)
|
| 184 |
+
audio_prompts.append(audio_prompt)
|
| 185 |
+
|
| 186 |
+
model.to(offload_device)
|
| 187 |
+
|
| 188 |
+
audio_prompts = torch.cat(audio_prompts, dim=1)
|
| 189 |
+
audio_prompts = audio_prompts[:,:audio_len*2]
|
| 190 |
+
|
| 191 |
+
feat0 = linear_interpolation_fps(audio_prompts[:, :, 0: 8].mean(dim=2), 50, 25)
|
| 192 |
+
feat1 = linear_interpolation_fps(audio_prompts[:, :, 8: 16].mean(dim=2), 50, 25)
|
| 193 |
+
feat2 = linear_interpolation_fps(audio_prompts[:, :, 16: 24].mean(dim=2), 50, 25)
|
| 194 |
+
feat3 = linear_interpolation_fps(audio_prompts[:, :, 24: 32].mean(dim=2), 50, 25)
|
| 195 |
+
feat4 = linear_interpolation_fps(audio_prompts[:, :, 32], 50, 25)
|
| 196 |
+
audio_emb = torch.stack([feat0, feat1, feat2, feat3, feat4], dim=2)[0] # [T, 5, 1280]
|
| 197 |
+
else:
|
| 198 |
+
audio_emb = torch.zeros(num_frames, 5, 1280, device=device)
|
| 199 |
+
audio_len = num_frames
|
| 200 |
+
|
| 201 |
+
pixel_frame_num = num_frames if num_frames != -1 else audio_len
|
| 202 |
+
pixel_frame_num = 4 * ((pixel_frame_num - 1) // 4) + 1
|
| 203 |
+
latent_frame_num = (pixel_frame_num - 1) // 4 + 1
|
| 204 |
+
|
| 205 |
+
log.info(f"HuMo set to generate {pixel_frame_num} frames")
|
| 206 |
+
|
| 207 |
+
#audio_emb, _ = get_audio_emb_window(audio_emb, pixel_frame_num, frame0_idx=0)
|
| 208 |
+
|
| 209 |
+
num_refs = 0
|
| 210 |
+
if reference_images is not None:
|
| 211 |
+
if reference_images.shape[1] != height or reference_images.shape[2] != width:
|
| 212 |
+
reference_images_in = common_upscale(reference_images.movedim(-1, 1), width, height, "lanczos", "disabled").movedim(1, -1)
|
| 213 |
+
else:
|
| 214 |
+
reference_images_in = reference_images
|
| 215 |
+
samples, = WanVideoEncodeLatentBatch.encode(self, vae, reference_images_in, tiled_vae, None, None, None, None)
|
| 216 |
+
samples = samples["samples"].transpose(0, 2).squeeze(0)
|
| 217 |
+
num_refs = samples.shape[1]
|
| 218 |
+
|
| 219 |
+
vae.to(device)
|
| 220 |
+
zero_frames = torch.zeros(1, 3, pixel_frame_num + 4*num_refs, height, width, device=device, dtype=vae.dtype)
|
| 221 |
+
zero_latents = vae.encode(zero_frames, device=device, tiled=tiled_vae)[0].to(offload_device)
|
| 222 |
+
|
| 223 |
+
vae.to(offload_device)
|
| 224 |
+
mm.soft_empty_cache()
|
| 225 |
+
|
| 226 |
+
target_shape = (16, latent_frame_num + num_refs, height // 8, width // 8)
|
| 227 |
+
|
| 228 |
+
mask = torch.ones(4, target_shape[1], target_shape[2], target_shape[3], device=offload_device, dtype=vae.dtype)
|
| 229 |
+
if reference_images is not None:
|
| 230 |
+
mask[:,:-num_refs] = 0
|
| 231 |
+
image_cond = torch.cat([zero_latents[:, :(target_shape[1]-num_refs)], samples], dim=1)
|
| 232 |
+
#zero_audio_pad = torch.zeros(num_refs, *audio_emb.shape[1:]).to(audio_emb.device)
|
| 233 |
+
#audio_emb = torch.cat([audio_emb, zero_audio_pad], dim=0)
|
| 234 |
+
else:
|
| 235 |
+
image_cond = zero_latents
|
| 236 |
+
mask = torch.zeros_like(mask)
|
| 237 |
+
image_cond = torch.cat([mask, image_cond], dim=0)
|
| 238 |
+
image_cond_neg = torch.cat([mask, zero_latents], dim=0)
|
| 239 |
+
|
| 240 |
+
embeds = {
|
| 241 |
+
"humo_audio_emb": audio_emb,
|
| 242 |
+
"humo_audio_emb_neg": torch.zeros_like(audio_emb, dtype=audio_emb.dtype, device=audio_emb.device),
|
| 243 |
+
"humo_image_cond": image_cond,
|
| 244 |
+
"humo_image_cond_neg": image_cond_neg,
|
| 245 |
+
"humo_reference_count": num_refs,
|
| 246 |
+
"target_shape": target_shape,
|
| 247 |
+
"num_frames": pixel_frame_num,
|
| 248 |
+
"humo_audio_scale": audio_scale,
|
| 249 |
+
"humo_audio_cfg_scale": audio_cfg_scale,
|
| 250 |
+
"humo_start_percent": audio_start_percent,
|
| 251 |
+
"humo_end_percent": audio_end_percent,
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
return (embeds, )
|
| 255 |
+
|
| 256 |
+
class WanVideoCombineEmbeds:
|
| 257 |
+
@classmethod
|
| 258 |
+
def INPUT_TYPES(s):
|
| 259 |
+
return {"required": {
|
| 260 |
+
"embeds_1": ("WANVIDIMAGE_EMBEDS",),
|
| 261 |
+
"embeds_2": ("WANVIDIMAGE_EMBEDS",),
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
RETURN_TYPES = ("WANVIDIMAGE_EMBEDS",)
|
| 266 |
+
RETURN_NAMES = ("image_embeds",)
|
| 267 |
+
FUNCTION = "add"
|
| 268 |
+
CATEGORY = "WanVideoWrapper"
|
| 269 |
+
EXPERIMENTAL = True
|
| 270 |
+
|
| 271 |
+
def add(self, embeds_1, embeds_2):
|
| 272 |
+
# Combine the two sets of embeds
|
| 273 |
+
combined = {**embeds_1, **embeds_2}
|
| 274 |
+
return (combined,)
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
NODE_CLASS_MAPPINGS = {
|
| 278 |
+
"WhisperModelLoader": WhisperModelLoader,
|
| 279 |
+
"HuMoEmbeds": HuMoEmbeds,
|
| 280 |
+
"WanVideoCombineEmbeds": WanVideoCombineEmbeds,
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
NODE_DISPLAY_NAME_MAPPINGS = {
|
| 284 |
+
"WhisperModelLoader": "Whisper Model Loader",
|
| 285 |
+
"HuMoEmbeds": "HuMo Embeds",
|
| 286 |
+
"WanVideoCombineEmbeds": "WanVideo Combine Embeds",
|
| 287 |
+
}
|
custom_nodes/ComfyUI-WanVideoWrapper/HuMo/whisper_config.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "openai/whisper-large-v3",
|
| 3 |
+
"activation_dropout": 0.0,
|
| 4 |
+
"activation_function": "gelu",
|
| 5 |
+
"apply_spec_augment": false,
|
| 6 |
+
"architectures": [
|
| 7 |
+
"WhisperForConditionalGeneration"
|
| 8 |
+
],
|
| 9 |
+
"attention_dropout": 0.0,
|
| 10 |
+
"begin_suppress_tokens": [
|
| 11 |
+
220,
|
| 12 |
+
50257
|
| 13 |
+
],
|
| 14 |
+
"bos_token_id": 50257,
|
| 15 |
+
"classifier_proj_size": 256,
|
| 16 |
+
"d_model": 1280,
|
| 17 |
+
"decoder_attention_heads": 20,
|
| 18 |
+
"decoder_ffn_dim": 5120,
|
| 19 |
+
"decoder_layerdrop": 0.0,
|
| 20 |
+
"decoder_layers": 32,
|
| 21 |
+
"decoder_start_token_id": 50258,
|
| 22 |
+
"dropout": 0.0,
|
| 23 |
+
"encoder_attention_heads": 20,
|
| 24 |
+
"encoder_ffn_dim": 5120,
|
| 25 |
+
"encoder_layerdrop": 0.0,
|
| 26 |
+
"encoder_layers": 32,
|
| 27 |
+
"eos_token_id": 50257,
|
| 28 |
+
"init_std": 0.02,
|
| 29 |
+
"is_encoder_decoder": true,
|
| 30 |
+
"mask_feature_length": 10,
|
| 31 |
+
"mask_feature_min_masks": 0,
|
| 32 |
+
"mask_feature_prob": 0.0,
|
| 33 |
+
"mask_time_length": 10,
|
| 34 |
+
"mask_time_min_masks": 2,
|
| 35 |
+
"mask_time_prob": 0.05,
|
| 36 |
+
"max_length": 448,
|
| 37 |
+
"max_source_positions": 1500,
|
| 38 |
+
"max_target_positions": 448,
|
| 39 |
+
"median_filter_width": 7,
|
| 40 |
+
"model_type": "whisper",
|
| 41 |
+
"num_hidden_layers": 32,
|
| 42 |
+
"num_mel_bins": 128,
|
| 43 |
+
"pad_token_id": 50256,
|
| 44 |
+
"scale_embedding": false,
|
| 45 |
+
"torch_dtype": "float16",
|
| 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright [yyyy] [name of copyright owner]
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
custom_nodes/ComfyUI-WanVideoWrapper/LongCat/__pycache__/nodes.cpython-313.pyc
ADDED
|
Binary file (18.9 kB). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/LongCat/layers.py
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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+
import math
|
| 5 |
+
from einops import rearrange
|
| 6 |
+
|
| 7 |
+
from ..wanvideo.modules.model import WanRMSNorm, attention
|
| 8 |
+
from ..multitalk.multitalk import RotaryPositionalEmbedding1D, normalize_and_scale
|
| 9 |
+
|
| 10 |
+
class FeedForwardSwiGLU(nn.Module):
|
| 11 |
+
def __init__(
|
| 12 |
+
self,
|
| 13 |
+
dim: int,
|
| 14 |
+
hidden_dim: int,
|
| 15 |
+
multiple_of: int = 256,
|
| 16 |
+
):
|
| 17 |
+
super().__init__()
|
| 18 |
+
hidden_dim = int(2 * hidden_dim / 3)
|
| 19 |
+
hidden_dim = multiple_of * ((hidden_dim + multiple_of - 1) // multiple_of)
|
| 20 |
+
|
| 21 |
+
self.dim = dim
|
| 22 |
+
self.hidden_dim = hidden_dim
|
| 23 |
+
self.w1 = nn.Linear(dim, hidden_dim, bias=False)
|
| 24 |
+
self.w2 = nn.Linear(hidden_dim, dim, bias=False)
|
| 25 |
+
self.w3 = nn.Linear(dim, hidden_dim, bias=False)
|
| 26 |
+
|
| 27 |
+
def forward(self, x):
|
| 28 |
+
return self.w2(F.silu(self.w1(x)) * self.w3(x))
|
| 29 |
+
|
| 30 |
+
class TimestepEmbedder(nn.Module):
|
| 31 |
+
"""
|
| 32 |
+
Embeds scalar timesteps into vector representations.
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
def __init__(self, t_embed_dim, frequency_embedding_size=256):
|
| 36 |
+
super().__init__()
|
| 37 |
+
self.t_embed_dim = t_embed_dim
|
| 38 |
+
self.frequency_embedding_size = frequency_embedding_size
|
| 39 |
+
self.mlp = nn.Sequential(
|
| 40 |
+
nn.Linear(frequency_embedding_size, t_embed_dim, bias=True),
|
| 41 |
+
nn.SiLU(),
|
| 42 |
+
nn.Linear(t_embed_dim, t_embed_dim, bias=True),
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
@staticmethod
|
| 46 |
+
def timestep_embedding(t, dim, max_period=10000):
|
| 47 |
+
"""
|
| 48 |
+
Create sinusoidal timestep embeddings.
|
| 49 |
+
:param t: a 1-D Tensor of N indices, one per batch element.
|
| 50 |
+
These may be fractional.
|
| 51 |
+
:param dim: the dimension of the output.
|
| 52 |
+
:param max_period: controls the minimum frequency of the embeddings.
|
| 53 |
+
:return: an (N, D) Tensor of positional embeddings.
|
| 54 |
+
"""
|
| 55 |
+
half = dim // 2
|
| 56 |
+
freqs = torch.exp(-math.log(max_period) * torch.arange(start=0, end=half, dtype=torch.float32) / half)
|
| 57 |
+
freqs = freqs.to(device=t.device)
|
| 58 |
+
args = t[:, None].float() * freqs[None]
|
| 59 |
+
embedding = torch.cat([torch.cos(args), torch.sin(args)], dim=-1)
|
| 60 |
+
if dim % 2:
|
| 61 |
+
embedding = torch.cat([embedding, torch.zeros_like(embedding[:, :1])], dim=-1)
|
| 62 |
+
return embedding
|
| 63 |
+
|
| 64 |
+
def forward(self, t, dtype):
|
| 65 |
+
t_freq = self.timestep_embedding(t, self.frequency_embedding_size)
|
| 66 |
+
if t_freq.dtype != dtype:
|
| 67 |
+
t_freq = t_freq.to(dtype)
|
| 68 |
+
t_emb = self.mlp(t_freq)
|
| 69 |
+
return t_emb
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class SingleStreamAttention(nn.Module):
|
| 73 |
+
def __init__(
|
| 74 |
+
self,
|
| 75 |
+
dim: int,
|
| 76 |
+
encoder_hidden_states_dim: int,
|
| 77 |
+
num_heads: int,
|
| 78 |
+
qkv_bias: bool,
|
| 79 |
+
qk_norm: bool,
|
| 80 |
+
attn_drop: float = 0.0,
|
| 81 |
+
proj_drop: float = 0.0,
|
| 82 |
+
eps: float = 1e-6,
|
| 83 |
+
class_range: int = 24,
|
| 84 |
+
class_interval: int = 4,
|
| 85 |
+
attention_mode: str = "sdpa",
|
| 86 |
+
) -> None:
|
| 87 |
+
super().__init__()
|
| 88 |
+
assert dim % num_heads == 0, "dim should be divisible by num_heads"
|
| 89 |
+
self.dim = dim
|
| 90 |
+
self.encoder_hidden_states_dim = encoder_hidden_states_dim
|
| 91 |
+
self.num_heads = num_heads
|
| 92 |
+
self.head_dim = dim // num_heads
|
| 93 |
+
self.scale = self.head_dim**-0.5
|
| 94 |
+
|
| 95 |
+
self.q_linear = nn.Linear(dim, dim, bias=qkv_bias)
|
| 96 |
+
self.q_norm = WanRMSNorm(self.head_dim, eps=eps) if qk_norm else nn.Identity()
|
| 97 |
+
|
| 98 |
+
self.attn_drop = nn.Dropout(attn_drop)
|
| 99 |
+
self.proj = nn.Linear(dim, dim)
|
| 100 |
+
self.proj_drop = nn.Dropout(proj_drop)
|
| 101 |
+
|
| 102 |
+
self.kv_linear = nn.Linear(encoder_hidden_states_dim, dim * 2, bias=qkv_bias)
|
| 103 |
+
self.k_norm = WanRMSNorm(self.head_dim, eps=eps) if qk_norm else nn.Identity()
|
| 104 |
+
|
| 105 |
+
self.attention_mode = attention_mode
|
| 106 |
+
|
| 107 |
+
# multitalk related params
|
| 108 |
+
self.class_interval = class_interval
|
| 109 |
+
self.class_range = class_range
|
| 110 |
+
self.rope_h1 = (0, self.class_interval)
|
| 111 |
+
self.rope_h2 = (self.class_range - self.class_interval, self.class_range)
|
| 112 |
+
self.rope_bak = int(self.class_range // 2)
|
| 113 |
+
self.rope_1d = RotaryPositionalEmbedding1D(self.head_dim)
|
| 114 |
+
|
| 115 |
+
def _process_cross_attn(self, x, cond, frames_num=None, x_ref_attn_map=None):
|
| 116 |
+
|
| 117 |
+
N_t = frames_num
|
| 118 |
+
out_dtype = x.dtype
|
| 119 |
+
x = rearrange(x, "B (N_t S) C -> (B N_t) S C", N_t=N_t)
|
| 120 |
+
|
| 121 |
+
# get q for hidden_state
|
| 122 |
+
B, N, C = x.shape
|
| 123 |
+
q = self.q_linear(x)
|
| 124 |
+
q_shape = (B, N, self.num_heads, self.head_dim)
|
| 125 |
+
q = q.view(q_shape).permute((0, 2, 1, 3)) # [B, H, N, D]
|
| 126 |
+
q = self.q_norm(q.to(self.q_norm.weight.dtype)).to(q.dtype)
|
| 127 |
+
|
| 128 |
+
# multitalk with rope1d pe
|
| 129 |
+
if x_ref_attn_map is not None:
|
| 130 |
+
max_values = x_ref_attn_map.max(1).values[:, None, None]
|
| 131 |
+
min_values = x_ref_attn_map.min(1).values[:, None, None]
|
| 132 |
+
max_min_values = torch.cat([max_values, min_values], dim=2)
|
| 133 |
+
human1_max_value, human1_min_value = max_min_values[0, :, 0].max(), max_min_values[0, :, 1].min()
|
| 134 |
+
human2_max_value, human2_min_value = max_min_values[1, :, 0].max(), max_min_values[1, :, 1].min()
|
| 135 |
+
|
| 136 |
+
human1 = normalize_and_scale(x_ref_attn_map[0], (human1_min_value, human1_max_value), (self.rope_h1[0], self.rope_h1[1]))
|
| 137 |
+
human2 = normalize_and_scale(x_ref_attn_map[1], (human2_min_value, human2_max_value), (self.rope_h2[0], self.rope_h2[1]))
|
| 138 |
+
back = torch.full((x_ref_attn_map.size(1),), self.rope_bak, dtype=human1.dtype).to(human1.device)
|
| 139 |
+
max_indices = x_ref_attn_map.argmax(dim=0)
|
| 140 |
+
normalized_map = torch.stack([human1, human2, back], dim=1)
|
| 141 |
+
normalized_pos = normalized_map[range(x_ref_attn_map.size(1)), max_indices]
|
| 142 |
+
|
| 143 |
+
q = rearrange(q, "(B N_t) H S C -> B H (N_t S) C", N_t=N_t)
|
| 144 |
+
q = self.rope_1d(q, normalized_pos)
|
| 145 |
+
q = rearrange(q, "B H (N_t S) C -> (B N_t) H S C", N_t=N_t)
|
| 146 |
+
|
| 147 |
+
# get kv from encoder_hidden_states
|
| 148 |
+
_, N_a, _ = cond.shape
|
| 149 |
+
encoder_kv = self.kv_linear(cond)
|
| 150 |
+
encoder_kv_shape = (B, N_a, 2, self.num_heads, self.head_dim)
|
| 151 |
+
encoder_kv = encoder_kv.view(encoder_kv_shape).permute((2, 0, 3, 1, 4))
|
| 152 |
+
|
| 153 |
+
encoder_k, encoder_v = encoder_kv.unbind(0)
|
| 154 |
+
encoder_k = self.k_norm(encoder_k.to(self.k_norm.weight.dtype)).to(encoder_k.dtype)
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
# multitalk with rope1d pe
|
| 158 |
+
if x_ref_attn_map is not None:
|
| 159 |
+
per_frame = torch.zeros(N_a, dtype=encoder_k.dtype).to(encoder_k.device)
|
| 160 |
+
per_frame[:per_frame.size(0)//2] = (self.rope_h1[0] + self.rope_h1[1]) / 2
|
| 161 |
+
per_frame[per_frame.size(0)//2:] = (self.rope_h2[0] + self.rope_h2[1]) / 2
|
| 162 |
+
encoder_pos = torch.concat([per_frame]*N_t, dim=0)
|
| 163 |
+
encoder_k = rearrange(encoder_k, "(B N_t) H S C -> B H (N_t S) C", N_t=N_t)
|
| 164 |
+
encoder_k = self.rope_1d(encoder_k, encoder_pos)
|
| 165 |
+
encoder_k = rearrange(encoder_k, "B H (N_t S) C -> (B N_t) H S C", N_t=N_t)
|
| 166 |
+
|
| 167 |
+
# Input tensors must be in format ``[B, M, H, K]``, where B is the batch size, M \
|
| 168 |
+
# the sequence length, H the number of heads, and K the embeding size per head
|
| 169 |
+
|
| 170 |
+
q = rearrange(q, "B H M K -> B M H K")
|
| 171 |
+
encoder_k = rearrange(encoder_k, "B H M K -> B M H K")
|
| 172 |
+
encoder_v = rearrange(encoder_v, "B H M K -> B M H K")
|
| 173 |
+
x = attention(q, encoder_k, encoder_v, attention_mode=self.attention_mode)
|
| 174 |
+
x = rearrange(x, "B M H K -> B H M K")
|
| 175 |
+
|
| 176 |
+
# linear transform
|
| 177 |
+
x_output_shape = (B, N, C)
|
| 178 |
+
x = x.transpose(1, 2)
|
| 179 |
+
x = x.reshape(x_output_shape)
|
| 180 |
+
x = self.proj(x)
|
| 181 |
+
x = self.proj_drop(x)
|
| 182 |
+
|
| 183 |
+
# reshape x to origin shape
|
| 184 |
+
x = rearrange(x, "(B N_t) S C -> B (N_t S) C", N_t=N_t)
|
| 185 |
+
|
| 186 |
+
return x.type(out_dtype)
|
| 187 |
+
|
| 188 |
+
def forward(self, x, cond, num_latent_frames=None, num_cond_latents=None, x_ref_attn_map=None, human_num=None):
|
| 189 |
+
|
| 190 |
+
B, N, C = x.shape
|
| 191 |
+
if (num_cond_latents is None or num_cond_latents == 0):
|
| 192 |
+
# text to video
|
| 193 |
+
output = self._process_cross_attn(x, cond, num_latent_frames, x_ref_attn_map)
|
| 194 |
+
return None, output
|
| 195 |
+
elif num_cond_latents is not None and num_cond_latents > 0:
|
| 196 |
+
# image to video or video continuation
|
| 197 |
+
num_cond_latents_thw = num_cond_latents * (N // num_latent_frames)
|
| 198 |
+
x_noise = x[:, num_cond_latents_thw:]
|
| 199 |
+
cond = rearrange(cond, "(B N_t) M C -> B N_t M C", B=B)
|
| 200 |
+
cond = cond[:, num_cond_latents:]
|
| 201 |
+
cond = rearrange(cond, "B N_t M C -> (B N_t) M C")
|
| 202 |
+
frames_num = num_latent_frames - num_cond_latents
|
| 203 |
+
if human_num is not None and human_num == 2:
|
| 204 |
+
# multitalk mode
|
| 205 |
+
output_noise = self._process_cross_attn(x_noise, cond, frames_num, x_ref_attn_map)
|
| 206 |
+
else:
|
| 207 |
+
# singletalk mode
|
| 208 |
+
output_noise = self._process_cross_attn(x_noise, cond, frames_num)
|
| 209 |
+
output_cond = torch.zeros((B, num_cond_latents_thw, C), dtype=output_noise.dtype, device=output_noise.device)
|
| 210 |
+
return output_cond, output_noise
|
| 211 |
+
else:
|
| 212 |
+
raise NotImplementedError
|
custom_nodes/ComfyUI-WanVideoWrapper/LongCat/longcat_i2v_testing.json
ADDED
|
@@ -0,0 +1,1292 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"id": "c6e410bc-5e2c-460b-ae81-c91b6094fbb1",
|
| 3 |
+
"revision": 0,
|
| 4 |
+
"last_node_id": 132,
|
| 5 |
+
"last_link_id": 226,
|
| 6 |
+
"nodes": [
|
| 7 |
+
{
|
| 8 |
+
"id": 103,
|
| 9 |
+
"type": "WanVideoSetBlockSwap",
|
| 10 |
+
"pos": [
|
| 11 |
+
198.53674831201326,
|
| 12 |
+
-432.11760852542864
|
| 13 |
+
],
|
| 14 |
+
"size": [
|
| 15 |
+
201.7681640625,
|
| 16 |
+
46
|
| 17 |
+
],
|
| 18 |
+
"flags": {},
|
| 19 |
+
"order": 15,
|
| 20 |
+
"mode": 0,
|
| 21 |
+
"inputs": [
|
| 22 |
+
{
|
| 23 |
+
"name": "model",
|
| 24 |
+
"type": "WANVIDEOMODEL",
|
| 25 |
+
"link": 213
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"name": "block_swap_args",
|
| 29 |
+
"shape": 7,
|
| 30 |
+
"type": "BLOCKSWAPARGS",
|
| 31 |
+
"link": 185
|
| 32 |
+
}
|
| 33 |
+
],
|
| 34 |
+
"outputs": [
|
| 35 |
+
{
|
| 36 |
+
"name": "model",
|
| 37 |
+
"type": "WANVIDEOMODEL",
|
| 38 |
+
"links": [
|
| 39 |
+
184
|
| 40 |
+
]
|
| 41 |
+
}
|
| 42 |
+
],
|
| 43 |
+
"properties": {
|
| 44 |
+
"cnr_id": "ComfyUI-WanVideoWrapper",
|
| 45 |
+
"ver": "d74cfc54e8ae065d7f32b36634be770bae525f5c",
|
| 46 |
+
"Node name for S&R": "WanVideoSetBlockSwap"
|
| 47 |
+
},
|
| 48 |
+
"widgets_values": []
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"id": 100,
|
| 52 |
+
"type": "PreviewAny",
|
| 53 |
+
"pos": [
|
| 54 |
+
907.0976743062528,
|
| 55 |
+
-296.3914196167795
|
| 56 |
+
],
|
| 57 |
+
"size": [
|
| 58 |
+
472.0564346168338,
|
| 59 |
+
212.24735250897345
|
| 60 |
+
],
|
| 61 |
+
"flags": {},
|
| 62 |
+
"order": 17,
|
| 63 |
+
"mode": 0,
|
| 64 |
+
"inputs": [
|
| 65 |
+
{
|
| 66 |
+
"name": "source",
|
| 67 |
+
"type": "*",
|
| 68 |
+
"link": 181
|
| 69 |
+
}
|
| 70 |
+
],
|
| 71 |
+
"outputs": [],
|
| 72 |
+
"properties": {
|
| 73 |
+
"cnr_id": "comfy-core",
|
| 74 |
+
"ver": "0.3.65",
|
| 75 |
+
"Node name for S&R": "PreviewAny"
|
| 76 |
+
},
|
| 77 |
+
"widgets_values": []
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"id": 109,
|
| 81 |
+
"type": "WanVideoDecode",
|
| 82 |
+
"pos": [
|
| 83 |
+
960.889179440407,
|
| 84 |
+
-582.2131207638263
|
| 85 |
+
],
|
| 86 |
+
"size": [
|
| 87 |
+
270,
|
| 88 |
+
198
|
| 89 |
+
],
|
| 90 |
+
"flags": {},
|
| 91 |
+
"order": 18,
|
| 92 |
+
"mode": 0,
|
| 93 |
+
"inputs": [
|
| 94 |
+
{
|
| 95 |
+
"name": "vae",
|
| 96 |
+
"type": "WANVAE",
|
| 97 |
+
"link": 196
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
"name": "samples",
|
| 101 |
+
"type": "LATENT",
|
| 102 |
+
"link": 197
|
| 103 |
+
}
|
| 104 |
+
],
|
| 105 |
+
"outputs": [
|
| 106 |
+
{
|
| 107 |
+
"name": "images",
|
| 108 |
+
"type": "IMAGE",
|
| 109 |
+
"links": [
|
| 110 |
+
201
|
| 111 |
+
]
|
| 112 |
+
}
|
| 113 |
+
],
|
| 114 |
+
"properties": {
|
| 115 |
+
"cnr_id": "ComfyUI-WanVideoWrapper",
|
| 116 |
+
"ver": "d74cfc54e8ae065d7f32b36634be770bae525f5c",
|
| 117 |
+
"Node name for S&R": "WanVideoDecode"
|
| 118 |
+
},
|
| 119 |
+
"widgets_values": [
|
| 120 |
+
false,
|
| 121 |
+
272,
|
| 122 |
+
272,
|
| 123 |
+
144,
|
| 124 |
+
128,
|
| 125 |
+
"default"
|
| 126 |
+
]
|
| 127 |
+
},
|
| 128 |
+
{
|
| 129 |
+
"id": 108,
|
| 130 |
+
"type": "WanVideoVAELoader",
|
| 131 |
+
"pos": [
|
| 132 |
+
701.274488676777,
|
| 133 |
+
-753.3785231063376
|
| 134 |
+
],
|
| 135 |
+
"size": [
|
| 136 |
+
270,
|
| 137 |
+
82
|
| 138 |
+
],
|
| 139 |
+
"flags": {},
|
| 140 |
+
"order": 0,
|
| 141 |
+
"mode": 0,
|
| 142 |
+
"inputs": [
|
| 143 |
+
{
|
| 144 |
+
"name": "compile_args",
|
| 145 |
+
"shape": 7,
|
| 146 |
+
"type": "WANCOMPILEARGS",
|
| 147 |
+
"link": null
|
| 148 |
+
}
|
| 149 |
+
],
|
| 150 |
+
"outputs": [
|
| 151 |
+
{
|
| 152 |
+
"name": "vae",
|
| 153 |
+
"type": "WANVAE",
|
| 154 |
+
"links": [
|
| 155 |
+
196,
|
| 156 |
+
216
|
| 157 |
+
]
|
| 158 |
+
}
|
| 159 |
+
],
|
| 160 |
+
"properties": {
|
| 161 |
+
"cnr_id": "ComfyUI-WanVideoWrapper",
|
| 162 |
+
"ver": "d74cfc54e8ae065d7f32b36634be770bae525f5c",
|
| 163 |
+
"Node name for S&R": "WanVideoVAELoader"
|
| 164 |
+
},
|
| 165 |
+
"widgets_values": [
|
| 166 |
+
"wanvideo\\Wan2_1_VAE_bf16.safetensors",
|
| 167 |
+
"bf16"
|
| 168 |
+
]
|
| 169 |
+
},
|
| 170 |
+
{
|
| 171 |
+
"id": 126,
|
| 172 |
+
"type": "LoadImage",
|
| 173 |
+
"pos": [
|
| 174 |
+
-1116.7882775583114,
|
| 175 |
+
19.526640428041055
|
| 176 |
+
],
|
| 177 |
+
"size": [
|
| 178 |
+
274.080078125,
|
| 179 |
+
314
|
| 180 |
+
],
|
| 181 |
+
"flags": {},
|
| 182 |
+
"order": 1,
|
| 183 |
+
"mode": 0,
|
| 184 |
+
"inputs": [],
|
| 185 |
+
"outputs": [
|
| 186 |
+
{
|
| 187 |
+
"name": "IMAGE",
|
| 188 |
+
"type": "IMAGE",
|
| 189 |
+
"links": []
|
| 190 |
+
},
|
| 191 |
+
{
|
| 192 |
+
"name": "MASK",
|
| 193 |
+
"type": "MASK",
|
| 194 |
+
"links": null
|
| 195 |
+
}
|
| 196 |
+
],
|
| 197 |
+
"properties": {
|
| 198 |
+
"cnr_id": "comfy-core",
|
| 199 |
+
"ver": "0.3.65",
|
| 200 |
+
"Node name for S&R": "LoadImage"
|
| 201 |
+
},
|
| 202 |
+
"widgets_values": [
|
| 203 |
+
"oldman_upscaled.png",
|
| 204 |
+
"image"
|
| 205 |
+
]
|
| 206 |
+
},
|
| 207 |
+
{
|
| 208 |
+
"id": 102,
|
| 209 |
+
"type": "WanVideoEmptyEmbeds",
|
| 210 |
+
"pos": [
|
| 211 |
+
-256.9952824373617,
|
| 212 |
+
-28.552965594186407
|
| 213 |
+
],
|
| 214 |
+
"size": [
|
| 215 |
+
272.431640625,
|
| 216 |
+
126
|
| 217 |
+
],
|
| 218 |
+
"flags": {},
|
| 219 |
+
"order": 14,
|
| 220 |
+
"mode": 0,
|
| 221 |
+
"inputs": [
|
| 222 |
+
{
|
| 223 |
+
"name": "control_embeds",
|
| 224 |
+
"shape": 7,
|
| 225 |
+
"type": "WANVIDIMAGE_EMBEDS",
|
| 226 |
+
"link": null
|
| 227 |
+
},
|
| 228 |
+
{
|
| 229 |
+
"name": "extra_latents",
|
| 230 |
+
"shape": 7,
|
| 231 |
+
"type": "LATENT",
|
| 232 |
+
"link": 217
|
| 233 |
+
},
|
| 234 |
+
{
|
| 235 |
+
"name": "width",
|
| 236 |
+
"type": "INT",
|
| 237 |
+
"widget": {
|
| 238 |
+
"name": "width"
|
| 239 |
+
},
|
| 240 |
+
"link": 221
|
| 241 |
+
},
|
| 242 |
+
{
|
| 243 |
+
"name": "height",
|
| 244 |
+
"type": "INT",
|
| 245 |
+
"widget": {
|
| 246 |
+
"name": "height"
|
| 247 |
+
},
|
| 248 |
+
"link": 222
|
| 249 |
+
}
|
| 250 |
+
],
|
| 251 |
+
"outputs": [
|
| 252 |
+
{
|
| 253 |
+
"name": "image_embeds",
|
| 254 |
+
"type": "WANVIDIMAGE_EMBEDS",
|
| 255 |
+
"links": [
|
| 256 |
+
182
|
| 257 |
+
]
|
| 258 |
+
}
|
| 259 |
+
],
|
| 260 |
+
"properties": {
|
| 261 |
+
"cnr_id": "ComfyUI-WanVideoWrapper",
|
| 262 |
+
"ver": "d74cfc54e8ae065d7f32b36634be770bae525f5c",
|
| 263 |
+
"Node name for S&R": "WanVideoEmptyEmbeds"
|
| 264 |
+
},
|
| 265 |
+
"widgets_values": [
|
| 266 |
+
832,
|
| 267 |
+
480,
|
| 268 |
+
93
|
| 269 |
+
]
|
| 270 |
+
},
|
| 271 |
+
{
|
| 272 |
+
"id": 125,
|
| 273 |
+
"type": "WanVideoEncode",
|
| 274 |
+
"pos": [
|
| 275 |
+
-244.74550735895536,
|
| 276 |
+
169.6444951142907
|
| 277 |
+
],
|
| 278 |
+
"size": [
|
| 279 |
+
270,
|
| 280 |
+
242
|
| 281 |
+
],
|
| 282 |
+
"flags": {},
|
| 283 |
+
"order": 12,
|
| 284 |
+
"mode": 0,
|
| 285 |
+
"inputs": [
|
| 286 |
+
{
|
| 287 |
+
"name": "vae",
|
| 288 |
+
"type": "WANVAE",
|
| 289 |
+
"link": 216
|
| 290 |
+
},
|
| 291 |
+
{
|
| 292 |
+
"name": "image",
|
| 293 |
+
"type": "IMAGE",
|
| 294 |
+
"link": 220
|
| 295 |
+
},
|
| 296 |
+
{
|
| 297 |
+
"name": "mask",
|
| 298 |
+
"shape": 7,
|
| 299 |
+
"type": "MASK",
|
| 300 |
+
"link": null
|
| 301 |
+
}
|
| 302 |
+
],
|
| 303 |
+
"outputs": [
|
| 304 |
+
{
|
| 305 |
+
"name": "samples",
|
| 306 |
+
"type": "LATENT",
|
| 307 |
+
"links": [
|
| 308 |
+
217
|
| 309 |
+
]
|
| 310 |
+
}
|
| 311 |
+
],
|
| 312 |
+
"properties": {
|
| 313 |
+
"cnr_id": "ComfyUI-WanVideoWrapper",
|
| 314 |
+
"ver": "d74cfc54e8ae065d7f32b36634be770bae525f5c",
|
| 315 |
+
"Node name for S&R": "WanVideoEncode"
|
| 316 |
+
},
|
| 317 |
+
"widgets_values": [
|
| 318 |
+
false,
|
| 319 |
+
272,
|
| 320 |
+
272,
|
| 321 |
+
144,
|
| 322 |
+
128,
|
| 323 |
+
0,
|
| 324 |
+
1
|
| 325 |
+
]
|
| 326 |
+
},
|
| 327 |
+
{
|
| 328 |
+
"id": 104,
|
| 329 |
+
"type": "WanVideoBlockSwap",
|
| 330 |
+
"pos": [
|
| 331 |
+
98.54766191748722,
|
| 332 |
+
-271.15222752636595
|
| 333 |
+
],
|
| 334 |
+
"size": [
|
| 335 |
+
281.404296875,
|
| 336 |
+
202
|
| 337 |
+
],
|
| 338 |
+
"flags": {},
|
| 339 |
+
"order": 2,
|
| 340 |
+
"mode": 0,
|
| 341 |
+
"inputs": [],
|
| 342 |
+
"outputs": [
|
| 343 |
+
{
|
| 344 |
+
"name": "block_swap_args",
|
| 345 |
+
"type": "BLOCKSWAPARGS",
|
| 346 |
+
"links": [
|
| 347 |
+
185
|
| 348 |
+
]
|
| 349 |
+
}
|
| 350 |
+
],
|
| 351 |
+
"properties": {
|
| 352 |
+
"cnr_id": "ComfyUI-WanVideoWrapper",
|
| 353 |
+
"ver": "d74cfc54e8ae065d7f32b36634be770bae525f5c",
|
| 354 |
+
"Node name for S&R": "WanVideoBlockSwap"
|
| 355 |
+
},
|
| 356 |
+
"widgets_values": [
|
| 357 |
+
28,
|
| 358 |
+
false,
|
| 359 |
+
false,
|
| 360 |
+
true,
|
| 361 |
+
0,
|
| 362 |
+
1,
|
| 363 |
+
false
|
| 364 |
+
]
|
| 365 |
+
},
|
| 366 |
+
{
|
| 367 |
+
"id": 129,
|
| 368 |
+
"type": "LoadImage",
|
| 369 |
+
"pos": [
|
| 370 |
+
-1031.8897272515296,
|
| 371 |
+
413.40841462982775
|
| 372 |
+
],
|
| 373 |
+
"size": [
|
| 374 |
+
392.9949805443068,
|
| 375 |
+
314
|
| 376 |
+
],
|
| 377 |
+
"flags": {},
|
| 378 |
+
"order": 3,
|
| 379 |
+
"mode": 0,
|
| 380 |
+
"inputs": [],
|
| 381 |
+
"outputs": [
|
| 382 |
+
{
|
| 383 |
+
"name": "IMAGE",
|
| 384 |
+
"type": "IMAGE",
|
| 385 |
+
"links": [
|
| 386 |
+
224
|
| 387 |
+
]
|
| 388 |
+
},
|
| 389 |
+
{
|
| 390 |
+
"name": "MASK",
|
| 391 |
+
"type": "MASK",
|
| 392 |
+
"links": null
|
| 393 |
+
}
|
| 394 |
+
],
|
| 395 |
+
"properties": {
|
| 396 |
+
"cnr_id": "comfy-core",
|
| 397 |
+
"ver": "0.3.65",
|
| 398 |
+
"Node name for S&R": "LoadImage"
|
| 399 |
+
},
|
| 400 |
+
"widgets_values": [
|
| 401 |
+
"pasted/image (1019).png",
|
| 402 |
+
"image"
|
| 403 |
+
]
|
| 404 |
+
},
|
| 405 |
+
{
|
| 406 |
+
"id": 107,
|
| 407 |
+
"type": "WanVideoTextEncodeCached",
|
| 408 |
+
"pos": [
|
| 409 |
+
-1750.2604021841967,
|
| 410 |
+
-323.41929541822685
|
| 411 |
+
],
|
| 412 |
+
"size": [
|
| 413 |
+
618.665832961123,
|
| 414 |
+
642.6927334053207
|
| 415 |
+
],
|
| 416 |
+
"flags": {},
|
| 417 |
+
"order": 4,
|
| 418 |
+
"mode": 0,
|
| 419 |
+
"inputs": [
|
| 420 |
+
{
|
| 421 |
+
"name": "extender_args",
|
| 422 |
+
"shape": 7,
|
| 423 |
+
"type": "WANVIDEOPROMPTEXTENDER_ARGS",
|
| 424 |
+
"link": null
|
| 425 |
+
}
|
| 426 |
+
],
|
| 427 |
+
"outputs": [
|
| 428 |
+
{
|
| 429 |
+
"name": "text_embeds",
|
| 430 |
+
"type": "WANVIDEOTEXTEMBEDS",
|
| 431 |
+
"links": [
|
| 432 |
+
208
|
| 433 |
+
]
|
| 434 |
+
},
|
| 435 |
+
{
|
| 436 |
+
"name": "negative_text_embeds",
|
| 437 |
+
"type": "WANVIDEOTEXTEMBEDS",
|
| 438 |
+
"links": null
|
| 439 |
+
},
|
| 440 |
+
{
|
| 441 |
+
"name": "positive_prompt",
|
| 442 |
+
"type": "STRING",
|
| 443 |
+
"links": null
|
| 444 |
+
}
|
| 445 |
+
],
|
| 446 |
+
"properties": {
|
| 447 |
+
"cnr_id": "ComfyUI-WanVideoWrapper",
|
| 448 |
+
"ver": "d74cfc54e8ae065d7f32b36634be770bae525f5c",
|
| 449 |
+
"Node name for S&R": "WanVideoTextEncodeCached"
|
| 450 |
+
},
|
| 451 |
+
"widgets_values": [
|
| 452 |
+
"umt5-xxl-enc-bf16.safetensors",
|
| 453 |
+
"bf16",
|
| 454 |
+
"A woman sits at a wooden table by the window in a cozy café. She reaches out with her right hand, picks up the white coffee cup from the saucer, and gently brings it to her lips to take a sip. After drinking, she places the cup back on the table and looks out the window, enjoying the peaceful atmosphere.\n",
|
| 455 |
+
"Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards",
|
| 456 |
+
"disabled",
|
| 457 |
+
true,
|
| 458 |
+
"gpu"
|
| 459 |
+
]
|
| 460 |
+
},
|
| 461 |
+
{
|
| 462 |
+
"id": 123,
|
| 463 |
+
"type": "WanVideoSetLoRAs",
|
| 464 |
+
"pos": [
|
| 465 |
+
92.10754330391187,
|
| 466 |
+
-557.3043008153837
|
| 467 |
+
],
|
| 468 |
+
"size": [
|
| 469 |
+
174.5337890625,
|
| 470 |
+
46
|
| 471 |
+
],
|
| 472 |
+
"flags": {},
|
| 473 |
+
"order": 13,
|
| 474 |
+
"mode": 0,
|
| 475 |
+
"inputs": [
|
| 476 |
+
{
|
| 477 |
+
"name": "model",
|
| 478 |
+
"type": "WANVIDEOMODEL",
|
| 479 |
+
"link": 212
|
| 480 |
+
},
|
| 481 |
+
{
|
| 482 |
+
"name": "lora",
|
| 483 |
+
"shape": 7,
|
| 484 |
+
"type": "WANVIDLORA",
|
| 485 |
+
"link": 214
|
| 486 |
+
}
|
| 487 |
+
],
|
| 488 |
+
"outputs": [
|
| 489 |
+
{
|
| 490 |
+
"name": "model",
|
| 491 |
+
"type": "WANVIDEOMODEL",
|
| 492 |
+
"links": [
|
| 493 |
+
213
|
| 494 |
+
]
|
| 495 |
+
}
|
| 496 |
+
],
|
| 497 |
+
"properties": {
|
| 498 |
+
"cnr_id": "ComfyUI-WanVideoWrapper",
|
| 499 |
+
"ver": "d74cfc54e8ae065d7f32b36634be770bae525f5c",
|
| 500 |
+
"Node name for S&R": "WanVideoSetLoRAs"
|
| 501 |
+
}
|
| 502 |
+
},
|
| 503 |
+
{
|
| 504 |
+
"id": 112,
|
| 505 |
+
"type": "WanVideoTorchCompileSettings",
|
| 506 |
+
"pos": [
|
| 507 |
+
-910.2747578589916,
|
| 508 |
+
-583.7762511222455
|
| 509 |
+
],
|
| 510 |
+
"size": [
|
| 511 |
+
342.74609375,
|
| 512 |
+
226
|
| 513 |
+
],
|
| 514 |
+
"flags": {},
|
| 515 |
+
"order": 5,
|
| 516 |
+
"mode": 0,
|
| 517 |
+
"inputs": [],
|
| 518 |
+
"outputs": [
|
| 519 |
+
{
|
| 520 |
+
"name": "torch_compile_args",
|
| 521 |
+
"type": "WANCOMPILEARGS",
|
| 522 |
+
"links": [
|
| 523 |
+
225
|
| 524 |
+
]
|
| 525 |
+
}
|
| 526 |
+
],
|
| 527 |
+
"properties": {
|
| 528 |
+
"cnr_id": "ComfyUI-WanVideoWrapper",
|
| 529 |
+
"ver": "d74cfc54e8ae065d7f32b36634be770bae525f5c",
|
| 530 |
+
"Node name for S&R": "WanVideoTorchCompileSettings"
|
| 531 |
+
},
|
| 532 |
+
"widgets_values": [
|
| 533 |
+
"inductor",
|
| 534 |
+
false,
|
| 535 |
+
"default",
|
| 536 |
+
false,
|
| 537 |
+
64,
|
| 538 |
+
true,
|
| 539 |
+
128,
|
| 540 |
+
false
|
| 541 |
+
]
|
| 542 |
+
},
|
| 543 |
+
{
|
| 544 |
+
"id": 128,
|
| 545 |
+
"type": "WanVideoTextEncodeCached",
|
| 546 |
+
"pos": [
|
| 547 |
+
-1736.4153732283746,
|
| 548 |
+
-1153.2101630077232
|
| 549 |
+
],
|
| 550 |
+
"size": [
|
| 551 |
+
618.665832961123,
|
| 552 |
+
642.6927334053207
|
| 553 |
+
],
|
| 554 |
+
"flags": {},
|
| 555 |
+
"order": 6,
|
| 556 |
+
"mode": 0,
|
| 557 |
+
"inputs": [
|
| 558 |
+
{
|
| 559 |
+
"name": "extender_args",
|
| 560 |
+
"shape": 7,
|
| 561 |
+
"type": "WANVIDEOPROMPTEXTENDER_ARGS",
|
| 562 |
+
"link": null
|
| 563 |
+
}
|
| 564 |
+
],
|
| 565 |
+
"outputs": [
|
| 566 |
+
{
|
| 567 |
+
"name": "text_embeds",
|
| 568 |
+
"type": "WANVIDEOTEXTEMBEDS",
|
| 569 |
+
"links": []
|
| 570 |
+
},
|
| 571 |
+
{
|
| 572 |
+
"name": "negative_text_embeds",
|
| 573 |
+
"type": "WANVIDEOTEXTEMBEDS",
|
| 574 |
+
"links": null
|
| 575 |
+
},
|
| 576 |
+
{
|
| 577 |
+
"name": "positive_prompt",
|
| 578 |
+
"type": "STRING",
|
| 579 |
+
"links": null
|
| 580 |
+
}
|
| 581 |
+
],
|
| 582 |
+
"properties": {
|
| 583 |
+
"cnr_id": "ComfyUI-WanVideoWrapper",
|
| 584 |
+
"ver": "d74cfc54e8ae065d7f32b36634be770bae525f5c",
|
| 585 |
+
"Node name for S&R": "WanVideoTextEncodeCached"
|
| 586 |
+
},
|
| 587 |
+
"widgets_values": [
|
| 588 |
+
"umt5-xxl-enc-bf16.safetensors",
|
| 589 |
+
"bf16",
|
| 590 |
+
"In a realistic photography style, a white boy around seven or eight years old sits on a park bench, wearing a light blue T-shirt, denim shorts, and white sneakers. He holds an ice cream cone with vanilla and chocolate flavors, and beside him is a medium-sized golden Labrador. Smiling, the boy offers the ice cream to the dog, who eagerly licks it with its tongue. The sun is shining brightly, and the background features a green lawn and several tall trees, creating a warm and loving scene.\n",
|
| 591 |
+
"Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards",
|
| 592 |
+
"disabled",
|
| 593 |
+
true,
|
| 594 |
+
"gpu"
|
| 595 |
+
]
|
| 596 |
+
},
|
| 597 |
+
{
|
| 598 |
+
"id": 120,
|
| 599 |
+
"type": "WanVideoLoraSelect",
|
| 600 |
+
"pos": [
|
| 601 |
+
-436.33493477842427,
|
| 602 |
+
-955.598852558214
|
| 603 |
+
],
|
| 604 |
+
"size": [
|
| 605 |
+
413.3203274956858,
|
| 606 |
+
200
|
| 607 |
+
],
|
| 608 |
+
"flags": {},
|
| 609 |
+
"order": 7,
|
| 610 |
+
"mode": 0,
|
| 611 |
+
"inputs": [
|
| 612 |
+
{
|
| 613 |
+
"name": "prev_lora",
|
| 614 |
+
"shape": 7,
|
| 615 |
+
"type": "WANVIDLORA",
|
| 616 |
+
"link": null
|
| 617 |
+
},
|
| 618 |
+
{
|
| 619 |
+
"name": "blocks",
|
| 620 |
+
"shape": 7,
|
| 621 |
+
"type": "SELECTEDBLOCKS",
|
| 622 |
+
"link": null
|
| 623 |
+
}
|
| 624 |
+
],
|
| 625 |
+
"outputs": [
|
| 626 |
+
{
|
| 627 |
+
"name": "lora",
|
| 628 |
+
"type": "WANVIDLORA",
|
| 629 |
+
"links": [
|
| 630 |
+
214
|
| 631 |
+
]
|
| 632 |
+
}
|
| 633 |
+
],
|
| 634 |
+
"properties": {
|
| 635 |
+
"cnr_id": "ComfyUI-WanVideoWrapper",
|
| 636 |
+
"ver": "d74cfc54e8ae065d7f32b36634be770bae525f5c",
|
| 637 |
+
"Node name for S&R": "WanVideoLoraSelect"
|
| 638 |
+
},
|
| 639 |
+
"widgets_values": [
|
| 640 |
+
"WanVideo\\LongCat_distill_lora_alpha64_bf16.safetensors",
|
| 641 |
+
1,
|
| 642 |
+
false,
|
| 643 |
+
false,
|
| 644 |
+
"<details><summary><b>Metadata</b></summary><table border='0' cellpadding='3'><tr><td colspan='2'><b>Metadata</b></td></tr><tr><td><b>model_type</b></td><td>LongCat_distill_lora</td></tr><tr><td><b>format</b></td><td>pt</td></tr></table></details>"
|
| 645 |
+
]
|
| 646 |
+
},
|
| 647 |
+
{
|
| 648 |
+
"id": 101,
|
| 649 |
+
"type": "WanVideoSampler",
|
| 650 |
+
"pos": [
|
| 651 |
+
503.79042505822946,
|
| 652 |
+
-525.92729515406
|
| 653 |
+
],
|
| 654 |
+
"size": [
|
| 655 |
+
327.80859375,
|
| 656 |
+
1011.80859375
|
| 657 |
+
],
|
| 658 |
+
"flags": {},
|
| 659 |
+
"order": 16,
|
| 660 |
+
"mode": 0,
|
| 661 |
+
"inputs": [
|
| 662 |
+
{
|
| 663 |
+
"name": "model",
|
| 664 |
+
"type": "WANVIDEOMODEL",
|
| 665 |
+
"link": 184
|
| 666 |
+
},
|
| 667 |
+
{
|
| 668 |
+
"name": "image_embeds",
|
| 669 |
+
"type": "WANVIDIMAGE_EMBEDS",
|
| 670 |
+
"link": 182
|
| 671 |
+
},
|
| 672 |
+
{
|
| 673 |
+
"name": "text_embeds",
|
| 674 |
+
"shape": 7,
|
| 675 |
+
"type": "WANVIDEOTEXTEMBEDS",
|
| 676 |
+
"link": 208
|
| 677 |
+
},
|
| 678 |
+
{
|
| 679 |
+
"name": "samples",
|
| 680 |
+
"shape": 7,
|
| 681 |
+
"type": "LATENT",
|
| 682 |
+
"link": null
|
| 683 |
+
},
|
| 684 |
+
{
|
| 685 |
+
"name": "feta_args",
|
| 686 |
+
"shape": 7,
|
| 687 |
+
"type": "FETAARGS",
|
| 688 |
+
"link": null
|
| 689 |
+
},
|
| 690 |
+
{
|
| 691 |
+
"name": "context_options",
|
| 692 |
+
"shape": 7,
|
| 693 |
+
"type": "WANVIDCONTEXT",
|
| 694 |
+
"link": null
|
| 695 |
+
},
|
| 696 |
+
{
|
| 697 |
+
"name": "cache_args",
|
| 698 |
+
"shape": 7,
|
| 699 |
+
"type": "CACHEARGS",
|
| 700 |
+
"link": null
|
| 701 |
+
},
|
| 702 |
+
{
|
| 703 |
+
"name": "flowedit_args",
|
| 704 |
+
"shape": 7,
|
| 705 |
+
"type": "FLOWEDITARGS",
|
| 706 |
+
"link": null
|
| 707 |
+
},
|
| 708 |
+
{
|
| 709 |
+
"name": "slg_args",
|
| 710 |
+
"shape": 7,
|
| 711 |
+
"type": "SLGARGS",
|
| 712 |
+
"link": null
|
| 713 |
+
},
|
| 714 |
+
{
|
| 715 |
+
"name": "loop_args",
|
| 716 |
+
"shape": 7,
|
| 717 |
+
"type": "LOOPARGS",
|
| 718 |
+
"link": null
|
| 719 |
+
},
|
| 720 |
+
{
|
| 721 |
+
"name": "experimental_args",
|
| 722 |
+
"shape": 7,
|
| 723 |
+
"type": "EXPERIMENTALARGS",
|
| 724 |
+
"link": 226
|
| 725 |
+
},
|
| 726 |
+
{
|
| 727 |
+
"name": "sigmas",
|
| 728 |
+
"shape": 7,
|
| 729 |
+
"type": "SIGMAS",
|
| 730 |
+
"link": null
|
| 731 |
+
},
|
| 732 |
+
{
|
| 733 |
+
"name": "unianimate_poses",
|
| 734 |
+
"shape": 7,
|
| 735 |
+
"type": "UNIANIMATE_POSE",
|
| 736 |
+
"link": null
|
| 737 |
+
},
|
| 738 |
+
{
|
| 739 |
+
"name": "fantasytalking_embeds",
|
| 740 |
+
"shape": 7,
|
| 741 |
+
"type": "FANTASYTALKING_EMBEDS",
|
| 742 |
+
"link": null
|
| 743 |
+
},
|
| 744 |
+
{
|
| 745 |
+
"name": "uni3c_embeds",
|
| 746 |
+
"shape": 7,
|
| 747 |
+
"type": "UNI3C_EMBEDS",
|
| 748 |
+
"link": null
|
| 749 |
+
},
|
| 750 |
+
{
|
| 751 |
+
"name": "multitalk_embeds",
|
| 752 |
+
"shape": 7,
|
| 753 |
+
"type": "MULTITALK_EMBEDS",
|
| 754 |
+
"link": null
|
| 755 |
+
},
|
| 756 |
+
{
|
| 757 |
+
"name": "freeinit_args",
|
| 758 |
+
"shape": 7,
|
| 759 |
+
"type": "FREEINITARGS",
|
| 760 |
+
"link": null
|
| 761 |
+
}
|
| 762 |
+
],
|
| 763 |
+
"outputs": [
|
| 764 |
+
{
|
| 765 |
+
"name": "samples",
|
| 766 |
+
"type": "LATENT",
|
| 767 |
+
"links": [
|
| 768 |
+
181,
|
| 769 |
+
197
|
| 770 |
+
]
|
| 771 |
+
},
|
| 772 |
+
{
|
| 773 |
+
"name": "denoised_samples",
|
| 774 |
+
"type": "LATENT",
|
| 775 |
+
"links": null
|
| 776 |
+
}
|
| 777 |
+
],
|
| 778 |
+
"properties": {
|
| 779 |
+
"cnr_id": "ComfyUI-WanVideoWrapper",
|
| 780 |
+
"ver": "d74cfc54e8ae065d7f32b36634be770bae525f5c",
|
| 781 |
+
"Node name for S&R": "WanVideoSampler"
|
| 782 |
+
},
|
| 783 |
+
"widgets_values": [
|
| 784 |
+
16,
|
| 785 |
+
1,
|
| 786 |
+
12,
|
| 787 |
+
42,
|
| 788 |
+
"fixed",
|
| 789 |
+
true,
|
| 790 |
+
"longcat_distill_euler",
|
| 791 |
+
0,
|
| 792 |
+
1,
|
| 793 |
+
false,
|
| 794 |
+
"comfy",
|
| 795 |
+
0,
|
| 796 |
+
-1,
|
| 797 |
+
false
|
| 798 |
+
]
|
| 799 |
+
},
|
| 800 |
+
{
|
| 801 |
+
"id": 111,
|
| 802 |
+
"type": "WanVideoExperimentalArgs",
|
| 803 |
+
"pos": [
|
| 804 |
+
116.0470602692117,
|
| 805 |
+
169.9625170294709
|
| 806 |
+
],
|
| 807 |
+
"size": [
|
| 808 |
+
308.767578125,
|
| 809 |
+
370
|
| 810 |
+
],
|
| 811 |
+
"flags": {},
|
| 812 |
+
"order": 8,
|
| 813 |
+
"mode": 0,
|
| 814 |
+
"inputs": [],
|
| 815 |
+
"outputs": [
|
| 816 |
+
{
|
| 817 |
+
"name": "exp_args",
|
| 818 |
+
"type": "EXPERIMENTALARGS",
|
| 819 |
+
"links": [
|
| 820 |
+
226
|
| 821 |
+
]
|
| 822 |
+
}
|
| 823 |
+
],
|
| 824 |
+
"properties": {
|
| 825 |
+
"cnr_id": "ComfyUI-WanVideoWrapper",
|
| 826 |
+
"ver": "d74cfc54e8ae065d7f32b36634be770bae525f5c",
|
| 827 |
+
"Node name for S&R": "WanVideoExperimentalArgs"
|
| 828 |
+
},
|
| 829 |
+
"widgets_values": [
|
| 830 |
+
"",
|
| 831 |
+
true,
|
| 832 |
+
false,
|
| 833 |
+
0,
|
| 834 |
+
false,
|
| 835 |
+
1,
|
| 836 |
+
1.25,
|
| 837 |
+
20,
|
| 838 |
+
false,
|
| 839 |
+
0,
|
| 840 |
+
false,
|
| 841 |
+
false,
|
| 842 |
+
0.95,
|
| 843 |
+
1
|
| 844 |
+
]
|
| 845 |
+
},
|
| 846 |
+
{
|
| 847 |
+
"id": 71,
|
| 848 |
+
"type": "WanVideoModelLoader",
|
| 849 |
+
"pos": [
|
| 850 |
+
-470.0395352860955,
|
| 851 |
+
-592.9329481538847
|
| 852 |
+
],
|
| 853 |
+
"size": [
|
| 854 |
+
477.4410095214844,
|
| 855 |
+
338
|
| 856 |
+
],
|
| 857 |
+
"flags": {},
|
| 858 |
+
"order": 11,
|
| 859 |
+
"mode": 0,
|
| 860 |
+
"inputs": [
|
| 861 |
+
{
|
| 862 |
+
"name": "compile_args",
|
| 863 |
+
"shape": 7,
|
| 864 |
+
"type": "WANCOMPILEARGS",
|
| 865 |
+
"link": 225
|
| 866 |
+
},
|
| 867 |
+
{
|
| 868 |
+
"name": "block_swap_args",
|
| 869 |
+
"shape": 7,
|
| 870 |
+
"type": "BLOCKSWAPARGS",
|
| 871 |
+
"link": null
|
| 872 |
+
},
|
| 873 |
+
{
|
| 874 |
+
"name": "lora",
|
| 875 |
+
"shape": 7,
|
| 876 |
+
"type": "WANVIDLORA",
|
| 877 |
+
"link": null
|
| 878 |
+
},
|
| 879 |
+
{
|
| 880 |
+
"name": "vram_management_args",
|
| 881 |
+
"shape": 7,
|
| 882 |
+
"type": "VRAM_MANAGEMENTARGS",
|
| 883 |
+
"link": null
|
| 884 |
+
},
|
| 885 |
+
{
|
| 886 |
+
"name": "extra_model",
|
| 887 |
+
"shape": 7,
|
| 888 |
+
"type": "VACEPATH",
|
| 889 |
+
"link": null
|
| 890 |
+
},
|
| 891 |
+
{
|
| 892 |
+
"name": "fantasytalking_model",
|
| 893 |
+
"shape": 7,
|
| 894 |
+
"type": "FANTASYTALKINGMODEL",
|
| 895 |
+
"link": null
|
| 896 |
+
},
|
| 897 |
+
{
|
| 898 |
+
"name": "multitalk_model",
|
| 899 |
+
"shape": 7,
|
| 900 |
+
"type": "MULTITALKMODEL",
|
| 901 |
+
"link": null
|
| 902 |
+
},
|
| 903 |
+
{
|
| 904 |
+
"name": "fantasyportrait_model",
|
| 905 |
+
"shape": 7,
|
| 906 |
+
"type": "FANTASYPORTRAITMODEL",
|
| 907 |
+
"link": null
|
| 908 |
+
},
|
| 909 |
+
{
|
| 910 |
+
"name": "vace_model",
|
| 911 |
+
"shape": 7,
|
| 912 |
+
"type": "VACEPATH",
|
| 913 |
+
"link": null
|
| 914 |
+
}
|
| 915 |
+
],
|
| 916 |
+
"outputs": [
|
| 917 |
+
{
|
| 918 |
+
"name": "model",
|
| 919 |
+
"type": "WANVIDEOMODEL",
|
| 920 |
+
"slot_index": 0,
|
| 921 |
+
"links": [
|
| 922 |
+
212
|
| 923 |
+
]
|
| 924 |
+
}
|
| 925 |
+
],
|
| 926 |
+
"properties": {
|
| 927 |
+
"cnr_id": "ComfyUI-WanVideoWrapper",
|
| 928 |
+
"ver": "998a69cc0acbec503001b8b0ce0a5d5404420e1e",
|
| 929 |
+
"Node name for S&R": "WanVideoModelLoader"
|
| 930 |
+
},
|
| 931 |
+
"widgets_values": [
|
| 932 |
+
"WanVideo\\LongCat_bf16.safetensors",
|
| 933 |
+
"bf16",
|
| 934 |
+
"disabled",
|
| 935 |
+
"offload_device",
|
| 936 |
+
"sageattn",
|
| 937 |
+
"default"
|
| 938 |
+
],
|
| 939 |
+
"color": "#223",
|
| 940 |
+
"bgcolor": "#335"
|
| 941 |
+
},
|
| 942 |
+
{
|
| 943 |
+
"id": 113,
|
| 944 |
+
"type": "VHS_VideoCombine",
|
| 945 |
+
"pos": [
|
| 946 |
+
1480.3078222002348,
|
| 947 |
+
-546.5502181468293
|
| 948 |
+
],
|
| 949 |
+
"size": [
|
| 950 |
+
734.569974728307,
|
| 951 |
+
1062.569974728307
|
| 952 |
+
],
|
| 953 |
+
"flags": {},
|
| 954 |
+
"order": 19,
|
| 955 |
+
"mode": 0,
|
| 956 |
+
"inputs": [
|
| 957 |
+
{
|
| 958 |
+
"name": "images",
|
| 959 |
+
"type": "IMAGE",
|
| 960 |
+
"link": 201
|
| 961 |
+
},
|
| 962 |
+
{
|
| 963 |
+
"name": "audio",
|
| 964 |
+
"shape": 7,
|
| 965 |
+
"type": "AUDIO",
|
| 966 |
+
"link": null
|
| 967 |
+
},
|
| 968 |
+
{
|
| 969 |
+
"name": "meta_batch",
|
| 970 |
+
"shape": 7,
|
| 971 |
+
"type": "VHS_BatchManager",
|
| 972 |
+
"link": null
|
| 973 |
+
},
|
| 974 |
+
{
|
| 975 |
+
"name": "vae",
|
| 976 |
+
"shape": 7,
|
| 977 |
+
"type": "VAE",
|
| 978 |
+
"link": null
|
| 979 |
+
}
|
| 980 |
+
],
|
| 981 |
+
"outputs": [
|
| 982 |
+
{
|
| 983 |
+
"name": "Filenames",
|
| 984 |
+
"type": "VHS_FILENAMES",
|
| 985 |
+
"links": null
|
| 986 |
+
}
|
| 987 |
+
],
|
| 988 |
+
"properties": {
|
| 989 |
+
"cnr_id": "comfyui-videohelpersuite",
|
| 990 |
+
"ver": "0edce8ef7ce173ac97a3ed3d6f4636029d1a4530",
|
| 991 |
+
"Node name for S&R": "VHS_VideoCombine"
|
| 992 |
+
},
|
| 993 |
+
"widgets_values": {
|
| 994 |
+
"frame_rate": 16,
|
| 995 |
+
"loop_count": 0,
|
| 996 |
+
"filename_prefix": "LongCat",
|
| 997 |
+
"format": "video/h264-mp4",
|
| 998 |
+
"pix_fmt": "yuv420p",
|
| 999 |
+
"crf": 19,
|
| 1000 |
+
"save_metadata": true,
|
| 1001 |
+
"trim_to_audio": false,
|
| 1002 |
+
"pingpong": false,
|
| 1003 |
+
"save_output": false,
|
| 1004 |
+
"videopreview": {
|
| 1005 |
+
"hidden": false,
|
| 1006 |
+
"paused": false,
|
| 1007 |
+
"params": {
|
| 1008 |
+
"filename": "LongCat_00017.mp4",
|
| 1009 |
+
"subfolder": "",
|
| 1010 |
+
"type": "temp",
|
| 1011 |
+
"format": "video/h264-mp4",
|
| 1012 |
+
"frame_rate": 16,
|
| 1013 |
+
"workflow": "LongCat_00017.png",
|
| 1014 |
+
"fullpath": "N:\\AI\\ComfyUI\\temp\\LongCat_00017.mp4"
|
| 1015 |
+
}
|
| 1016 |
+
}
|
| 1017 |
+
}
|
| 1018 |
+
},
|
| 1019 |
+
{
|
| 1020 |
+
"id": 132,
|
| 1021 |
+
"type": "MarkdownNote",
|
| 1022 |
+
"pos": [
|
| 1023 |
+
-566.4254932249919,
|
| 1024 |
+
293.07563303420795
|
| 1025 |
+
],
|
| 1026 |
+
"size": [
|
| 1027 |
+
272.9529376966493,
|
| 1028 |
+
656.357191483194
|
| 1029 |
+
],
|
| 1030 |
+
"flags": {},
|
| 1031 |
+
"order": 9,
|
| 1032 |
+
"mode": 0,
|
| 1033 |
+
"inputs": [],
|
| 1034 |
+
"outputs": [],
|
| 1035 |
+
"title": "Default bucket aspect ratios",
|
| 1036 |
+
"properties": {},
|
| 1037 |
+
"widgets_values": [
|
| 1038 |
+
"| Aspect Ratio | Resolution (W × H) |\n|--------------|--------------------|\n| 0.26 | 320 × 1216 |\n| 0.31 | 352 × 1120 |\n| 0.38 | 384 × 1024 |\n| 0.43 | 416 × 960 |\n| 0.52 | 448 × 864 |\n| 0.58 | 480 × 832 |\n| 0.67 | 512 × 768 |\n| 0.74 | 544 × 736 |\n| 0.86 | 576 × 672 |\n| 0.95 | 608 × 640 |\n| 1.05 | 640 × 608 |\n| 1.17 | 672 × 576 |\n| 1.29 | 704 × 544 |\n| 1.35 | 736 × 544 |\n| 1.50 | 768 × 512 |\n| 1.67 | 800 × 480 |\n| 1.73 | 832 × 480 |\n| 2.00 | 896 × 448 |\n| 2.31 | 960 × 416 |\n| 2.58 | 992 × 384 |\n| 2.75 | 1056 × 384 |\n| 3.09 | 1088 × 352 |\n| 3.70 | 1184 × 320 |\n| 3.80 | 1216 × 320 |\n| 3.90 | 1248 × 320 |\n| 4.00 | 1280 × 320 |"
|
| 1039 |
+
],
|
| 1040 |
+
"color": "#432",
|
| 1041 |
+
"bgcolor": "#653"
|
| 1042 |
+
},
|
| 1043 |
+
{
|
| 1044 |
+
"id": 127,
|
| 1045 |
+
"type": "ImageResizeKJv2",
|
| 1046 |
+
"pos": [
|
| 1047 |
+
-764.6297949873966,
|
| 1048 |
+
-192.58743226889652
|
| 1049 |
+
],
|
| 1050 |
+
"size": [
|
| 1051 |
+
270,
|
| 1052 |
+
336
|
| 1053 |
+
],
|
| 1054 |
+
"flags": {},
|
| 1055 |
+
"order": 10,
|
| 1056 |
+
"mode": 0,
|
| 1057 |
+
"inputs": [
|
| 1058 |
+
{
|
| 1059 |
+
"name": "image",
|
| 1060 |
+
"type": "IMAGE",
|
| 1061 |
+
"link": 224
|
| 1062 |
+
},
|
| 1063 |
+
{
|
| 1064 |
+
"name": "mask",
|
| 1065 |
+
"shape": 7,
|
| 1066 |
+
"type": "MASK",
|
| 1067 |
+
"link": null
|
| 1068 |
+
}
|
| 1069 |
+
],
|
| 1070 |
+
"outputs": [
|
| 1071 |
+
{
|
| 1072 |
+
"name": "IMAGE",
|
| 1073 |
+
"type": "IMAGE",
|
| 1074 |
+
"links": [
|
| 1075 |
+
220
|
| 1076 |
+
]
|
| 1077 |
+
},
|
| 1078 |
+
{
|
| 1079 |
+
"name": "width",
|
| 1080 |
+
"type": "INT",
|
| 1081 |
+
"links": [
|
| 1082 |
+
221
|
| 1083 |
+
]
|
| 1084 |
+
},
|
| 1085 |
+
{
|
| 1086 |
+
"name": "height",
|
| 1087 |
+
"type": "INT",
|
| 1088 |
+
"links": [
|
| 1089 |
+
222
|
| 1090 |
+
]
|
| 1091 |
+
},
|
| 1092 |
+
{
|
| 1093 |
+
"name": "mask",
|
| 1094 |
+
"type": "MASK",
|
| 1095 |
+
"links": null
|
| 1096 |
+
}
|
| 1097 |
+
],
|
| 1098 |
+
"properties": {
|
| 1099 |
+
"cnr_id": "comfyui-kjnodes",
|
| 1100 |
+
"ver": "6ee278aa7d802c03ad713a7c5fbc02861b6773a8",
|
| 1101 |
+
"Node name for S&R": "ImageResizeKJv2"
|
| 1102 |
+
},
|
| 1103 |
+
"widgets_values": [
|
| 1104 |
+
640,
|
| 1105 |
+
608,
|
| 1106 |
+
"lanczos",
|
| 1107 |
+
"crop",
|
| 1108 |
+
"0, 0, 0",
|
| 1109 |
+
"center",
|
| 1110 |
+
2,
|
| 1111 |
+
"cpu",
|
| 1112 |
+
"<tr><td>Output: </td><td><b>1</b> x <b>640</b> x <b>640 | 4.69MB</b></td></tr>"
|
| 1113 |
+
]
|
| 1114 |
+
}
|
| 1115 |
+
],
|
| 1116 |
+
"links": [
|
| 1117 |
+
[
|
| 1118 |
+
181,
|
| 1119 |
+
101,
|
| 1120 |
+
0,
|
| 1121 |
+
100,
|
| 1122 |
+
0,
|
| 1123 |
+
"*"
|
| 1124 |
+
],
|
| 1125 |
+
[
|
| 1126 |
+
182,
|
| 1127 |
+
102,
|
| 1128 |
+
0,
|
| 1129 |
+
101,
|
| 1130 |
+
1,
|
| 1131 |
+
"WANVIDIMAGE_EMBEDS"
|
| 1132 |
+
],
|
| 1133 |
+
[
|
| 1134 |
+
184,
|
| 1135 |
+
103,
|
| 1136 |
+
0,
|
| 1137 |
+
101,
|
| 1138 |
+
0,
|
| 1139 |
+
"WANVIDEOMODEL"
|
| 1140 |
+
],
|
| 1141 |
+
[
|
| 1142 |
+
185,
|
| 1143 |
+
104,
|
| 1144 |
+
0,
|
| 1145 |
+
103,
|
| 1146 |
+
1,
|
| 1147 |
+
"BLOCKSWAPARGS"
|
| 1148 |
+
],
|
| 1149 |
+
[
|
| 1150 |
+
196,
|
| 1151 |
+
108,
|
| 1152 |
+
0,
|
| 1153 |
+
109,
|
| 1154 |
+
0,
|
| 1155 |
+
"WANVAE"
|
| 1156 |
+
],
|
| 1157 |
+
[
|
| 1158 |
+
197,
|
| 1159 |
+
101,
|
| 1160 |
+
0,
|
| 1161 |
+
109,
|
| 1162 |
+
1,
|
| 1163 |
+
"LATENT"
|
| 1164 |
+
],
|
| 1165 |
+
[
|
| 1166 |
+
201,
|
| 1167 |
+
109,
|
| 1168 |
+
0,
|
| 1169 |
+
113,
|
| 1170 |
+
0,
|
| 1171 |
+
"IMAGE"
|
| 1172 |
+
],
|
| 1173 |
+
[
|
| 1174 |
+
208,
|
| 1175 |
+
107,
|
| 1176 |
+
0,
|
| 1177 |
+
101,
|
| 1178 |
+
2,
|
| 1179 |
+
"WANVIDEOTEXTEMBEDS"
|
| 1180 |
+
],
|
| 1181 |
+
[
|
| 1182 |
+
212,
|
| 1183 |
+
71,
|
| 1184 |
+
0,
|
| 1185 |
+
123,
|
| 1186 |
+
0,
|
| 1187 |
+
"WANVIDEOMODEL"
|
| 1188 |
+
],
|
| 1189 |
+
[
|
| 1190 |
+
213,
|
| 1191 |
+
123,
|
| 1192 |
+
0,
|
| 1193 |
+
103,
|
| 1194 |
+
0,
|
| 1195 |
+
"WANVIDEOMODEL"
|
| 1196 |
+
],
|
| 1197 |
+
[
|
| 1198 |
+
214,
|
| 1199 |
+
120,
|
| 1200 |
+
0,
|
| 1201 |
+
123,
|
| 1202 |
+
1,
|
| 1203 |
+
"WANVIDLORA"
|
| 1204 |
+
],
|
| 1205 |
+
[
|
| 1206 |
+
216,
|
| 1207 |
+
108,
|
| 1208 |
+
0,
|
| 1209 |
+
125,
|
| 1210 |
+
0,
|
| 1211 |
+
"WANVAE"
|
| 1212 |
+
],
|
| 1213 |
+
[
|
| 1214 |
+
217,
|
| 1215 |
+
125,
|
| 1216 |
+
0,
|
| 1217 |
+
102,
|
| 1218 |
+
1,
|
| 1219 |
+
"LATENT"
|
| 1220 |
+
],
|
| 1221 |
+
[
|
| 1222 |
+
220,
|
| 1223 |
+
127,
|
| 1224 |
+
0,
|
| 1225 |
+
125,
|
| 1226 |
+
1,
|
| 1227 |
+
"IMAGE"
|
| 1228 |
+
],
|
| 1229 |
+
[
|
| 1230 |
+
221,
|
| 1231 |
+
127,
|
| 1232 |
+
1,
|
| 1233 |
+
102,
|
| 1234 |
+
2,
|
| 1235 |
+
"INT"
|
| 1236 |
+
],
|
| 1237 |
+
[
|
| 1238 |
+
222,
|
| 1239 |
+
127,
|
| 1240 |
+
2,
|
| 1241 |
+
102,
|
| 1242 |
+
3,
|
| 1243 |
+
"INT"
|
| 1244 |
+
],
|
| 1245 |
+
[
|
| 1246 |
+
224,
|
| 1247 |
+
129,
|
| 1248 |
+
0,
|
| 1249 |
+
127,
|
| 1250 |
+
0,
|
| 1251 |
+
"IMAGE"
|
| 1252 |
+
],
|
| 1253 |
+
[
|
| 1254 |
+
225,
|
| 1255 |
+
112,
|
| 1256 |
+
0,
|
| 1257 |
+
71,
|
| 1258 |
+
0,
|
| 1259 |
+
"WANCOMPILEARGS"
|
| 1260 |
+
],
|
| 1261 |
+
[
|
| 1262 |
+
226,
|
| 1263 |
+
111,
|
| 1264 |
+
0,
|
| 1265 |
+
101,
|
| 1266 |
+
10,
|
| 1267 |
+
"EXPERIMENTALARGS"
|
| 1268 |
+
]
|
| 1269 |
+
],
|
| 1270 |
+
"groups": [],
|
| 1271 |
+
"config": {},
|
| 1272 |
+
"extra": {
|
| 1273 |
+
"ds": {
|
| 1274 |
+
"scale": 0.8140274938684529,
|
| 1275 |
+
"offset": [
|
| 1276 |
+
1362.0224139354584,
|
| 1277 |
+
443.9498340135939
|
| 1278 |
+
]
|
| 1279 |
+
},
|
| 1280 |
+
"frontendVersion": "1.30.1",
|
| 1281 |
+
"node_versions": {
|
| 1282 |
+
"ComfyUI-WanVideoWrapper": "5a2383621a05825d0d0437781afcb8552d9590fd",
|
| 1283 |
+
"comfy-core": "0.3.26",
|
| 1284 |
+
"ComfyUI-VideoHelperSuite": "0a75c7958fe320efcb052f1d9f8451fd20c730a8"
|
| 1285 |
+
},
|
| 1286 |
+
"VHS_latentpreview": true,
|
| 1287 |
+
"VHS_latentpreviewrate": 0,
|
| 1288 |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+
from ..utils import log
|
| 4 |
+
import comfy.model_management as mm
|
| 5 |
+
from comfy_api.latest import io
|
| 6 |
+
|
| 7 |
+
device = mm.get_torch_device()
|
| 8 |
+
offload_device = mm.unet_offload_device()
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class WanVideoLongCatAvatarExtendEmbeds(io.ComfyNode):
|
| 12 |
+
@classmethod
|
| 13 |
+
def define_schema(cls):
|
| 14 |
+
return io.Schema(
|
| 15 |
+
node_id="WanVideoLongCatAvatarExtendEmbeds",
|
| 16 |
+
category="WanVideoWrapper",
|
| 17 |
+
inputs=[
|
| 18 |
+
io.Latent.Input("prev_latents", tooltip="Full previous latents to be used to continue generation, continuation frames are selected based on 'overlap' parameter"),
|
| 19 |
+
io.Custom("MULTITALK_EMBEDS").Input("audio_embeds", tooltip="Full length audio embeddings"),
|
| 20 |
+
io.Int.Input("num_frames", default=93, min=1, max=256, step=1, tooltip="Number of new frames to generate"),
|
| 21 |
+
io.Int.Input("overlap", default=13, min=0, max=16, step=1, tooltip="Number of overlapping frames from previous latents for video continuation, set to 0 for T2V"),
|
| 22 |
+
io.Int.Input("frames_processed", default=0, min=0, max=10000, step=1, tooltip="Number of frames already processed in the video, used to select audio features"),
|
| 23 |
+
io.Combo.Input("if_not_enough_audio", ["pad_with_start", "mirror_from_end"], default="pad_with_start", tooltip="What to do if there are not enough frames in pose_images for the window"),
|
| 24 |
+
io.Int.Input("ref_frame_index", default=10, min=0, max=1000, step=1, tooltip="Values between 0 - 24 ensures better consistency, while selecting other ranges (e.g., -10 or 30) helps reduce repeated actions"),
|
| 25 |
+
io.Int.Input("ref_mask_frame_range", default=3, min=0, max=20, step=1, tooltip="Larger range can further help mitigate repeated actions, but excessively large values may introduce artifacts"),
|
| 26 |
+
io.Latent.Input("ref_latent", optional=True, tooltip="Reference latent used for consistency, generally should be either the init image, or first latent from first generation"),
|
| 27 |
+
io.Latent.Input("samples", optional=True, tooltip="For the sampler 'samples' input, used for slicing samples per window for vid2vid"),
|
| 28 |
+
io.Custom("IMAGE").Input("prev_images", optional=True, tooltip="LongCat-Avatar-1.5: decoded frames from the previous segment. When provided together with `vae`, the trailing `overlap` frames are re-encoded through the VAE and used as the overlap conditioning (matches v1.5's use_vcond=False behavior). Leave disconnected for v1.0."),
|
| 29 |
+
io.Custom("WANVAE").Input("vae", optional=True, tooltip="LongCat-Avatar-1.5: VAE used to re-encode `prev_images` for the overlap region. Only used when `prev_images` is also provided."),
|
| 30 |
+
],
|
| 31 |
+
outputs=[
|
| 32 |
+
io.Custom("WANVIDIMAGE_EMBEDS").Output(display_name="image_embeds", tooltip="Embeds for WanVideo LongCat Avatar generation"),
|
| 33 |
+
io.Latent.Output(display_name="samples_slice", tooltip="Sliced latent samples for the new frames"),
|
| 34 |
+
],
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
@classmethod
|
| 38 |
+
def execute(cls, prev_latents, audio_embeds, num_frames, overlap, if_not_enough_audio, frames_processed, ref_frame_index, ref_mask_frame_range, ref_latent=None, samples=None, prev_images=None, vae=None) -> io.NodeOutput:
|
| 39 |
+
|
| 40 |
+
new_audio_embed = audio_embeds.copy()
|
| 41 |
+
|
| 42 |
+
audio_features = torch.stack(new_audio_embed["audio_features"])
|
| 43 |
+
num_audio_features = audio_features.shape[1]
|
| 44 |
+
if audio_features.shape[1] < frames_processed + num_frames:
|
| 45 |
+
deficit = frames_processed + num_frames - audio_features.shape[1]
|
| 46 |
+
if if_not_enough_audio == "pad_with_start":
|
| 47 |
+
pad = audio_features[:, :1].repeat(1, deficit, 1, 1)
|
| 48 |
+
audio_features = torch.cat([audio_features, pad], dim=1)
|
| 49 |
+
elif if_not_enough_audio == "mirror_from_end":
|
| 50 |
+
to_add = audio_features[:, -deficit:, :].flip(dims=[1])
|
| 51 |
+
audio_features = torch.cat([audio_features, to_add], dim=1)
|
| 52 |
+
log.warning(f"Not enough audio features, padded with strategy '{if_not_enough_audio}' from {num_audio_features} to {audio_features.shape[1]} frames")
|
| 53 |
+
|
| 54 |
+
ref_target_masks = new_audio_embed.get("ref_target_masks", None)
|
| 55 |
+
if ref_target_masks is not None:
|
| 56 |
+
new_audio_embed["ref_target_masks"] = ref_target_masks[:, frames_processed:frames_processed+num_frames, :]
|
| 57 |
+
|
| 58 |
+
prev_samples = prev_latents["samples"].clone()
|
| 59 |
+
if overlap != 0:
|
| 60 |
+
latent_overlap = (overlap - 1) // 4 + 1
|
| 61 |
+
if prev_images is not None and vae is not None:
|
| 62 |
+
# LongCat-Avatar-1.5 path: re-encodes instead of just slicing
|
| 63 |
+
img = prev_images[-overlap:]
|
| 64 |
+
if img.shape[-1] == 4:
|
| 65 |
+
img = img[..., :3]
|
| 66 |
+
img = img.to(vae.dtype).to(device) * 2.0 - 1.0
|
| 67 |
+
img = img.permute(3, 0, 1, 2).unsqueeze(0).contiguous() # [T, H, W, C] -> [B, C, T, H, W]
|
| 68 |
+
vae.to(device)
|
| 69 |
+
prev_samples = vae.encode(img, device=device).to(prev_samples)
|
| 70 |
+
vae.to(offload_device)
|
| 71 |
+
mm.soft_empty_cache()
|
| 72 |
+
log.info(f"Re-encoded {overlap} overlap frames -> latent shape {tuple(prev_samples.shape)}")
|
| 73 |
+
else:
|
| 74 |
+
prev_samples = prev_samples[:, :, -latent_overlap:]
|
| 75 |
+
|
| 76 |
+
ref_sample = None
|
| 77 |
+
if ref_latent is not None:
|
| 78 |
+
ref_sample = ref_latent["samples"][0, :, :1].clone()
|
| 79 |
+
log.info(f"Previous latents shape: {prev_samples.shape}, using last {latent_overlap} latent frames for overlap.")
|
| 80 |
+
|
| 81 |
+
new_latent_frames = (num_frames - 1) // 4 + 1
|
| 82 |
+
target_shape = (16, new_latent_frames, prev_samples.shape[-2], prev_samples.shape[-1])
|
| 83 |
+
|
| 84 |
+
audio_stride = new_audio_embed.get("audio_stride", 2)
|
| 85 |
+
indices = torch.arange(2 * 2 + 1) - 2
|
| 86 |
+
|
| 87 |
+
if frames_processed == 0:
|
| 88 |
+
audio_start_idx = 0
|
| 89 |
+
else:
|
| 90 |
+
audio_start_idx = (frames_processed - overlap) * audio_stride
|
| 91 |
+
audio_end_idx = audio_start_idx + num_frames * audio_stride
|
| 92 |
+
|
| 93 |
+
log.info(f"Extracting audio embeddings from index {audio_start_idx} to {audio_end_idx}")
|
| 94 |
+
|
| 95 |
+
audio_embs = []
|
| 96 |
+
for human_idx in range(len(audio_features)):
|
| 97 |
+
center_indices = torch.arange(audio_start_idx, audio_end_idx, audio_stride).unsqueeze(1) + indices.unsqueeze(0)
|
| 98 |
+
center_indices = torch.clamp(center_indices, min=0, max=audio_features[human_idx].shape[0] - 1)
|
| 99 |
+
|
| 100 |
+
audio_emb = audio_features[human_idx][center_indices].unsqueeze(0).to(device)
|
| 101 |
+
audio_embs.append(audio_emb)
|
| 102 |
+
audio_emb = torch.cat(audio_embs, dim=0)
|
| 103 |
+
|
| 104 |
+
new_audio_embed["audio_features"] = None
|
| 105 |
+
new_audio_embed["audio_emb_slice"] = audio_emb
|
| 106 |
+
|
| 107 |
+
longcat_avatar_options = {
|
| 108 |
+
"longcat_ref_latent": ref_sample,
|
| 109 |
+
"ref_frame_index": ref_frame_index,
|
| 110 |
+
"ref_mask_frame_range": ref_mask_frame_range,
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
embeds = {
|
| 114 |
+
"target_shape": target_shape,
|
| 115 |
+
"num_frames": num_frames,
|
| 116 |
+
"extra_latents": [{"samples": prev_samples, "index": 0}] if overlap != 0 else None,
|
| 117 |
+
"multitalk_embeds": new_audio_embed,
|
| 118 |
+
"longcat_avatar_options": longcat_avatar_options,
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
samples_slice = None
|
| 122 |
+
if samples is not None:
|
| 123 |
+
latent_start_index = (frames_processed - 1) // 4 + 1 if frames_processed > 0 else 0
|
| 124 |
+
latent_end_index = latent_start_index + new_latent_frames
|
| 125 |
+
samples_slice = samples.copy()
|
| 126 |
+
samples_slice["samples"] = samples["samples"][:, :, latent_start_index:latent_end_index].clone()
|
| 127 |
+
|
| 128 |
+
return io.NodeOutput(embeds, samples_slice)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
class LongCatAvatarWhisperEmbeds:
|
| 132 |
+
"""Audio embeds for LongCat-Video-Avatar-1.5 (Whisper-large-v3).
|
| 133 |
+
|
| 134 |
+
Produces a MULTITALK_EMBEDS dict whose audio_features are shaped [T, 5, 1280]
|
| 135 |
+
(5 grouped Whisper layers, 1280-d hidden state), matching the audio stream
|
| 136 |
+
the v1.5 AudioProjModel expects. audio_stride is set to 1 to signal v1.5
|
| 137 |
+
timing to the consumer nodes (vs. 2 for the v1.0 wav2vec2 path).
|
| 138 |
+
"""
|
| 139 |
+
|
| 140 |
+
@classmethod
|
| 141 |
+
def INPUT_TYPES(s):
|
| 142 |
+
return {
|
| 143 |
+
"required": {
|
| 144 |
+
"whisper_model": ("WHISPERMODEL",),
|
| 145 |
+
"audio_1": ("AUDIO",),
|
| 146 |
+
"normalize_loudness": ("BOOLEAN", {"default": True, "tooltip": "Normalize audio loudness to -23 LUFS before encoding (matches the v1.5 reference pipeline)"}),
|
| 147 |
+
"num_frames": ("INT", {"default": 93, "min": 1, "max": 10000, "step": 1, "tooltip": "Total frame count to generate; bounds how much audio is consumed"}),
|
| 148 |
+
"fps": ("FLOAT", {"default": 25.0, "min": 1.0, "max": 60.0, "step": 0.1, "tooltip": "Target video fps. LongCat-Video-Avatar-1.5 is trained at 25 fps."}),
|
| 149 |
+
"audio_scale": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 100.0, "step": 0.01, "tooltip": "Strength of the audio conditioning"}),
|
| 150 |
+
"audio_cfg_scale": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 100.0, "step": 0.01, "tooltip": "When not 1.0, an extra model pass without audio conditioning is done"}),
|
| 151 |
+
"multi_audio_type": (["para", "add"], {"default": "para", "tooltip": "'para' overlays speakers in parallel (equal length); 'add' concatenates speakers sequentially with silence padding"}),
|
| 152 |
+
},
|
| 153 |
+
"optional": {
|
| 154 |
+
"audio_2": ("AUDIO",),
|
| 155 |
+
"audio_3": ("AUDIO",),
|
| 156 |
+
"audio_4": ("AUDIO",),
|
| 157 |
+
"ref_target_masks": ("MASK", {"tooltip": "Per-speaker semantic mask(s) in pixel space, one per speaker"}),
|
| 158 |
+
},
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
RETURN_TYPES = ("MULTITALK_EMBEDS", "AUDIO", "INT",)
|
| 162 |
+
RETURN_NAMES = ("multitalk_embeds", "audio", "num_frames",)
|
| 163 |
+
FUNCTION = "process"
|
| 164 |
+
CATEGORY = "WanVideoWrapper"
|
| 165 |
+
|
| 166 |
+
def process(self, whisper_model, audio_1, normalize_loudness, num_frames, fps,
|
| 167 |
+
audio_scale, audio_cfg_scale, multi_audio_type,
|
| 168 |
+
audio_2=None, audio_3=None, audio_4=None, ref_target_masks=None):
|
| 169 |
+
import torchaudio
|
| 170 |
+
import numpy as np
|
| 171 |
+
from ..multitalk.nodes import loudness_norm
|
| 172 |
+
|
| 173 |
+
model = whisper_model["model"]
|
| 174 |
+
feature_extractor = whisper_model["feature_extractor"]
|
| 175 |
+
dtype = whisper_model["dtype"]
|
| 176 |
+
|
| 177 |
+
sr = 16000
|
| 178 |
+
MEL_CHUNK = 750 * 640 # 480000 samples = 30s at 16kHz; matches Whisper's chunk_length
|
| 179 |
+
ENC_CHUNK = 3000 # encoder window in mel frames
|
| 180 |
+
ENC_FPS = 50 # whisper encoder output frames per second
|
| 181 |
+
|
| 182 |
+
def linear_interp(features, output_len):
|
| 183 |
+
features = features.transpose(1, 2) # [B, D, T]
|
| 184 |
+
out = F.interpolate(features, size=output_len, align_corners=True, mode='linear')
|
| 185 |
+
return out.transpose(1, 2)
|
| 186 |
+
|
| 187 |
+
audio_inputs = [a for a in [audio_1, audio_2, audio_3, audio_4] if a is not None]
|
| 188 |
+
|
| 189 |
+
audio_features_list = []
|
| 190 |
+
seq_lengths = []
|
| 191 |
+
audio_outputs = []
|
| 192 |
+
|
| 193 |
+
end_time = num_frames / float(fps)
|
| 194 |
+
end_sample = int(end_time * sr)
|
| 195 |
+
|
| 196 |
+
for audio in audio_inputs:
|
| 197 |
+
audio_input = audio["waveform"]
|
| 198 |
+
sample_rate = audio["sample_rate"]
|
| 199 |
+
if sample_rate != sr:
|
| 200 |
+
audio_input = torchaudio.functional.resample(audio_input, sample_rate, sr)
|
| 201 |
+
audio_input = audio_input[0][0]
|
| 202 |
+
audio_segment = audio_input[:end_sample].cpu().numpy().astype(np.float32)
|
| 203 |
+
|
| 204 |
+
if normalize_loudness:
|
| 205 |
+
audio_segment = loudness_norm(audio_segment, sr=sr)
|
| 206 |
+
|
| 207 |
+
audio_duration = len(audio_segment) / sr
|
| 208 |
+
video_length = int(audio_duration * fps)
|
| 209 |
+
if video_length < 1:
|
| 210 |
+
continue
|
| 211 |
+
|
| 212 |
+
mel_chunks = []
|
| 213 |
+
for i in range(0, len(audio_segment), MEL_CHUNK):
|
| 214 |
+
mel = feature_extractor(audio_segment[i:i + MEL_CHUNK], sampling_rate=sr,
|
| 215 |
+
return_tensors="pt").input_features
|
| 216 |
+
mel_chunks.append(mel)
|
| 217 |
+
mel_features = torch.cat(mel_chunks, dim=-1).to(device=device, dtype=dtype)
|
| 218 |
+
|
| 219 |
+
model.to(device)
|
| 220 |
+
enc_chunks = []
|
| 221 |
+
with torch.no_grad():
|
| 222 |
+
for i in range(0, mel_features.shape[-1], ENC_CHUNK):
|
| 223 |
+
chunk = mel_features[:, :, i:i + ENC_CHUNK]
|
| 224 |
+
chunk_hs = model.encoder(chunk, output_hidden_states=True).hidden_states
|
| 225 |
+
enc_chunks.append(torch.stack(chunk_hs, dim=2)) # [1, T_enc, n_layers+1, D]
|
| 226 |
+
model.to(offload_device)
|
| 227 |
+
|
| 228 |
+
audio_prompts = torch.cat(enc_chunks, dim=1)
|
| 229 |
+
audio_prompts = audio_prompts[:, :video_length * 2]
|
| 230 |
+
|
| 231 |
+
feat0 = linear_interp(audio_prompts[:, :, 0:8].mean(dim=2), video_length)
|
| 232 |
+
feat1 = linear_interp(audio_prompts[:, :, 8:16].mean(dim=2), video_length)
|
| 233 |
+
feat2 = linear_interp(audio_prompts[:, :, 16:24].mean(dim=2), video_length)
|
| 234 |
+
feat3 = linear_interp(audio_prompts[:, :, 24:32].mean(dim=2), video_length)
|
| 235 |
+
feat4 = linear_interp(audio_prompts[:, :, 32], video_length)
|
| 236 |
+
audio_emb = torch.stack([feat0, feat1, feat2, feat3, feat4], dim=2)[0] # [T, 5, 1280]
|
| 237 |
+
|
| 238 |
+
audio_features_list.append(audio_emb.cpu().detach())
|
| 239 |
+
seq_lengths.append(audio_emb.shape[0])
|
| 240 |
+
|
| 241 |
+
waveform_tensor = torch.from_numpy(audio_segment).float().unsqueeze(0).unsqueeze(0)
|
| 242 |
+
audio_outputs.append({"waveform": waveform_tensor, "sample_rate": sr})
|
| 243 |
+
|
| 244 |
+
if len(audio_features_list) == 0:
|
| 245 |
+
raise RuntimeError("No valid Whisper audio embeddings extracted, please check inputs")
|
| 246 |
+
|
| 247 |
+
if len(audio_features_list) > 1:
|
| 248 |
+
if multi_audio_type == "para":
|
| 249 |
+
max_len = max(seq_lengths)
|
| 250 |
+
padded = []
|
| 251 |
+
for emb in audio_features_list:
|
| 252 |
+
if emb.shape[0] < max_len:
|
| 253 |
+
pad = torch.zeros(max_len - emb.shape[0], *emb.shape[1:], dtype=emb.dtype)
|
| 254 |
+
emb = torch.cat([emb, pad], dim=0)
|
| 255 |
+
padded.append(emb)
|
| 256 |
+
audio_features_list = padded
|
| 257 |
+
else: # "add"
|
| 258 |
+
total_len = sum(seq_lengths)
|
| 259 |
+
full_list = []
|
| 260 |
+
offset = 0
|
| 261 |
+
for emb, length in zip(audio_features_list, seq_lengths):
|
| 262 |
+
full = torch.zeros(total_len, *emb.shape[1:], dtype=emb.dtype)
|
| 263 |
+
full[offset:offset + length] = emb
|
| 264 |
+
full_list.append(full)
|
| 265 |
+
offset += length
|
| 266 |
+
audio_features_list = full_list
|
| 267 |
+
|
| 268 |
+
multitalk_embeds = {
|
| 269 |
+
"audio_features": audio_features_list,
|
| 270 |
+
"audio_scale": audio_scale,
|
| 271 |
+
"audio_cfg_scale": audio_cfg_scale,
|
| 272 |
+
"ref_target_masks": ref_target_masks,
|
| 273 |
+
"audio_stride": 1,
|
| 274 |
+
"audio_encoder_type": "whisper",
|
| 275 |
+
}
|
| 276 |
+
|
| 277 |
+
if len(audio_outputs) == 1:
|
| 278 |
+
out_audio = audio_outputs[0]
|
| 279 |
+
elif multi_audio_type == "para":
|
| 280 |
+
max_len = max(a["waveform"].shape[-1] for a in audio_outputs)
|
| 281 |
+
mixed = torch.zeros(1, 1, max_len, dtype=audio_outputs[0]["waveform"].dtype)
|
| 282 |
+
for a in audio_outputs:
|
| 283 |
+
w = a["waveform"]
|
| 284 |
+
if w.shape[-1] < max_len:
|
| 285 |
+
w = F.pad(w, (0, max_len - w.shape[-1]))
|
| 286 |
+
mixed += w
|
| 287 |
+
out_audio = {"waveform": mixed, "sample_rate": sr}
|
| 288 |
+
else:
|
| 289 |
+
total_len = sum(a["waveform"].shape[-1] for a in audio_outputs)
|
| 290 |
+
mixed = torch.zeros(1, 1, total_len, dtype=audio_outputs[0]["waveform"].dtype)
|
| 291 |
+
offset = 0
|
| 292 |
+
for a in audio_outputs:
|
| 293 |
+
w = a["waveform"]
|
| 294 |
+
mixed[:, :, offset:offset + w.shape[-1]] += w
|
| 295 |
+
offset += w.shape[-1]
|
| 296 |
+
out_audio = {"waveform": mixed, "sample_rate": sr}
|
| 297 |
+
|
| 298 |
+
return (multitalk_embeds, out_audio, num_frames)
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
NODE_CLASS_MAPPINGS = {
|
| 302 |
+
"WanVideoLongCatAvatarExtendEmbeds": WanVideoLongCatAvatarExtendEmbeds,
|
| 303 |
+
"LongCatAvatarWhisperEmbeds": LongCatAvatarWhisperEmbeds,
|
| 304 |
+
}
|
| 305 |
+
NODE_DISPLAY_NAME_MAPPINGS = {
|
| 306 |
+
"WanVideoLongCatAvatarExtendEmbeds": "WanVideo LongCat Avatar Extend Embeds",
|
| 307 |
+
"LongCatAvatarWhisperEmbeds": "LongCat Avatar Whisper Embeds (v1.5)",
|
| 308 |
+
}
|
custom_nodes/ComfyUI-WanVideoWrapper/LongVie2/__pycache__/nodes.cpython-313.pyc
ADDED
|
Binary file (6.08 kB). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/LongVie2/modules.py
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
from einops import rearrange
|
| 4 |
+
|
| 5 |
+
from ..wanvideo.modules.attention import attention
|
| 6 |
+
|
| 7 |
+
def modulate(x: torch.Tensor, shift: torch.Tensor, scale: torch.Tensor):
|
| 8 |
+
return (x * (1 + scale) + shift)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def sinusoidal_embedding_1d(dim, position):
|
| 12 |
+
sinusoid = torch.outer(position.type(torch.float64), torch.pow(
|
| 13 |
+
10000, -torch.arange(dim//2, dtype=torch.float64, device=position.device).div(dim//2)))
|
| 14 |
+
x = torch.cat([torch.cos(sinusoid), torch.sin(sinusoid)], dim=1)
|
| 15 |
+
return x.to(position.dtype)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def precompute_freqs_cis_3d(dim: int, end: int = 1024, theta: float = 10000.0):
|
| 19 |
+
# 3d rope precompute
|
| 20 |
+
f_freqs_cis = precompute_freqs_cis(dim - 2 * (dim // 3), end, theta)
|
| 21 |
+
h_freqs_cis = precompute_freqs_cis(dim // 3, end, theta)
|
| 22 |
+
w_freqs_cis = precompute_freqs_cis(dim // 3, end, theta)
|
| 23 |
+
return f_freqs_cis, h_freqs_cis, w_freqs_cis
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def precompute_freqs_cis(dim: int, end: int = 1024, theta: float = 10000.0):
|
| 27 |
+
# 1d rope precompute
|
| 28 |
+
freqs = 1.0 / (theta ** (torch.arange(0, dim, 2)
|
| 29 |
+
[: (dim // 2)].double() / dim))
|
| 30 |
+
freqs = torch.outer(torch.arange(end, device=freqs.device), freqs)
|
| 31 |
+
freqs_cis = torch.polar(torch.ones_like(freqs), freqs) # complex64
|
| 32 |
+
return freqs_cis
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def rope_apply(x, freqs, num_heads):
|
| 36 |
+
x = rearrange(x, "b s (n d) -> b s n d", n=num_heads)
|
| 37 |
+
x_out = torch.view_as_complex(x.to(torch.float64).reshape(
|
| 38 |
+
x.shape[0], x.shape[1], x.shape[2], -1, 2))
|
| 39 |
+
x_out = torch.view_as_real(x_out * freqs).flatten(2)
|
| 40 |
+
return x_out.to(x.dtype)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class RMSNorm(nn.Module):
|
| 44 |
+
def __init__(self, dim, eps=1e-5):
|
| 45 |
+
super().__init__()
|
| 46 |
+
self.eps = eps
|
| 47 |
+
self.weight = nn.Parameter(torch.ones(dim))
|
| 48 |
+
|
| 49 |
+
def norm(self, x):
|
| 50 |
+
return x * torch.rsqrt(x.pow(2).mean(dim=-1, keepdim=True) + self.eps)
|
| 51 |
+
|
| 52 |
+
def forward(self, x):
|
| 53 |
+
dtype = x.dtype
|
| 54 |
+
return self.norm(x.float()).to(dtype) * self.weight
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class AttentionModule(nn.Module):
|
| 58 |
+
def __init__(self, num_heads, head_dim):
|
| 59 |
+
super().__init__()
|
| 60 |
+
self.num_heads = num_heads
|
| 61 |
+
self.head_dim = head_dim
|
| 62 |
+
|
| 63 |
+
def forward(self, q, k, v):
|
| 64 |
+
b, n, d = q.size(0), self.num_heads, self.head_dim
|
| 65 |
+
x = attention(
|
| 66 |
+
q.view(b, -1, n, d),
|
| 67 |
+
k.view(b, -1, n, d),
|
| 68 |
+
v.view(b, -1, n, d)
|
| 69 |
+
)
|
| 70 |
+
return x.flatten(2)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
class SelfAttention(nn.Module):
|
| 74 |
+
def __init__(self, dim: int, num_heads: int, eps: float = 1e-6):
|
| 75 |
+
super().__init__()
|
| 76 |
+
self.dim = dim
|
| 77 |
+
self.num_heads = num_heads
|
| 78 |
+
self.head_dim = dim // num_heads
|
| 79 |
+
|
| 80 |
+
self.q = nn.Linear(dim, dim)
|
| 81 |
+
self.k = nn.Linear(dim, dim)
|
| 82 |
+
self.v = nn.Linear(dim, dim)
|
| 83 |
+
self.o = nn.Linear(dim, dim)
|
| 84 |
+
self.norm_q = RMSNorm(dim, eps=eps)
|
| 85 |
+
self.norm_k = RMSNorm(dim, eps=eps)
|
| 86 |
+
|
| 87 |
+
self.attn = AttentionModule(self.num_heads, self.head_dim)
|
| 88 |
+
|
| 89 |
+
def forward(self, x, freqs):
|
| 90 |
+
q = self.norm_q(self.q(x))
|
| 91 |
+
k = self.norm_k(self.k(x))
|
| 92 |
+
v = self.v(x)
|
| 93 |
+
q = rope_apply(q, freqs, self.num_heads)
|
| 94 |
+
k = rope_apply(k, freqs, self.num_heads)
|
| 95 |
+
x = self.attn(q, k, v)
|
| 96 |
+
return self.o(x)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
class CrossAttention(nn.Module):
|
| 100 |
+
def __init__(self, dim: int, num_heads: int, eps: float = 1e-6, clip_fea: torch.Tensor = None):
|
| 101 |
+
super().__init__()
|
| 102 |
+
self.dim = dim
|
| 103 |
+
self.num_heads = num_heads
|
| 104 |
+
self.head_dim = dim // num_heads
|
| 105 |
+
|
| 106 |
+
self.q = nn.Linear(dim, dim)
|
| 107 |
+
self.k = nn.Linear(dim, dim)
|
| 108 |
+
self.v = nn.Linear(dim, dim)
|
| 109 |
+
self.o = nn.Linear(dim, dim)
|
| 110 |
+
self.norm_q = RMSNorm(dim, eps=eps)
|
| 111 |
+
self.norm_k = RMSNorm(dim, eps=eps)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
self.k_img = nn.Linear(dim, dim)
|
| 115 |
+
self.v_img = nn.Linear(dim, dim)
|
| 116 |
+
self.norm_k_img = RMSNorm(dim, eps=eps)
|
| 117 |
+
|
| 118 |
+
self.attn = AttentionModule(self.num_heads, self.head_dim)
|
| 119 |
+
|
| 120 |
+
def forward(self, x: torch.Tensor, y: torch.Tensor, clip_fea: torch.Tensor = None):
|
| 121 |
+
ctx = y
|
| 122 |
+
q = self.norm_q(self.q(x))
|
| 123 |
+
k = self.norm_k(self.k(ctx))
|
| 124 |
+
v = self.v(ctx)
|
| 125 |
+
x = self.attn(q, k, v)
|
| 126 |
+
if clip_fea is not None:
|
| 127 |
+
k_img = self.norm_k_img(self.k_img(clip_fea))
|
| 128 |
+
v_img = self.v_img(clip_fea)
|
| 129 |
+
y = self.attn(q, k_img, v_img)
|
| 130 |
+
x = x + y
|
| 131 |
+
return self.o(x)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
class GateModule(nn.Module):
|
| 135 |
+
def __init__(self,):
|
| 136 |
+
super().__init__()
|
| 137 |
+
|
| 138 |
+
def forward(self, x, gate, residual):
|
| 139 |
+
return x + gate * residual
|
| 140 |
+
|
| 141 |
+
class DiTBlock(nn.Module):
|
| 142 |
+
def __init__(self, dim: int, num_heads: int, ffn_dim: int, eps: float = 1e-6):
|
| 143 |
+
super().__init__()
|
| 144 |
+
self.dim = dim
|
| 145 |
+
self.num_heads = num_heads
|
| 146 |
+
self.ffn_dim = ffn_dim
|
| 147 |
+
|
| 148 |
+
self.self_attn = SelfAttention(dim, num_heads, eps)
|
| 149 |
+
self.cross_attn = CrossAttention(dim, num_heads, eps)
|
| 150 |
+
self.norm1 = nn.LayerNorm(dim, eps=eps, elementwise_affine=False)
|
| 151 |
+
self.norm2 = nn.LayerNorm(dim, eps=eps, elementwise_affine=False)
|
| 152 |
+
self.norm3 = nn.LayerNorm(dim, eps=eps)
|
| 153 |
+
self.ffn = nn.Sequential(nn.Linear(dim, ffn_dim), nn.GELU(
|
| 154 |
+
approximate='tanh'), nn.Linear(ffn_dim, dim))
|
| 155 |
+
self.modulation = nn.Parameter(torch.randn(1, 6, dim) / dim**0.5)
|
| 156 |
+
self.gate = GateModule()
|
| 157 |
+
|
| 158 |
+
def forward(self, x, context, t_mod, freqs, clip_fea=None):
|
| 159 |
+
has_seq = len(t_mod.shape) == 4
|
| 160 |
+
chunk_dim = 2 if has_seq else 1
|
| 161 |
+
# msa: multi-head self-attention mlp: multi-layer perceptron
|
| 162 |
+
shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = (
|
| 163 |
+
self.modulation.to(dtype=t_mod.dtype, device=t_mod.device) + t_mod).chunk(6, dim=chunk_dim)
|
| 164 |
+
if has_seq:
|
| 165 |
+
shift_msa, scale_msa, gate_msa, shift_mlp, scale_mlp, gate_mlp = (
|
| 166 |
+
shift_msa.squeeze(2), scale_msa.squeeze(2), gate_msa.squeeze(2),
|
| 167 |
+
shift_mlp.squeeze(2), scale_mlp.squeeze(2), gate_mlp.squeeze(2),
|
| 168 |
+
)
|
| 169 |
+
input_x = modulate(self.norm1(x), shift_msa, scale_msa)
|
| 170 |
+
x = self.gate(x, gate_msa, self.self_attn(input_x, freqs))
|
| 171 |
+
x = x + self.cross_attn(self.norm3(x), context, clip_fea=clip_fea)
|
| 172 |
+
input_x = modulate(self.norm2(x), shift_mlp, scale_mlp)
|
| 173 |
+
x = self.gate(x, gate_mlp, self.ffn(input_x))
|
| 174 |
+
return x
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
class WanModelDualControl(torch.nn.Module):
|
| 178 |
+
def __init__(self, dim: int, ffn_dim: int, eps: float, num_heads: int, control_layers = 12):
|
| 179 |
+
super().__init__()
|
| 180 |
+
self.control_layers = control_layers
|
| 181 |
+
self.control_blocks_dense = nn.ModuleList([
|
| 182 |
+
DiTBlock(dim//2, num_heads//2, ffn_dim//2, eps)
|
| 183 |
+
for _ in range(self.control_layers)
|
| 184 |
+
])
|
| 185 |
+
|
| 186 |
+
self.control_blocks_sparse = nn.ModuleList([
|
| 187 |
+
DiTBlock(dim//2, num_heads//2, ffn_dim//2, eps)
|
| 188 |
+
for _ in range(self.control_layers)
|
| 189 |
+
])
|
| 190 |
+
|
| 191 |
+
self.control_initial_combine_linear_dense = torch.nn.Linear(dim, dim//2)
|
| 192 |
+
self.control_initial_combine_linear_sparse = torch.nn.Linear(dim, dim//2)
|
| 193 |
+
|
| 194 |
+
self.control_text_linear = torch.nn.Linear(dim, dim//2)
|
| 195 |
+
self.control_t_mod = torch.nn.Linear(dim, dim//2)
|
| 196 |
+
|
| 197 |
+
self.control_combine_linears = torch.nn.ModuleList([torch.nn.Linear(dim//2, dim) for _ in range(self.control_layers)])
|
| 198 |
+
head_dim = dim // num_heads
|
| 199 |
+
self.freqs = precompute_freqs_cis_3d(head_dim)
|
custom_nodes/ComfyUI-WanVideoWrapper/LongVie2/nodes.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from ..utils import log
|
| 3 |
+
import comfy.model_management as mm
|
| 4 |
+
|
| 5 |
+
device = mm.get_torch_device()
|
| 6 |
+
offload_device = mm.unet_offload_device()
|
| 7 |
+
|
| 8 |
+
class WanVideoAddDualControlEmbeds:
|
| 9 |
+
@classmethod
|
| 10 |
+
def INPUT_TYPES(s):
|
| 11 |
+
return {"required": {
|
| 12 |
+
"embeds": ("WANVIDIMAGE_EMBEDS",),
|
| 13 |
+
"vae": ("WANVAE", {"tooltip": "VAE model"}),
|
| 14 |
+
"strength": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01, "tooltip": "Strength of the reference embedding"}),
|
| 15 |
+
"start_percent": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "Start percentage of the embedding application"}),
|
| 16 |
+
"end_percent": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "End percentage of the embedding application"}),
|
| 17 |
+
"first_frame_noise_level": ("FLOAT", {"default": 0.925926, "min": 0.0, "max": 1.0, "step": 0.000001, "tooltip": "Noise level for the first frame when using previous frames"}),
|
| 18 |
+
},
|
| 19 |
+
"optional": {
|
| 20 |
+
"dense": ("IMAGE", {"tooltip": "Dense control signal (depth) video input"}),
|
| 21 |
+
"sparse": ("IMAGE", {"tooltip": "Sparse control signal (tracks) video input"}),
|
| 22 |
+
"prev_images": ("IMAGE", {"tooltip": "Previous frames for temporal consistency, default is 8 frames"}),
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
RETURN_TYPES = ("WANVIDIMAGE_EMBEDS",)
|
| 27 |
+
RETURN_NAMES = ("image_embeds",)
|
| 28 |
+
FUNCTION = "add"
|
| 29 |
+
CATEGORY = "WanVideoWrapper"
|
| 30 |
+
|
| 31 |
+
def add(self, embeds, vae, strength, start_percent, end_percent, first_frame_noise_level, dense=None, sparse=None, prev_images=None):
|
| 32 |
+
updated = dict(embeds)
|
| 33 |
+
updated.setdefault("dual_control", {})
|
| 34 |
+
|
| 35 |
+
if dense is None and sparse is None:
|
| 36 |
+
raise ValueError("At least one of dense or sparse inputs must be provided.")
|
| 37 |
+
|
| 38 |
+
num_frames = dense.shape[0] if dense is not None else sparse.shape[0]
|
| 39 |
+
height = dense.shape[1] if dense is not None else sparse.shape[1]
|
| 40 |
+
width = dense.shape[2] if dense is not None else sparse.shape[2]
|
| 41 |
+
msk = torch.ones(1, num_frames, height//8, width//8, device=device)
|
| 42 |
+
msk[:, 1:] = 0
|
| 43 |
+
msk = torch.concat([torch.repeat_interleave(msk[:, 0:1], repeats=4, dim=1), msk[:, 1:]], dim=1)
|
| 44 |
+
msk = msk.view(1, msk.shape[1] // 4, 4, height//8, width//8)
|
| 45 |
+
msk = msk.transpose(1, 2)
|
| 46 |
+
|
| 47 |
+
dense_input_latent = sparse_input_latent = None
|
| 48 |
+
|
| 49 |
+
vae.to(device)
|
| 50 |
+
if dense is not None:
|
| 51 |
+
dense_images = 1 - dense[..., :3] # Invert colors for depth to match the usual range in comfy
|
| 52 |
+
dense_images = dense_images.permute(3, 0, 1, 2) * 2 - 1
|
| 53 |
+
dense_video_latent = vae.encode([dense_images.to(device, vae.dtype)], device, tiled=False)
|
| 54 |
+
dense_first = (dense_images[:, :1]).to(device, vae.dtype)
|
| 55 |
+
vae_input_dense = torch.cat([dense_first, torch.zeros(3, num_frames-1, height, width, device=device, dtype=vae.dtype)], dim=1)
|
| 56 |
+
dense_concat_latent = vae.encode([vae_input_dense], device, tiled=False)
|
| 57 |
+
dense_concat_latent = torch.cat([msk, dense_concat_latent], dim=1)
|
| 58 |
+
dense_input_latent = torch.cat([dense_video_latent, dense_concat_latent],dim=1)
|
| 59 |
+
if sparse is not None:
|
| 60 |
+
sparse_images = sparse[..., :3].permute(3, 0, 1, 2) * 2 - 1
|
| 61 |
+
sparse_video_latent = vae.encode([sparse_images.to(device, vae.dtype)], device, tiled=False)
|
| 62 |
+
sparse_first = (sparse_images[:, :1]).to(device, vae.dtype)
|
| 63 |
+
vae_input_sparse = torch.cat([sparse_first, torch.zeros(3, num_frames-1, height, width, device=device, dtype=vae.dtype)], dim=1)
|
| 64 |
+
sparse_concat_latent = vae.encode([vae_input_sparse], device, tiled=False)
|
| 65 |
+
sparse_concat_latent = torch.cat([msk, sparse_concat_latent], dim=1)
|
| 66 |
+
sparse_input_latent = torch.cat([sparse_video_latent, sparse_concat_latent],dim=1)
|
| 67 |
+
|
| 68 |
+
if prev_images is not None:
|
| 69 |
+
prev_images = prev_images[..., :3].permute(3, 0, 1, 2) * 2 - 1
|
| 70 |
+
prev_video_latent = vae.encode([prev_images.to(device, vae.dtype)], device, tiled=False)
|
| 71 |
+
updated["dual_control"]["prev_latent"] = prev_video_latent[0]
|
| 72 |
+
|
| 73 |
+
vae.to(offload_device)
|
| 74 |
+
updated["dual_control"]["dense_input_latent"] = dense_input_latent
|
| 75 |
+
updated["dual_control"]["sparse_input_latent"] = sparse_input_latent
|
| 76 |
+
updated["dual_control"]["strength"] = strength
|
| 77 |
+
updated["dual_control"]["start_percent"] = start_percent
|
| 78 |
+
updated["dual_control"]["end_percent"] = end_percent
|
| 79 |
+
updated["dual_control"]["first_frame_noise_level"] = first_frame_noise_level
|
| 80 |
+
return (updated,)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
NODE_CLASS_MAPPINGS = {
|
| 84 |
+
"WanVideoAddDualControlEmbeds": WanVideoAddDualControlEmbeds,
|
| 85 |
+
}
|
| 86 |
+
NODE_DISPLAY_NAME_MAPPINGS = {
|
| 87 |
+
"WanVideoAddDualControlEmbeds": "WanVideo Add Dual Control Embeds",
|
| 88 |
+
}
|
custom_nodes/ComfyUI-WanVideoWrapper/MTV/__pycache__/mtv.cpython-313.pyc
ADDED
|
Binary file (11 kB). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/MTV/__pycache__/nodes.cpython-313.pyc
ADDED
|
Binary file (16.3 kB). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/MTV/data/mean.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3ababeaabf5ac096ce7c7714ada14aa1de8355c0016de25695be611d51285141
|
| 3 |
+
size 416
|
custom_nodes/ComfyUI-WanVideoWrapper/MTV/data/std.npy
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:650e46902a0878e6947be401e4e1995e54a8fd407f2be3ded0dda62bda99a9b3
|
| 3 |
+
size 416
|
custom_nodes/ComfyUI-WanVideoWrapper/MTV/draw_pose.py
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import math
|
| 3 |
+
import torch
|
| 4 |
+
import numpy as np
|
| 5 |
+
from PIL import Image
|
| 6 |
+
from torchvision import transforms
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def intrinsic_matrix_from_field_of_view(imshape, fov_degrees:float =55 ): # nlf default fov_degrees 55
|
| 10 |
+
imshape = np.array(imshape)
|
| 11 |
+
fov_radians = fov_degrees * np.array(np.pi / 180)
|
| 12 |
+
larger_side = np.max(imshape)
|
| 13 |
+
focal_length = larger_side / (np.tan(fov_radians / 2) * 2)
|
| 14 |
+
# intrinsic_matrix 3*3
|
| 15 |
+
return np.array([
|
| 16 |
+
[focal_length, 0, imshape[1] / 2],
|
| 17 |
+
[0, focal_length, imshape[0] / 2],
|
| 18 |
+
[0, 0, 1],
|
| 19 |
+
])
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def p3d_to_p2d(point_3d, height, width): # point3d n*1024*3
|
| 23 |
+
camera_matrix = intrinsic_matrix_from_field_of_view((height,width))
|
| 24 |
+
camera_matrix = np.expand_dims(camera_matrix, axis=0)
|
| 25 |
+
camera_matrix = np.expand_dims(camera_matrix, axis=0) # 1*1*3*3
|
| 26 |
+
point_3d = np.expand_dims(point_3d,axis=-1) # n*1024*3*1
|
| 27 |
+
point_2d = (camera_matrix@point_3d).squeeze(-1)
|
| 28 |
+
point_2d[:,:,:2] = point_2d[:,:,:2]/point_2d[:,:,2:3]
|
| 29 |
+
return point_2d[:,:,:] # n*1024*2
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def get_pose_images(smpl_data, offset):
|
| 33 |
+
pose_images = []
|
| 34 |
+
for data in smpl_data:
|
| 35 |
+
if isinstance(data, np.ndarray):
|
| 36 |
+
joints3d = data
|
| 37 |
+
else:
|
| 38 |
+
joints3d = data.numpy()
|
| 39 |
+
canvas = np.zeros(shape=(offset[0], offset[1], 3), dtype=np.uint8)
|
| 40 |
+
joints3d = p3d_to_p2d(joints3d, offset[0], offset[1])
|
| 41 |
+
canvas = draw_3d_points(canvas, joints3d[0], stickwidth=int(offset[1]/350))
|
| 42 |
+
pose_images.append(Image.fromarray(canvas))
|
| 43 |
+
return pose_images
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def get_control_conditions(poses, h, w, stick_width=1.0, point_radius=2, style="original"):
|
| 47 |
+
control_images = []
|
| 48 |
+
for idx, pose in enumerate(poses):
|
| 49 |
+
canvas = np.zeros(shape=(h, w, 3), dtype=np.uint8)
|
| 50 |
+
try:
|
| 51 |
+
joints3d = p3d_to_p2d(pose, h, w)
|
| 52 |
+
if style == "original":
|
| 53 |
+
canvas = draw_3d_points(
|
| 54 |
+
canvas,
|
| 55 |
+
joints3d[0],
|
| 56 |
+
stickwidth=int(h / 350 * stick_width),
|
| 57 |
+
r=point_radius,
|
| 58 |
+
)
|
| 59 |
+
elif style == "scail":
|
| 60 |
+
canvas = draw_3d_points_scail(
|
| 61 |
+
canvas,
|
| 62 |
+
joints3d[0],
|
| 63 |
+
stickwidth=int(h / 350 * stick_width),
|
| 64 |
+
r=point_radius,
|
| 65 |
+
)
|
| 66 |
+
resized_canvas = cv2.resize(canvas, (w, h))
|
| 67 |
+
# Image.fromarray(resized_canvas).save(f'tmp/{idx}_pose.jpg')
|
| 68 |
+
control_images.append(resized_canvas)
|
| 69 |
+
except Exception:
|
| 70 |
+
control_images.append(Image.fromarray(canvas))
|
| 71 |
+
control_pixel_values = np.array(control_images)
|
| 72 |
+
control_pixel_values = torch.from_numpy(control_pixel_values).contiguous() / 255.
|
| 73 |
+
return control_pixel_values
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def draw_3d_points(canvas, points, stickwidth=2, r=2, draw_line=True):
|
| 77 |
+
colors = [
|
| 78 |
+
[255, 0, 0], # 0
|
| 79 |
+
[0, 255, 0], # 1
|
| 80 |
+
[0, 0, 255], # 2
|
| 81 |
+
[255, 0, 255], # 3
|
| 82 |
+
[255, 255, 0], # 4
|
| 83 |
+
[85, 255, 0], # 5
|
| 84 |
+
[0, 75, 255], # 6
|
| 85 |
+
[0, 255, 85], # 7
|
| 86 |
+
[0, 255, 170], # 8
|
| 87 |
+
[170, 0, 255], # 9
|
| 88 |
+
[85, 0, 255], # 10
|
| 89 |
+
[0, 85, 255], # 11
|
| 90 |
+
[0, 255, 255], # 12
|
| 91 |
+
[85, 0, 255], # 13
|
| 92 |
+
[170, 0, 255], # 14
|
| 93 |
+
[255, 0, 255], # 15
|
| 94 |
+
[255, 0, 170], # 16
|
| 95 |
+
[255, 0, 85], # 17
|
| 96 |
+
]
|
| 97 |
+
connetions = [
|
| 98 |
+
[15,12],[12, 16],[16, 18],[18, 20],[20, 22],
|
| 99 |
+
[12,17],[17,19],[19,21],
|
| 100 |
+
[21,23],[12,9],[9,6],
|
| 101 |
+
[6,3],[3,0],[0,1],
|
| 102 |
+
[1,4],[4,7],[7,10],[0,2],[2,5],[5,8],[8,11]
|
| 103 |
+
]
|
| 104 |
+
connection_colors = [
|
| 105 |
+
[255, 0, 0], # 0
|
| 106 |
+
[0, 255, 0], # 1
|
| 107 |
+
[0, 0, 255], # 2
|
| 108 |
+
[255, 255, 0], # 3
|
| 109 |
+
[255, 0, 255], # 4
|
| 110 |
+
[0, 255, 0], # 5
|
| 111 |
+
[0, 85, 255], # 6
|
| 112 |
+
[255, 175, 0], # 7
|
| 113 |
+
[0, 0, 255], # 8
|
| 114 |
+
[255, 85, 0], # 9
|
| 115 |
+
[0, 255, 85], # 10
|
| 116 |
+
[255, 0, 255], # 11
|
| 117 |
+
[255, 0, 0], # 12
|
| 118 |
+
[0, 175, 255], # 13
|
| 119 |
+
[255, 255, 0], # 14
|
| 120 |
+
[0, 0, 255], # 15
|
| 121 |
+
[0, 255, 0], # 16
|
| 122 |
+
]
|
| 123 |
+
|
| 124 |
+
# draw point
|
| 125 |
+
for i in range(len(points)):
|
| 126 |
+
x,y = points[i][0:2]
|
| 127 |
+
x,y = int(x),int(y)
|
| 128 |
+
if i==13 or i == 14:
|
| 129 |
+
continue
|
| 130 |
+
cv2.circle(canvas, (x, y), r, colors[i%17], thickness=-1)
|
| 131 |
+
|
| 132 |
+
# draw line
|
| 133 |
+
if draw_line:
|
| 134 |
+
for i in range(len(connetions)):
|
| 135 |
+
point1_idx,point2_idx = connetions[i][0:2]
|
| 136 |
+
point1 = points[point1_idx]
|
| 137 |
+
point2 = points[point2_idx]
|
| 138 |
+
Y = [point2[0],point1[0]]
|
| 139 |
+
X = [point2[1],point1[1]]
|
| 140 |
+
mX = int(np.mean(X))
|
| 141 |
+
mY = int(np.mean(Y))
|
| 142 |
+
length = ((X[0] - X[1]) ** 2 + (Y[0] - Y[1]) ** 2) ** 0.5
|
| 143 |
+
angle = math.degrees(math.atan2(X[0] - X[1], Y[0] - Y[1]))
|
| 144 |
+
polygon = cv2.ellipse2Poly((mY, mX), (int(length / 2), stickwidth), int(angle), 0, 360, 1)
|
| 145 |
+
cv2.fillConvexPoly(canvas, polygon, connection_colors[i%17])
|
| 146 |
+
|
| 147 |
+
return canvas
|
| 148 |
+
|
| 149 |
+
def draw_3d_points_scail(canvas, points, stickwidth=2, r=2, draw_line=True):
|
| 150 |
+
|
| 151 |
+
connetions = [
|
| 152 |
+
[15,12],[12, 16],[16, 18],[18, 20],[20, 22], # 0-4: Left arm chain
|
| 153 |
+
[12,17],[17,19],[19,21], # 5-7: Right arm chain
|
| 154 |
+
[21,23], # 8: Right hand
|
| 155 |
+
[12,1],[1,4],[4,7], # 9-11: Neck to left leg (hip, thigh, shin)
|
| 156 |
+
[12,2],[2,5],[5,8], # 12-14: Neck to right leg (hip, thigh, shin)
|
| 157 |
+
]
|
| 158 |
+
|
| 159 |
+
# Warm colors for right side, cool colors for left side
|
| 160 |
+
connection_colors = [
|
| 161 |
+
[180, 180, 180], # 0: [15,12] - L. clavicle (Bright Cyan)
|
| 162 |
+
[0, 200, 255], # 1: [12,16] - L. shoulder (Bright Cyan)
|
| 163 |
+
[0, 120, 255], # 2: [16,18] - L. upper arm (Bright Blue)
|
| 164 |
+
[0, 60, 255], # 3: [18,20] - L. forearm (Deep Blue)
|
| 165 |
+
[60, 0, 255], # 4: [20,22] - L. hand (Blue-Purple)
|
| 166 |
+
[255, 0, 0], # 5: [12,17] - R. clavicle (Bright Red)
|
| 167 |
+
[255, 100, 0], # 6: [17,19] - R. upper arm (Bright Orange)
|
| 168 |
+
[255, 180, 0], # 7: [19,21] - R. forearm (Golden Orange)
|
| 169 |
+
[255, 255, 0], # 8: [21,23] - R. hand (Bright Yellow)
|
| 170 |
+
[30, 27, 160], # 9: [12,1] - Neck to L. hip (purple-blue)
|
| 171 |
+
[73, 27, 177], # 10: [1,4] - L. thigh (purple)
|
| 172 |
+
[145, 27, 194], # 11: [4,7] - L. shin (magenta)
|
| 173 |
+
[200, 255, 100], # 12: [12,2] - Neck to R. hip (yellow)
|
| 174 |
+
[54, 201, 52], # 13: [2,5] - R. thigh (green)
|
| 175 |
+
[30, 176, 85], # 14: [5,8] - R. shin (green)
|
| 176 |
+
]
|
| 177 |
+
|
| 178 |
+
# draw line
|
| 179 |
+
if draw_line:
|
| 180 |
+
# Collect all joints that are part of connections
|
| 181 |
+
joints_in_use = set()
|
| 182 |
+
for connection in connetions:
|
| 183 |
+
joints_in_use.add(connection[0])
|
| 184 |
+
joints_in_use.add(connection[1])
|
| 185 |
+
|
| 186 |
+
for i in range(len(connetions)):
|
| 187 |
+
point1_idx, point2_idx = connetions[i][0:2]
|
| 188 |
+
point1 = points[point1_idx]
|
| 189 |
+
point2 = points[point2_idx]
|
| 190 |
+
x1, y1 = int(point1[0]), int(point1[1])
|
| 191 |
+
x2, y2 = int(point2[0]), int(point2[1])
|
| 192 |
+
cv2.line(canvas, (x1, y1), (x2, y2), connection_colors[i], stickwidth)
|
| 193 |
+
|
| 194 |
+
# draw points for joints that have connections
|
| 195 |
+
joints_in_use = set()
|
| 196 |
+
for connection in connetions:
|
| 197 |
+
joints_in_use.add(connection[0])
|
| 198 |
+
joints_in_use.add(connection[1])
|
| 199 |
+
|
| 200 |
+
for joint_idx in joints_in_use:
|
| 201 |
+
if joint_idx >= len(points):
|
| 202 |
+
continue
|
| 203 |
+
x, y = points[joint_idx][0:2]
|
| 204 |
+
x, y = int(x), int(y)
|
| 205 |
+
# Use the color from the first connection involving this joint
|
| 206 |
+
joint_color = [180, 180, 180] # default grey
|
| 207 |
+
for i, connection in enumerate(connetions):
|
| 208 |
+
if connection[0] == joint_idx or connection[1] == joint_idx:
|
| 209 |
+
joint_color = connection_colors[i]
|
| 210 |
+
break
|
| 211 |
+
cv2.circle(canvas, (x, y), r, joint_color, thickness=-1)
|
| 212 |
+
|
| 213 |
+
return canvas
|
custom_nodes/ComfyUI-WanVideoWrapper/MTV/motion4d/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from .vqvae import SMPL_VQVAE, VectorQuantizer, Encoder, Decoder
|
custom_nodes/ComfyUI-WanVideoWrapper/MTV/motion4d/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (307 Bytes). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/MTV/motion4d/__pycache__/vqvae.cpython-313.pyc
ADDED
|
Binary file (17.9 kB). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/MTV/motion4d/vqvae.py
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
import torch.nn.functional as F
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class Encoder(nn.Module):
|
| 8 |
+
def __init__(
|
| 9 |
+
self,
|
| 10 |
+
in_channels=3,
|
| 11 |
+
mid_channels=[128, 512],
|
| 12 |
+
out_channels=3072,
|
| 13 |
+
downsample_time=[1, 1],
|
| 14 |
+
downsample_joint=[1, 1],
|
| 15 |
+
num_attention_heads=8,
|
| 16 |
+
attention_head_dim=64,
|
| 17 |
+
dim=3072,
|
| 18 |
+
):
|
| 19 |
+
super(Encoder, self).__init__()
|
| 20 |
+
|
| 21 |
+
self.conv_in = nn.Conv2d(in_channels, mid_channels[0], kernel_size=3, stride=1, padding=1)
|
| 22 |
+
self.resnet1 = nn.ModuleList([ResBlock(mid_channels[0], mid_channels[0]) for _ in range(3)])
|
| 23 |
+
self.downsample1 = Downsample(mid_channels[0], mid_channels[0], downsample_time[0], downsample_joint[0])
|
| 24 |
+
self.resnet2 = ResBlock(mid_channels[0], mid_channels[1])
|
| 25 |
+
self.resnet3 = nn.ModuleList([ResBlock(mid_channels[1], mid_channels[1]) for _ in range(3)])
|
| 26 |
+
self.downsample2 = Downsample(mid_channels[1], mid_channels[1], downsample_time[1], downsample_joint[1])
|
| 27 |
+
self.conv_out = nn.Conv2d(mid_channels[-1], out_channels, kernel_size=3, stride=1, padding=1)
|
| 28 |
+
|
| 29 |
+
def forward(self, x):
|
| 30 |
+
x = self.conv_in(x)
|
| 31 |
+
for resnet in self.resnet1:
|
| 32 |
+
x = resnet(x)
|
| 33 |
+
x = self.downsample1(x)
|
| 34 |
+
|
| 35 |
+
x = self.resnet2(x)
|
| 36 |
+
for resnet in self.resnet3:
|
| 37 |
+
x = resnet(x)
|
| 38 |
+
x = self.downsample2(x)
|
| 39 |
+
|
| 40 |
+
x = self.conv_out(x)
|
| 41 |
+
|
| 42 |
+
return x
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class VectorQuantizer(nn.Module):
|
| 47 |
+
def __init__(self, nb_code, code_dim):
|
| 48 |
+
super().__init__()
|
| 49 |
+
self.nb_code = nb_code
|
| 50 |
+
self.code_dim = code_dim
|
| 51 |
+
self.mu = 0.99
|
| 52 |
+
self.reset_codebook()
|
| 53 |
+
self.reset_count = 0
|
| 54 |
+
self.usage = torch.zeros((self.nb_code, 1))
|
| 55 |
+
|
| 56 |
+
def reset_codebook(self):
|
| 57 |
+
self.init = False
|
| 58 |
+
self.code_sum = None
|
| 59 |
+
self.code_count = None
|
| 60 |
+
self.register_buffer('codebook', torch.zeros(self.nb_code, self.code_dim).cuda())
|
| 61 |
+
|
| 62 |
+
def _tile(self, x):
|
| 63 |
+
nb_code_x, code_dim = x.shape
|
| 64 |
+
if nb_code_x < self.nb_code:
|
| 65 |
+
n_repeats = (self.nb_code + nb_code_x - 1) // nb_code_x
|
| 66 |
+
std = 0.01 / np.sqrt(code_dim)
|
| 67 |
+
out = x.repeat(n_repeats, 1)
|
| 68 |
+
out = out + torch.randn_like(out) * std
|
| 69 |
+
else:
|
| 70 |
+
out = x
|
| 71 |
+
return out
|
| 72 |
+
|
| 73 |
+
def preprocess(self, x):
|
| 74 |
+
# [bs, c, f, j] -> [bs * f * j, c]
|
| 75 |
+
x = x.permute(0, 2, 3, 1).contiguous()
|
| 76 |
+
x = x.view(-1, x.shape[-1])
|
| 77 |
+
return x
|
| 78 |
+
|
| 79 |
+
def quantize(self, x):
|
| 80 |
+
# [bs * f * j, dim=3072]
|
| 81 |
+
# Calculate latent code x_l
|
| 82 |
+
k_w = self.codebook.t()
|
| 83 |
+
distance = torch.sum(x ** 2, dim=-1, keepdim=True) - 2 * torch.matmul(x, k_w) + torch.sum(k_w ** 2, dim=0, keepdim=True)
|
| 84 |
+
_, code_idx = torch.min(distance, dim=-1)
|
| 85 |
+
return code_idx
|
| 86 |
+
|
| 87 |
+
def dequantize(self, code_idx):
|
| 88 |
+
x = F.embedding(code_idx, self.codebook) # indexing: [bs * f * j, 32]
|
| 89 |
+
return x
|
| 90 |
+
|
| 91 |
+
def forward(self, x, return_vq=False):
|
| 92 |
+
bs, c, f, j = x.shape # SMPL data frames: [bs, 3072, f, j]
|
| 93 |
+
|
| 94 |
+
# Preprocess
|
| 95 |
+
x = self.preprocess(x)
|
| 96 |
+
# return x.view(bs, f*j, c).contiguous(), None
|
| 97 |
+
assert x.shape[-1] == self.code_dim
|
| 98 |
+
|
| 99 |
+
# quantize and dequantize through bottleneck
|
| 100 |
+
code_idx = self.quantize(x)
|
| 101 |
+
x_d = self.dequantize(code_idx)
|
| 102 |
+
|
| 103 |
+
# Loss
|
| 104 |
+
commit_loss = F.mse_loss(x, x_d.detach())
|
| 105 |
+
|
| 106 |
+
# Passthrough
|
| 107 |
+
x_d = x + (x_d - x).detach()
|
| 108 |
+
|
| 109 |
+
if return_vq:
|
| 110 |
+
return x_d.view(bs, f*j, c).contiguous(), commit_loss
|
| 111 |
+
# return (x_d, x_d.view(bs, f, j, c).permute(0, 3, 1, 2).contiguous()), commit_loss, perplexity
|
| 112 |
+
|
| 113 |
+
# Postprocess
|
| 114 |
+
x_d = x_d.view(bs, f, j, c).permute(0, 3, 1, 2).contiguous()
|
| 115 |
+
|
| 116 |
+
return x_d, commit_loss
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
class Decoder(nn.Module):
|
| 122 |
+
def __init__(
|
| 123 |
+
self,
|
| 124 |
+
in_channels=3072,
|
| 125 |
+
mid_channels=[512, 128],
|
| 126 |
+
out_channels=3,
|
| 127 |
+
upsample_rate=None,
|
| 128 |
+
frame_upsample_rate=[1.0, 1.0],
|
| 129 |
+
joint_upsample_rate=[1.0, 1.0],
|
| 130 |
+
dim=128,
|
| 131 |
+
attention_head_dim=64,
|
| 132 |
+
num_attention_heads=8,
|
| 133 |
+
):
|
| 134 |
+
super(Decoder, self).__init__()
|
| 135 |
+
|
| 136 |
+
self.conv_in = nn.Conv2d(in_channels, mid_channels[0], kernel_size=3, stride=1, padding=1)
|
| 137 |
+
self.resnet1 = nn.ModuleList([ResBlock(mid_channels[0], mid_channels[0]) for _ in range(3)])
|
| 138 |
+
self.upsample1 = Upsample(mid_channels[0], mid_channels[0], frame_upsample_rate=frame_upsample_rate[0], joint_upsample_rate=joint_upsample_rate[0])
|
| 139 |
+
self.resnet2 = ResBlock(mid_channels[0], mid_channels[1])
|
| 140 |
+
self.resnet3 = nn.ModuleList([ResBlock(mid_channels[1], mid_channels[1]) for _ in range(3)])
|
| 141 |
+
self.upsample2 = Upsample(mid_channels[1], mid_channels[1], frame_upsample_rate=frame_upsample_rate[1], joint_upsample_rate=joint_upsample_rate[1])
|
| 142 |
+
self.conv_out = nn.Conv2d(mid_channels[-1], out_channels, kernel_size=3, stride=1, padding=1)
|
| 143 |
+
|
| 144 |
+
def forward(self, x):
|
| 145 |
+
x = self.conv_in(x)
|
| 146 |
+
for resnet in self.resnet1:
|
| 147 |
+
x = resnet(x)
|
| 148 |
+
x = self.upsample1(x)
|
| 149 |
+
|
| 150 |
+
x = self.resnet2(x)
|
| 151 |
+
for resnet in self.resnet3:
|
| 152 |
+
x = resnet(x)
|
| 153 |
+
x = self.upsample2(x)
|
| 154 |
+
|
| 155 |
+
x = self.conv_out(x)
|
| 156 |
+
|
| 157 |
+
return x
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
class Upsample(nn.Module):
|
| 161 |
+
def __init__(
|
| 162 |
+
self,
|
| 163 |
+
in_channels,
|
| 164 |
+
out_channels,
|
| 165 |
+
upsample_rate=None,
|
| 166 |
+
frame_upsample_rate=None,
|
| 167 |
+
joint_upsample_rate=None,
|
| 168 |
+
):
|
| 169 |
+
super(Upsample, self).__init__()
|
| 170 |
+
|
| 171 |
+
self.upsampler = nn.Conv1d(in_channels, out_channels, kernel_size=3, stride=1, padding=1)
|
| 172 |
+
self.upsample_rate = upsample_rate
|
| 173 |
+
self.frame_upsample_rate = frame_upsample_rate
|
| 174 |
+
self.joint_upsample_rate = joint_upsample_rate
|
| 175 |
+
self.upsample_rate = upsample_rate
|
| 176 |
+
|
| 177 |
+
def forward(self, inputs):
|
| 178 |
+
if inputs.shape[2] > 1 and inputs.shape[2] % 2 == 1:
|
| 179 |
+
# split first frame
|
| 180 |
+
x_first, x_rest = inputs[:, :, 0], inputs[:, :, 1:]
|
| 181 |
+
|
| 182 |
+
if self.upsample_rate is not None:
|
| 183 |
+
# import pdb; pdb.set_trace()
|
| 184 |
+
x_first = F.interpolate(x_first, scale_factor=self.upsample_rate)
|
| 185 |
+
x_rest = F.interpolate(x_rest, scale_factor=self.upsample_rate)
|
| 186 |
+
else:
|
| 187 |
+
# import pdb; pdb.set_trace()
|
| 188 |
+
# x_first = F.interpolate(x_first, scale_factor=(self.frame_upsample_rate, self.joint_upsample_rate), mode="bilinear", align_corners=True)
|
| 189 |
+
x_rest = F.interpolate(x_rest, scale_factor=(self.frame_upsample_rate, self.joint_upsample_rate), mode="bilinear", align_corners=True)
|
| 190 |
+
x_first = x_first[:, :, None, :]
|
| 191 |
+
inputs = torch.cat([x_first, x_rest], dim=2)
|
| 192 |
+
elif inputs.shape[2] > 1:
|
| 193 |
+
if self.upsample_rate is not None:
|
| 194 |
+
inputs = F.interpolate(inputs, scale_factor=self.upsample_rate)
|
| 195 |
+
else:
|
| 196 |
+
inputs = F.interpolate(inputs, scale_factor=(self.frame_upsample_rate, self.joint_upsample_rate), mode="bilinear", align_corners=True)
|
| 197 |
+
else:
|
| 198 |
+
inputs = inputs.squeeze(2)
|
| 199 |
+
if self.upsample_rate is not None:
|
| 200 |
+
inputs = F.interpolate(inputs, scale_factor=self.upsample_rate)
|
| 201 |
+
else:
|
| 202 |
+
inputs = F.interpolate(inputs, scale_factor=(self.frame_upsample_rate, self.joint_upsample_rate), mode="linear", align_corners=True)
|
| 203 |
+
inputs = inputs[:, :, None, :, :]
|
| 204 |
+
|
| 205 |
+
b, c, t, j = inputs.shape
|
| 206 |
+
inputs = inputs.permute(0, 2, 1, 3).reshape(b * t, c, j)
|
| 207 |
+
inputs = self.upsampler(inputs)
|
| 208 |
+
inputs = inputs.reshape(b, t, *inputs.shape[1:]).permute(0, 2, 1, 3)
|
| 209 |
+
|
| 210 |
+
return inputs
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
class Downsample(nn.Module):
|
| 214 |
+
def __init__(
|
| 215 |
+
self,
|
| 216 |
+
in_channels,
|
| 217 |
+
out_channels,
|
| 218 |
+
frame_downsample_rate,
|
| 219 |
+
joint_downsample_rate
|
| 220 |
+
):
|
| 221 |
+
super(Downsample, self).__init__()
|
| 222 |
+
|
| 223 |
+
self.frame_downsample_rate = frame_downsample_rate
|
| 224 |
+
self.joint_downsample_rate = joint_downsample_rate
|
| 225 |
+
self.joint_downsample = nn.Conv1d(in_channels, out_channels, kernel_size=3, stride=self.joint_downsample_rate, padding=1)
|
| 226 |
+
|
| 227 |
+
def forward(self, x):
|
| 228 |
+
# (batch_size, channels, frames, joints) -> (batch_size * joints, channels, frames)
|
| 229 |
+
if self.frame_downsample_rate > 1:
|
| 230 |
+
batch_size, channels, frames, joints = x.shape
|
| 231 |
+
x = x.permute(0, 3, 1, 2).reshape(batch_size * joints, channels, frames)
|
| 232 |
+
if x.shape[-1] % 2 == 1:
|
| 233 |
+
x_first, x_rest = x[..., 0], x[..., 1:]
|
| 234 |
+
if x_rest.shape[-1] > 0:
|
| 235 |
+
# (batch_size * height * width, channels, frames - 1) -> (batch_size * height * width, channels, (frames - 1) // 2)
|
| 236 |
+
x_rest = F.avg_pool1d(x_rest, kernel_size=self.frame_downsample_rate, stride=self.frame_downsample_rate)
|
| 237 |
+
|
| 238 |
+
x = torch.cat([x_first[..., None], x_rest], dim=-1)
|
| 239 |
+
# (batch_size * joints, channels, (frames // 2) + 1) -> (batch_size, channels, (frames // 2) + 1, joints)
|
| 240 |
+
x = x.reshape(batch_size, joints, channels, x.shape[-1]).permute(0, 2, 3, 1)
|
| 241 |
+
else:
|
| 242 |
+
# (batch_size * joints, channels, frames) -> (batch_size * joints, channels, frames // 2)
|
| 243 |
+
x = F.avg_pool1d(x, kernel_size=2, stride=2)
|
| 244 |
+
# (batch_size * joints, channels, frames // 2) -> (batch_size, height, width, channels, frames // 2) -> (batch_size, channels, frames // 2, height, width)
|
| 245 |
+
x = x.reshape(batch_size, joints, channels, x.shape[-1]).permute(0, 2, 3, 1)
|
| 246 |
+
|
| 247 |
+
# Pad the tensor
|
| 248 |
+
# pad = (0, 1)
|
| 249 |
+
# x = F.pad(x, pad, mode="constant", value=0)
|
| 250 |
+
batch_size, channels, frames, joints = x.shape
|
| 251 |
+
# (batch_size, channels, frames, joints) -> (batch_size * frames, channels, joints)
|
| 252 |
+
x = x.permute(0, 2, 1, 3).reshape(batch_size * frames, channels, joints)
|
| 253 |
+
x = self.joint_downsample(x)
|
| 254 |
+
# (batch_size * frames, channels, joints) -> (batch_size, channels, frames, joints)
|
| 255 |
+
x = x.reshape(batch_size, frames, x.shape[1], x.shape[2]).permute(0, 2, 1, 3)
|
| 256 |
+
return x
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
class ResBlock(nn.Module):
|
| 261 |
+
def __init__(self,
|
| 262 |
+
in_channels,
|
| 263 |
+
out_channels,
|
| 264 |
+
group_num=32,
|
| 265 |
+
max_channels=512):
|
| 266 |
+
super(ResBlock, self).__init__()
|
| 267 |
+
skip = max(1, max_channels // out_channels - 1)
|
| 268 |
+
self.block = nn.Sequential(
|
| 269 |
+
nn.GroupNorm(group_num, in_channels, eps=1e-06, affine=True),
|
| 270 |
+
nn.SiLU(),
|
| 271 |
+
nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=1, padding=skip, dilation=skip),
|
| 272 |
+
nn.GroupNorm(group_num, out_channels, eps=1e-06, affine=True),
|
| 273 |
+
nn.SiLU(),
|
| 274 |
+
nn.Conv2d(out_channels, out_channels, kernel_size=1, stride=1, padding=0),
|
| 275 |
+
)
|
| 276 |
+
self.conv_short = nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=1, padding=0) if in_channels != out_channels else nn.Identity()
|
| 277 |
+
|
| 278 |
+
def forward(self, x):
|
| 279 |
+
hidden_states = self.block(x)
|
| 280 |
+
if hidden_states.shape != x.shape:
|
| 281 |
+
x = self.conv_short(x)
|
| 282 |
+
x = x + hidden_states
|
| 283 |
+
return x
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
class SMPL_VQVAE(nn.Module):
|
| 288 |
+
def __init__(self, encoder, decoder, vq):
|
| 289 |
+
super(SMPL_VQVAE, self).__init__()
|
| 290 |
+
|
| 291 |
+
self.encoder = encoder
|
| 292 |
+
self.decoder = decoder
|
| 293 |
+
self.vq = vq
|
| 294 |
+
|
| 295 |
+
def to(self, device):
|
| 296 |
+
self.encoder = self.encoder.to(device)
|
| 297 |
+
self.decoder = self.decoder.to(device)
|
| 298 |
+
self.vq = self.vq.to(device)
|
| 299 |
+
self.device = device
|
| 300 |
+
return self
|
| 301 |
+
|
| 302 |
+
def encdec_slice_frames(self, x, frame_batch_size, encdec, return_vq):
|
| 303 |
+
num_frames = x.shape[2]
|
| 304 |
+
remaining_frames = num_frames % frame_batch_size
|
| 305 |
+
x_output = []
|
| 306 |
+
|
| 307 |
+
for i in range(num_frames // frame_batch_size):
|
| 308 |
+
remaining_frames = num_frames % frame_batch_size
|
| 309 |
+
start_frame = frame_batch_size * i + (0 if i == 0 else remaining_frames)
|
| 310 |
+
end_frame = frame_batch_size * (i + 1) + remaining_frames
|
| 311 |
+
x_intermediate = x[:, :, start_frame:end_frame]
|
| 312 |
+
x_intermediate = encdec(x_intermediate)
|
| 313 |
+
x_output.append(x_intermediate)
|
| 314 |
+
if encdec == self.encoder and self.vq is not None:
|
| 315 |
+
x_output, loss = self.vq(torch.cat(x_output, dim=2), return_vq=return_vq)
|
| 316 |
+
return x_output, loss
|
| 317 |
+
else:
|
| 318 |
+
return torch.cat(x_output, dim=2), None, None
|
| 319 |
+
|
| 320 |
+
def forward(self, x, return_vq=False):
|
| 321 |
+
x = x.permute(0, 3, 1, 2)
|
| 322 |
+
x, loss = self.encdec_slice_frames(x, frame_batch_size=8, encdec=self.encoder, return_vq=return_vq)
|
| 323 |
+
|
| 324 |
+
if return_vq:
|
| 325 |
+
return x, loss
|
| 326 |
+
x, _, _ = self.encdec_slice_frames(x, frame_batch_size=2, encdec=self.decoder, return_vq=return_vq)
|
| 327 |
+
x = x.permute(0, 2, 3, 1)
|
| 328 |
+
|
| 329 |
+
return x, loss
|
custom_nodes/ComfyUI-WanVideoWrapper/MTV/mtv.py
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
| 8 |
+
pos: Union[np.ndarray, int],
|
| 9 |
+
theta: float = 10000.0,
|
| 10 |
+
use_real=False,
|
| 11 |
+
linear_factor=1.0,
|
| 12 |
+
ntk_factor=1.0,
|
| 13 |
+
repeat_interleave_real=True,
|
| 14 |
+
freqs_dtype=torch.float32, # torch.float32, torch.float64 (flux)
|
| 15 |
+
):
|
| 16 |
+
"""
|
| 17 |
+
Precompute the frequency tensor for complex exponentials (cis) with given dimensions.
|
| 18 |
+
|
| 19 |
+
This function calculates a frequency tensor with complex exponentials using the given dimension 'dim' and the end
|
| 20 |
+
index 'end'. The 'theta' parameter scales the frequencies. The returned tensor contains complex values in complex64
|
| 21 |
+
data type.
|
| 22 |
+
|
| 23 |
+
Args:
|
| 24 |
+
dim (`int`): Dimension of the frequency tensor.
|
| 25 |
+
pos (`np.ndarray` or `int`): Position indices for the frequency tensor. [S] or scalar
|
| 26 |
+
theta (`float`, *optional*, defaults to 10000.0):
|
| 27 |
+
Scaling factor for frequency computation. Defaults to 10000.0.
|
| 28 |
+
use_real (`bool`, *optional*):
|
| 29 |
+
If True, return real part and imaginary part separately. Otherwise, return complex numbers.
|
| 30 |
+
linear_factor (`float`, *optional*, defaults to 1.0):
|
| 31 |
+
Scaling factor for the context extrapolation. Defaults to 1.0.
|
| 32 |
+
ntk_factor (`float`, *optional*, defaults to 1.0):
|
| 33 |
+
Scaling factor for the NTK-Aware RoPE. Defaults to 1.0.
|
| 34 |
+
repeat_interleave_real (`bool`, *optional*, defaults to `True`):
|
| 35 |
+
If `True` and `use_real`, real part and imaginary part are each interleaved with themselves to reach `dim`.
|
| 36 |
+
Otherwise, they are concateanted with themselves.
|
| 37 |
+
freqs_dtype (`torch.float32` or `torch.float64`, *optional*, defaults to `torch.float32`):
|
| 38 |
+
the dtype of the frequency tensor.
|
| 39 |
+
Returns:
|
| 40 |
+
`torch.Tensor`: Precomputed frequency tensor with complex exponentials. [S, D/2]
|
| 41 |
+
"""
|
| 42 |
+
assert dim % 2 == 0
|
| 43 |
+
|
| 44 |
+
if isinstance(pos, int):
|
| 45 |
+
pos = torch.arange(pos)
|
| 46 |
+
if isinstance(pos, np.ndarray):
|
| 47 |
+
pos = torch.from_numpy(pos) # type: ignore # [S]
|
| 48 |
+
|
| 49 |
+
theta = theta * ntk_factor
|
| 50 |
+
freqs = (
|
| 51 |
+
1.0
|
| 52 |
+
/ (theta ** (torch.arange(0, dim, 2, dtype=freqs_dtype, device=pos.device)[: (dim // 2)] / dim))
|
| 53 |
+
/ linear_factor
|
| 54 |
+
) # [D/2]
|
| 55 |
+
freqs = torch.outer(pos, freqs) # type: ignore # [S, D/2]
|
| 56 |
+
if use_real and repeat_interleave_real:
|
| 57 |
+
freqs_cos = freqs.cos().repeat_interleave(2, dim=1).float() # [S, D]
|
| 58 |
+
freqs_sin = freqs.sin().repeat_interleave(2, dim=1).float() # [S, D]
|
| 59 |
+
return freqs_cos, freqs_sin
|
| 60 |
+
elif use_real:
|
| 61 |
+
freqs_cos = torch.cat([freqs.cos(), freqs.cos()], dim=-1).float() # [S, D]
|
| 62 |
+
freqs_sin = torch.cat([freqs.sin(), freqs.sin()], dim=-1).float() # [S, D]
|
| 63 |
+
return freqs_cos, freqs_sin
|
| 64 |
+
else:
|
| 65 |
+
freqs_cis = torch.polar(torch.ones_like(freqs), freqs) # complex64 # [S, D/2]
|
| 66 |
+
return freqs_cis
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def get_3d_rotary_pos_embed(
|
| 70 |
+
embed_dim, crops_coords, grid_size, temporal_size, theta: int = 10000, use_real: bool = True
|
| 71 |
+
) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:
|
| 72 |
+
"""
|
| 73 |
+
RoPE for video tokens with 3D structure.
|
| 74 |
+
|
| 75 |
+
Args:
|
| 76 |
+
embed_dim: (`int`):
|
| 77 |
+
The embedding dimension size, corresponding to hidden_size_head.
|
| 78 |
+
crops_coords (`Tuple[int]`):
|
| 79 |
+
The top-left and bottom-right coordinates of the crop.
|
| 80 |
+
grid_size (`Tuple[int]`):
|
| 81 |
+
The grid size of the spatial positional embedding (height, width).
|
| 82 |
+
temporal_size (`int`):
|
| 83 |
+
The size of the temporal dimension.
|
| 84 |
+
theta (`float`):
|
| 85 |
+
Scaling factor for frequency computation.
|
| 86 |
+
|
| 87 |
+
Returns:
|
| 88 |
+
`torch.Tensor`: positional embedding with shape `(temporal_size * grid_size[0] * grid_size[1], embed_dim/2)`.
|
| 89 |
+
"""
|
| 90 |
+
if use_real is not True:
|
| 91 |
+
raise ValueError(" `use_real = False` is not currently supported for get_3d_rotary_pos_embed")
|
| 92 |
+
start, stop = crops_coords
|
| 93 |
+
grid_size_h, grid_size_w = grid_size
|
| 94 |
+
grid_h = np.linspace(start[0], stop[0], grid_size_h, endpoint=False, dtype=np.float32)
|
| 95 |
+
grid_w = np.linspace(start[1], stop[1], grid_size_w, endpoint=False, dtype=np.float32)
|
| 96 |
+
grid_t = np.linspace(0, temporal_size, temporal_size, endpoint=False, dtype=np.float32)
|
| 97 |
+
|
| 98 |
+
# Compute dimensions for each axis
|
| 99 |
+
dim_t = embed_dim // 4
|
| 100 |
+
dim_h = embed_dim // 8 * 3
|
| 101 |
+
dim_w = embed_dim // 8 * 3
|
| 102 |
+
|
| 103 |
+
# Temporal frequencies
|
| 104 |
+
freqs_t = get_1d_rotary_pos_embed(dim_t, grid_t, use_real=True)
|
| 105 |
+
# Spatial frequencies for height and width
|
| 106 |
+
freqs_h = get_1d_rotary_pos_embed(dim_h, grid_h, use_real=True)
|
| 107 |
+
freqs_w = get_1d_rotary_pos_embed(dim_w, grid_w, use_real=True)
|
| 108 |
+
|
| 109 |
+
# BroadCast and concatenate temporal and spaial frequencie (height and width) into a 3d tensor
|
| 110 |
+
def combine_time_height_width(freqs_t, freqs_h, freqs_w):
|
| 111 |
+
freqs_t = freqs_t[:, None, None, :].expand(
|
| 112 |
+
-1, grid_size_h, grid_size_w, -1
|
| 113 |
+
) # temporal_size, grid_size_h, grid_size_w, dim_t
|
| 114 |
+
freqs_h = freqs_h[None, :, None, :].expand(
|
| 115 |
+
temporal_size, -1, grid_size_w, -1
|
| 116 |
+
) # temporal_size, grid_size_h, grid_size_2, dim_h
|
| 117 |
+
freqs_w = freqs_w[None, None, :, :].expand(
|
| 118 |
+
temporal_size, grid_size_h, -1, -1
|
| 119 |
+
) # temporal_size, grid_size_h, grid_size_2, dim_w
|
| 120 |
+
|
| 121 |
+
freqs = torch.cat(
|
| 122 |
+
[freqs_t, freqs_h, freqs_w], dim=-1
|
| 123 |
+
) # temporal_size, grid_size_h, grid_size_w, (dim_t + dim_h + dim_w)
|
| 124 |
+
freqs = freqs.view(
|
| 125 |
+
temporal_size * grid_size_h * grid_size_w, -1
|
| 126 |
+
) # (temporal_size * grid_size_h * grid_size_w), (dim_t + dim_h + dim_w)
|
| 127 |
+
return freqs
|
| 128 |
+
|
| 129 |
+
t_cos, t_sin = freqs_t # both t_cos and t_sin has shape: temporal_size, dim_t
|
| 130 |
+
h_cos, h_sin = freqs_h # both h_cos and h_sin has shape: grid_size_h, dim_h
|
| 131 |
+
w_cos, w_sin = freqs_w # both w_cos and w_sin has shape: grid_size_w, dim_w
|
| 132 |
+
cos = combine_time_height_width(t_cos, h_cos, w_cos)
|
| 133 |
+
sin = combine_time_height_width(t_sin, h_sin, w_sin)
|
| 134 |
+
return cos, sin
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
def get_3d_motion_spatial_embed(
|
| 138 |
+
embed_dim: int, num_joints: int, joints_mean: np.ndarray, joints_std: np.ndarray, theta: float = 10000.0
|
| 139 |
+
) -> Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]:
|
| 140 |
+
assert embed_dim % 2 == 0 and embed_dim % 3 == 0
|
| 141 |
+
|
| 142 |
+
def create_rope_pe(dim, pos, freqs_dtype=torch.float32):
|
| 143 |
+
if isinstance(pos, np.ndarray):
|
| 144 |
+
pos = torch.from_numpy(pos)
|
| 145 |
+
freqs = (
|
| 146 |
+
1.0
|
| 147 |
+
/ (theta ** (torch.arange(0, dim, 2, dtype=freqs_dtype, device=pos.device)[: (dim // 2)] / dim))
|
| 148 |
+
) # [D/2]
|
| 149 |
+
freqs = torch.outer(pos, freqs) # type: ignore # [S, D/2]
|
| 150 |
+
freqs_cos = freqs.cos().repeat_interleave(2, dim=1).float() # [S, D]
|
| 151 |
+
freqs_sin = freqs.sin().repeat_interleave(2, dim=1).float() # [S, D]
|
| 152 |
+
return freqs_cos, freqs_sin
|
| 153 |
+
|
| 154 |
+
pos_x = joints_mean[:, 0]
|
| 155 |
+
pos_y = joints_mean[:, 1]
|
| 156 |
+
pos_z = joints_mean[:, 2]
|
| 157 |
+
|
| 158 |
+
normalized_pos_x = (pos_x - pos_x.mean())
|
| 159 |
+
normalized_pos_y = (pos_y - pos_y.mean())
|
| 160 |
+
normalized_pos_z = (pos_z - pos_z.mean())
|
| 161 |
+
|
| 162 |
+
freqs_cos_x, freqs_sin_x = create_rope_pe(embed_dim // 3, normalized_pos_x)
|
| 163 |
+
freqs_cos_y, freqs_sin_y = create_rope_pe(embed_dim // 3, normalized_pos_y)
|
| 164 |
+
freqs_cos_z, freqs_sin_z = create_rope_pe(embed_dim // 3, normalized_pos_z)
|
| 165 |
+
|
| 166 |
+
freqs_cos = torch.cat([freqs_cos_x, freqs_cos_y, freqs_cos_z], dim=-1)
|
| 167 |
+
freqs_sin = torch.cat([freqs_sin_x, freqs_sin_y, freqs_sin_z], dim=-1)
|
| 168 |
+
|
| 169 |
+
return freqs_cos, freqs_sin
|
| 170 |
+
|
| 171 |
+
def prepare_motion_embeddings(num_frames, num_joints, joints_mean, joints_std, theta=10000, device='cuda'):
|
| 172 |
+
time_embed = get_1d_rotary_pos_embed(44, num_frames, theta, use_real=True)
|
| 173 |
+
time_embed_cos = time_embed[0][:, None, :].expand(-1, num_joints, -1).reshape(num_frames*num_joints, -1)
|
| 174 |
+
time_embed_sin = time_embed[1][:, None, :].expand(-1, num_joints, -1).reshape(num_frames*num_joints, -1)
|
| 175 |
+
spatial_motion_embed = get_3d_motion_spatial_embed(84, num_joints, joints_mean, joints_std, theta)
|
| 176 |
+
spatial_embed_cos = spatial_motion_embed[0][None, :, :].expand(num_frames, -1, -1).reshape(num_frames*num_joints, -1)
|
| 177 |
+
spatial_embed_sin = spatial_motion_embed[1][None, :, :].expand(num_frames, -1, -1).reshape(num_frames*num_joints, -1)
|
| 178 |
+
motion_embed_cos = torch.cat([time_embed_cos, spatial_embed_cos], dim=-1).to(device=device)
|
| 179 |
+
motion_embed_sin = torch.cat([time_embed_sin, spatial_embed_sin], dim=-1).to(device=device)
|
| 180 |
+
return motion_embed_cos, motion_embed_sin
|
| 181 |
+
|
| 182 |
+
def apply_rotary_emb(x, freqs_cis):
|
| 183 |
+
cos, sin = freqs_cis # [S, D]
|
| 184 |
+
cos = cos[None, None]
|
| 185 |
+
sin = sin[None, None]
|
| 186 |
+
cos, sin = cos.to(x.device), sin.to(x.device)
|
| 187 |
+
|
| 188 |
+
x_real, x_imag = x.reshape(*x.shape[:-1], -1, 2).unbind(-1) # [B, S, H, D//2]
|
| 189 |
+
x_rotated = torch.stack([-x_imag, x_real], dim=-1).flatten(3)
|
| 190 |
+
|
| 191 |
+
out = (x.float() * cos + x_rotated.float() * sin).to(x.dtype)
|
| 192 |
+
|
| 193 |
+
return out
|
custom_nodes/ComfyUI-WanVideoWrapper/MTV/nodes.py
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import torch
|
| 3 |
+
from ..utils import log
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
import comfy.model_management as mm
|
| 7 |
+
from comfy.utils import load_torch_file
|
| 8 |
+
import folder_paths
|
| 9 |
+
|
| 10 |
+
script_directory = os.path.dirname(os.path.abspath(__file__))
|
| 11 |
+
device = mm.get_torch_device()
|
| 12 |
+
offload_device = mm.unet_offload_device()
|
| 13 |
+
|
| 14 |
+
local_model_path = os.path.join(folder_paths.models_dir, "nlf", "nlf_l_multi_0.3.2.torchscript")
|
| 15 |
+
folder_paths.add_model_folder_path("nlf", os.path.join(folder_paths.models_dir, "nlf"))
|
| 16 |
+
|
| 17 |
+
from .motion4d import SMPL_VQVAE, VectorQuantizer, Encoder, Decoder
|
| 18 |
+
|
| 19 |
+
def check_jit_script_function():
|
| 20 |
+
if torch.jit.script.__name__ != "script":
|
| 21 |
+
# Get more details about what modified it
|
| 22 |
+
module = torch.jit.script.__module__
|
| 23 |
+
qualname = getattr(torch.jit.script, '__qualname__', 'unknown')
|
| 24 |
+
code_file = None
|
| 25 |
+
try:
|
| 26 |
+
code_file = torch.jit.script.__code__.co_filename
|
| 27 |
+
code_line = torch.jit.script.__code__.co_firstlineno
|
| 28 |
+
log.warning(f"torch.jit.script has been modified by another custom node.\n"
|
| 29 |
+
f" Function name: {torch.jit.script.__name__}\n"
|
| 30 |
+
f" Module: {module}\n"
|
| 31 |
+
f" Qualified name: {qualname}\n"
|
| 32 |
+
f" Defined in: {code_file}:{code_line}\n"
|
| 33 |
+
f"This may cause issues with the NLF model.")
|
| 34 |
+
except Exception:
|
| 35 |
+
log.warning("--------------------------------")
|
| 36 |
+
log.warning(f"torch.jit.script function is: {torch.jit.script.__name__} from module {module}, "
|
| 37 |
+
f"this has been modified by another custom node. This may cause issues with the NLF model.")
|
| 38 |
+
log.warning("--------------------------------")
|
| 39 |
+
|
| 40 |
+
model_list = [
|
| 41 |
+
"https://github.com/isarandi/nlf/releases/download/v0.3.2/nlf_l_multi_0.3.2.torchscript",
|
| 42 |
+
"https://github.com/isarandi/nlf/releases/download/v0.2.2/nlf_l_multi_0.2.2.torchscript",
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
class DownloadAndLoadNLFModel:
|
| 46 |
+
@classmethod
|
| 47 |
+
def INPUT_TYPES(s):
|
| 48 |
+
return {
|
| 49 |
+
"required": {
|
| 50 |
+
"url": (model_list, {"default": "https://github.com/isarandi/nlf/releases/download/v0.3.2/nlf_l_multi_0.3.2.torchscript"}),
|
| 51 |
+
},
|
| 52 |
+
"optional": {
|
| 53 |
+
"warmup": ("BOOLEAN", {"default": True, "tooltip": "Whether to warmup the model after loading"}),
|
| 54 |
+
},
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
RETURN_TYPES = ("NLFMODEL",)
|
| 58 |
+
RETURN_NAMES = ("nlf_model", )
|
| 59 |
+
FUNCTION = "loadmodel"
|
| 60 |
+
CATEGORY = "WanVideoWrapper"
|
| 61 |
+
|
| 62 |
+
def loadmodel(self, url, warmup=True):
|
| 63 |
+
if url not in model_list:
|
| 64 |
+
raise ValueError(f"URL {url} is not in the list of allowed models.")
|
| 65 |
+
check_jit_script_function()
|
| 66 |
+
|
| 67 |
+
if not os.path.exists(local_model_path):
|
| 68 |
+
log.info(f"Downloading NLF model to: {local_model_path}")
|
| 69 |
+
import requests
|
| 70 |
+
os.makedirs(os.path.dirname(local_model_path), exist_ok=True)
|
| 71 |
+
response = requests.get(url)
|
| 72 |
+
if response.status_code == 200:
|
| 73 |
+
with open(local_model_path, "wb") as f:
|
| 74 |
+
f.write(response.content)
|
| 75 |
+
else:
|
| 76 |
+
print("Failed to download file:", response.status_code)
|
| 77 |
+
|
| 78 |
+
model = torch.jit.load(local_model_path).eval()
|
| 79 |
+
|
| 80 |
+
if warmup:
|
| 81 |
+
log.info("Warming up NLF model...")
|
| 82 |
+
dummy_input = torch.zeros(1, 3, 256, 256, device=device)
|
| 83 |
+
jit_profiling_prev_state = torch._C._jit_set_profiling_executor(True)
|
| 84 |
+
try:
|
| 85 |
+
for _ in range(2):
|
| 86 |
+
_ = model.detect_smpl_batched(dummy_input)
|
| 87 |
+
finally:
|
| 88 |
+
torch._C._jit_set_profiling_executor(jit_profiling_prev_state)
|
| 89 |
+
|
| 90 |
+
log.info("NLF model warmed up")
|
| 91 |
+
|
| 92 |
+
model = model.to(offload_device)
|
| 93 |
+
|
| 94 |
+
return (model,)
|
| 95 |
+
|
| 96 |
+
class LoadNLFModel:
|
| 97 |
+
@classmethod
|
| 98 |
+
def INPUT_TYPES(s):
|
| 99 |
+
return {
|
| 100 |
+
"required": {
|
| 101 |
+
"nlf_model": (folder_paths.get_filename_list("nlf"), {"tooltip": "These models are loaded from the 'ComfyUI/models/nlf' -folder",}),
|
| 102 |
+
|
| 103 |
+
},
|
| 104 |
+
"optional": {
|
| 105 |
+
"warmup": ("BOOLEAN", {"default": True, "tooltip": "Whether to warmup the model after loading"}),
|
| 106 |
+
},
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
RETURN_TYPES = ("NLFMODEL",)
|
| 110 |
+
RETURN_NAMES = ("nlf_model", )
|
| 111 |
+
FUNCTION = "loadmodel"
|
| 112 |
+
CATEGORY = "WanVideoWrapper"
|
| 113 |
+
|
| 114 |
+
def loadmodel(self, nlf_model, warmup=True):
|
| 115 |
+
check_jit_script_function()
|
| 116 |
+
model = torch.jit.load(folder_paths.get_full_path_or_raise("nlf", nlf_model)).eval()
|
| 117 |
+
|
| 118 |
+
if warmup:
|
| 119 |
+
log.info("Warming up NLF model...")
|
| 120 |
+
dummy_input = torch.zeros(1, 3, 256, 256, device=device)
|
| 121 |
+
jit_profiling_prev_state = torch._C._jit_set_profiling_executor(True)
|
| 122 |
+
try:
|
| 123 |
+
for _ in range(2):
|
| 124 |
+
_ = model.detect_smpl_batched(dummy_input)
|
| 125 |
+
finally:
|
| 126 |
+
torch._C._jit_set_profiling_executor(jit_profiling_prev_state)
|
| 127 |
+
log.info("NLF model warmed up")
|
| 128 |
+
|
| 129 |
+
model = model.to(offload_device)
|
| 130 |
+
|
| 131 |
+
return model,
|
| 132 |
+
|
| 133 |
+
class LoadVQVAE:
|
| 134 |
+
@classmethod
|
| 135 |
+
def INPUT_TYPES(s):
|
| 136 |
+
return {
|
| 137 |
+
"required": {
|
| 138 |
+
"model_name": (folder_paths.get_filename_list("vae"), {"tooltip": "These models are loaded from 'ComfyUI/models/vae'"}),
|
| 139 |
+
},
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
RETURN_TYPES = ("VQVAE",)
|
| 143 |
+
RETURN_NAMES = ("vqvae", )
|
| 144 |
+
FUNCTION = "loadmodel"
|
| 145 |
+
CATEGORY = "WanVideoWrapper"
|
| 146 |
+
|
| 147 |
+
def loadmodel(self, model_name):
|
| 148 |
+
model_path = folder_paths.get_full_path("vae", model_name)
|
| 149 |
+
vae_sd = load_torch_file(model_path, safe_load=True)
|
| 150 |
+
|
| 151 |
+
# Get motion tokenizer
|
| 152 |
+
motion_encoder = Encoder(
|
| 153 |
+
in_channels=3,
|
| 154 |
+
mid_channels=[128, 512],
|
| 155 |
+
out_channels=3072,
|
| 156 |
+
downsample_time=[2, 2],
|
| 157 |
+
downsample_joint=[1, 1]
|
| 158 |
+
)
|
| 159 |
+
motion_quant = VectorQuantizer(nb_code=8192, code_dim=3072)
|
| 160 |
+
motion_decoder = Decoder(
|
| 161 |
+
in_channels=3072,
|
| 162 |
+
mid_channels=[512, 128],
|
| 163 |
+
out_channels=3,
|
| 164 |
+
upsample_rate=2.0,
|
| 165 |
+
frame_upsample_rate=[2.0, 2.0],
|
| 166 |
+
joint_upsample_rate=[1.0, 1.0]
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
+
vqvae = SMPL_VQVAE(motion_encoder, motion_decoder, motion_quant).to(device)
|
| 170 |
+
vqvae.load_state_dict(vae_sd, strict=True)
|
| 171 |
+
|
| 172 |
+
return vqvae,
|
| 173 |
+
|
| 174 |
+
class MTVCrafterEncodePoses:
|
| 175 |
+
@classmethod
|
| 176 |
+
def INPUT_TYPES(s):
|
| 177 |
+
return {
|
| 178 |
+
"required": {
|
| 179 |
+
"vqvae": ("VQVAE", {"tooltip": "VQVAE model"}),
|
| 180 |
+
"poses": ("NLFPRED", {"tooltip": "Input poses for the model"}),
|
| 181 |
+
},
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
RETURN_TYPES = ("MTVCRAFTERMOTION", "NLFPRED")
|
| 185 |
+
RETURN_NAMES = ("mtvcrafter_motion", "pose_results")
|
| 186 |
+
FUNCTION = "encode"
|
| 187 |
+
CATEGORY = "WanVideoWrapper"
|
| 188 |
+
|
| 189 |
+
def encode(self, vqvae, poses):
|
| 190 |
+
|
| 191 |
+
global_mean = np.load(os.path.join(script_directory, "data", "mean.npy")) #global_mean.shape: (24, 3)
|
| 192 |
+
global_std = np.load(os.path.join(script_directory, "data", "std.npy"))
|
| 193 |
+
|
| 194 |
+
smpl_poses = []
|
| 195 |
+
for pose in poses['joints3d_nonparam'][0]:
|
| 196 |
+
smpl_poses.append(pose[0].cpu().numpy())
|
| 197 |
+
smpl_poses = np.array(smpl_poses)
|
| 198 |
+
|
| 199 |
+
norm_poses = torch.tensor((smpl_poses - global_mean) / global_std).unsqueeze(0)
|
| 200 |
+
print(f"norm_poses shape: {norm_poses.shape}, dtype: {norm_poses.dtype}")
|
| 201 |
+
|
| 202 |
+
vqvae.to(device)
|
| 203 |
+
motion_tokens, vq_loss = vqvae(norm_poses.to(device), return_vq=True)
|
| 204 |
+
|
| 205 |
+
recon_motion = vqvae(norm_poses.to(device))[0][0].to(dtype=torch.float32).cpu().detach() * global_std + global_mean
|
| 206 |
+
vqvae.to(offload_device)
|
| 207 |
+
|
| 208 |
+
poses_dict = {
|
| 209 |
+
'mtv_motion_tokens': motion_tokens,
|
| 210 |
+
'global_mean': global_mean,
|
| 211 |
+
'global_std': global_std
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
return poses_dict, recon_motion
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
class NLFPredict:
|
| 218 |
+
@classmethod
|
| 219 |
+
def INPUT_TYPES(s):
|
| 220 |
+
return {"required": {
|
| 221 |
+
"model": ("NLFMODEL",),
|
| 222 |
+
"images": ("IMAGE", {"tooltip": "Input images for the model"}),
|
| 223 |
+
},
|
| 224 |
+
"optional": {
|
| 225 |
+
"per_batch": ("INT", {"default": -1, "min": -1, "max": 10000, "step": 1, "tooltip": "How many images to process at once. -1 means all at once."}),
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
RETURN_TYPES = ("NLFPRED", "BBOX",)
|
| 230 |
+
RETURN_NAMES = ("pose_results", "bboxes")
|
| 231 |
+
FUNCTION = "predict"
|
| 232 |
+
CATEGORY = "WanVideoWrapper"
|
| 233 |
+
|
| 234 |
+
def predict(self, model, images, per_batch=-1):
|
| 235 |
+
|
| 236 |
+
check_jit_script_function()
|
| 237 |
+
model = model.to(device)
|
| 238 |
+
|
| 239 |
+
num_images = images.shape[0]
|
| 240 |
+
|
| 241 |
+
# Determine batch size
|
| 242 |
+
if per_batch == -1:
|
| 243 |
+
batch_size = num_images
|
| 244 |
+
else:
|
| 245 |
+
batch_size = per_batch
|
| 246 |
+
|
| 247 |
+
# Initialize result containers
|
| 248 |
+
all_boxes = []
|
| 249 |
+
all_joints3d_nonparam = []
|
| 250 |
+
|
| 251 |
+
# Process in batches
|
| 252 |
+
for i in range(0, num_images, batch_size):
|
| 253 |
+
end_idx = min(i + batch_size, num_images)
|
| 254 |
+
batch_images = images[i:end_idx]
|
| 255 |
+
|
| 256 |
+
jit_profiling_prev_state = torch._C._jit_set_profiling_executor(True)
|
| 257 |
+
try:
|
| 258 |
+
pred = model.detect_smpl_batched(batch_images.permute(0, 3, 1, 2).to(device))
|
| 259 |
+
finally:
|
| 260 |
+
torch._C._jit_set_profiling_executor(jit_profiling_prev_state)
|
| 261 |
+
|
| 262 |
+
# Collect boxes and joints from this batch
|
| 263 |
+
if 'boxes' in pred:
|
| 264 |
+
all_boxes.extend(pred['boxes'])
|
| 265 |
+
if 'joints3d_nonparam' in pred:
|
| 266 |
+
all_joints3d_nonparam.extend(pred['joints3d_nonparam'])
|
| 267 |
+
|
| 268 |
+
model = model.to(offload_device)
|
| 269 |
+
|
| 270 |
+
# Move collected results to offload device
|
| 271 |
+
all_boxes = [box.to(offload_device) for box in all_boxes]
|
| 272 |
+
all_joints3d_nonparam = [joints.to(offload_device) for joints in all_joints3d_nonparam]
|
| 273 |
+
|
| 274 |
+
# Maintain the original nested format: wrap in a list to match expected structure
|
| 275 |
+
pose_results = {
|
| 276 |
+
'joints3d_nonparam': [all_joints3d_nonparam],
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
# Convert bboxes to list format: [x_min, y_min, x_max, y_max] for each detection
|
| 280 |
+
# Each box tensor is shape (1, 5) with [x_min, y_min, x_max, y_max, confidence]
|
| 281 |
+
formatted_boxes = []
|
| 282 |
+
for box in all_boxes:
|
| 283 |
+
# Handle empty detections (no person detected in frame)
|
| 284 |
+
if box.numel() == 0 or box.shape[0] == 0:
|
| 285 |
+
formatted_boxes.append([0.0, 0.0, 0.0, 0.0])
|
| 286 |
+
else:
|
| 287 |
+
# Extract first 4 values (x_min, y_min, x_max, y_max), drop confidence
|
| 288 |
+
bbox_values = box[0, :4].cpu().tolist()
|
| 289 |
+
formatted_boxes.append(bbox_values)
|
| 290 |
+
|
| 291 |
+
return (pose_results, formatted_boxes)
|
| 292 |
+
|
| 293 |
+
class DrawNLFPoses:
|
| 294 |
+
@classmethod
|
| 295 |
+
def INPUT_TYPES(s):
|
| 296 |
+
return {"required": {
|
| 297 |
+
"poses": ("NLFPRED", {"tooltip": "Input poses for the model"}),
|
| 298 |
+
"width": ("INT", {"default": 512}),
|
| 299 |
+
"height": ("INT", {"default": 512}),
|
| 300 |
+
},
|
| 301 |
+
"optional": {
|
| 302 |
+
"stick_width": ("FLOAT", {"default": 4.0, "min": 0.0, "max": 1000.0, "step": 0.01, "tooltip": "Stick width multiplier"}),
|
| 303 |
+
"point_radius": ("INT", {"default": 5, "min": 1, "max": 10, "step": 1, "tooltip": "Point radius for drawing the pose"}),
|
| 304 |
+
"style": (["original", "scail"], {"default": "original", "tooltip": "style of the pose drawing"}),
|
| 305 |
+
}
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
RETURN_TYPES = ("IMAGE", )
|
| 309 |
+
RETURN_NAMES = ("image",)
|
| 310 |
+
FUNCTION = "predict"
|
| 311 |
+
CATEGORY = "WanVideoWrapper"
|
| 312 |
+
|
| 313 |
+
def predict(self, poses, width, height, stick_width=1.0, point_radius=2, style="original"):
|
| 314 |
+
from .draw_pose import get_control_conditions
|
| 315 |
+
|
| 316 |
+
if isinstance(poses, dict):
|
| 317 |
+
pose_input = poses['joints3d_nonparam'][0] if 'joints3d_nonparam' in poses else poses
|
| 318 |
+
else:
|
| 319 |
+
pose_input = poses
|
| 320 |
+
|
| 321 |
+
control_conditions = get_control_conditions(pose_input, height, width, stick_width=stick_width, point_radius=point_radius, style=style)
|
| 322 |
+
|
| 323 |
+
return (control_conditions,)
|
| 324 |
+
|
| 325 |
+
NODE_CLASS_MAPPINGS = {
|
| 326 |
+
"LoadNLFModel": LoadNLFModel,
|
| 327 |
+
"DownloadAndLoadNLFModel": DownloadAndLoadNLFModel,
|
| 328 |
+
"NLFPredict": NLFPredict,
|
| 329 |
+
"DrawNLFPoses": DrawNLFPoses,
|
| 330 |
+
"LoadVQVAE": LoadVQVAE,
|
| 331 |
+
"MTVCrafterEncodePoses": MTVCrafterEncodePoses
|
| 332 |
+
}
|
| 333 |
+
NODE_DISPLAY_NAME_MAPPINGS = {
|
| 334 |
+
"LoadNLFModel": "Load NLF Model",
|
| 335 |
+
"DownloadAndLoadNLFModel": "(Download)Load NLF Model",
|
| 336 |
+
"NLFPredict": "NLF Predict",
|
| 337 |
+
"DrawNLFPoses": "Draw NLF Poses",
|
| 338 |
+
"LoadVQVAE": "Load VQVAE",
|
| 339 |
+
"MTVCrafterEncodePoses": "MTV Crafter Encode Poses"
|
| 340 |
+
}
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/__pycache__/mel_converter.cpython-313.pyc
ADDED
|
Binary file (8.44 kB). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/__pycache__/nodes_ovi.cpython-313.pyc
ADDED
|
Binary file (13.1 kB). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/audio_model_layers.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
import torch.nn.functional as F
|
| 4 |
+
|
| 5 |
+
class ChannelLastConv1d(nn.Conv1d):
|
| 6 |
+
|
| 7 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 8 |
+
x = x.permute(0, 2, 1)
|
| 9 |
+
x = super().forward(x)
|
| 10 |
+
x = x.permute(0, 2, 1)
|
| 11 |
+
return x
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class ConvMLP(nn.Module):
|
| 15 |
+
|
| 16 |
+
def __init__(
|
| 17 |
+
self,
|
| 18 |
+
dim: int,
|
| 19 |
+
hidden_dim: int,
|
| 20 |
+
multiple_of: int = 256,
|
| 21 |
+
kernel_size: int = 3,
|
| 22 |
+
padding: int = 1,
|
| 23 |
+
):
|
| 24 |
+
"""
|
| 25 |
+
Initialize the FeedForward module.
|
| 26 |
+
|
| 27 |
+
Args:
|
| 28 |
+
dim (int): Input dimension.
|
| 29 |
+
hidden_dim (int): Hidden dimension of the feedforward layer.
|
| 30 |
+
multiple_of (int): Value to ensure hidden dimension is a multiple of this value.
|
| 31 |
+
|
| 32 |
+
Attributes:
|
| 33 |
+
w1 (ColumnParallelLinear): Linear transformation for the first layer.
|
| 34 |
+
w2 (RowParallelLinear): Linear transformation for the second layer.
|
| 35 |
+
w3 (ColumnParallelLinear): Linear transformation for the third layer.
|
| 36 |
+
|
| 37 |
+
"""
|
| 38 |
+
super().__init__()
|
| 39 |
+
hidden_dim = int(2 * hidden_dim / 3)
|
| 40 |
+
hidden_dim = multiple_of * ((hidden_dim + multiple_of - 1) // multiple_of)
|
| 41 |
+
|
| 42 |
+
self.w1 = ChannelLastConv1d(dim, hidden_dim, bias=False, kernel_size=kernel_size, padding=padding)
|
| 43 |
+
self.w2 = ChannelLastConv1d(hidden_dim, dim, bias=False, kernel_size=kernel_size, padding=padding)
|
| 44 |
+
self.w3 = ChannelLastConv1d(dim, hidden_dim, bias=False, kernel_size=kernel_size, padding=padding)
|
| 45 |
+
|
| 46 |
+
def forward(self, x):
|
| 47 |
+
return self.w2(F.silu(self.w1(x)) * self.w3(x))
|
| 48 |
+
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2022 NVIDIA CORPORATION.
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from .bigvgan import BigVGAN
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (240 Bytes). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/__pycache__/activations.cpython-313.pyc
ADDED
|
Binary file (5.54 kB). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/__pycache__/bigvgan.cpython-313.pyc
ADDED
|
Binary file (2.92 kB). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/__pycache__/models.cpython-313.pyc
ADDED
|
Binary file (11.2 kB). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/__pycache__/utils.cpython-313.pyc
ADDED
|
Binary file (1.19 kB). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/activations.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Implementation adapted from https://github.com/EdwardDixon/snake under the MIT license.
|
| 2 |
+
# LICENSE is in incl_licenses directory.
|
| 3 |
+
|
| 4 |
+
import torch
|
| 5 |
+
from torch import nn, sin, pow
|
| 6 |
+
from torch.nn import Parameter
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class Snake(nn.Module):
|
| 10 |
+
'''
|
| 11 |
+
Implementation of a sine-based periodic activation function
|
| 12 |
+
Shape:
|
| 13 |
+
- Input: (B, C, T)
|
| 14 |
+
- Output: (B, C, T), same shape as the input
|
| 15 |
+
Parameters:
|
| 16 |
+
- alpha - trainable parameter
|
| 17 |
+
References:
|
| 18 |
+
- This activation function is from this paper by Liu Ziyin, Tilman Hartwig, Masahito Ueda:
|
| 19 |
+
https://arxiv.org/abs/2006.08195
|
| 20 |
+
Examples:
|
| 21 |
+
>>> a1 = snake(256)
|
| 22 |
+
>>> x = torch.randn(256)
|
| 23 |
+
>>> x = a1(x)
|
| 24 |
+
'''
|
| 25 |
+
def __init__(self, in_features, alpha=1.0, alpha_trainable=True, alpha_logscale=False):
|
| 26 |
+
'''
|
| 27 |
+
Initialization.
|
| 28 |
+
INPUT:
|
| 29 |
+
- in_features: shape of the input
|
| 30 |
+
- alpha: trainable parameter
|
| 31 |
+
alpha is initialized to 1 by default, higher values = higher-frequency.
|
| 32 |
+
alpha will be trained along with the rest of your model.
|
| 33 |
+
'''
|
| 34 |
+
super(Snake, self).__init__()
|
| 35 |
+
self.in_features = in_features
|
| 36 |
+
|
| 37 |
+
# initialize alpha
|
| 38 |
+
self.alpha_logscale = alpha_logscale
|
| 39 |
+
if self.alpha_logscale: # log scale alphas initialized to zeros
|
| 40 |
+
self.alpha = Parameter(torch.zeros(in_features) * alpha)
|
| 41 |
+
else: # linear scale alphas initialized to ones
|
| 42 |
+
self.alpha = Parameter(torch.ones(in_features) * alpha)
|
| 43 |
+
|
| 44 |
+
self.alpha.requires_grad = alpha_trainable
|
| 45 |
+
|
| 46 |
+
self.no_div_by_zero = 0.000000001
|
| 47 |
+
|
| 48 |
+
def forward(self, x):
|
| 49 |
+
'''
|
| 50 |
+
Forward pass of the function.
|
| 51 |
+
Applies the function to the input elementwise.
|
| 52 |
+
Snake ∶= x + 1/a * sin^2 (xa)
|
| 53 |
+
'''
|
| 54 |
+
alpha = self.alpha.unsqueeze(0).unsqueeze(-1) # line up with x to [B, C, T]
|
| 55 |
+
if self.alpha_logscale:
|
| 56 |
+
alpha = torch.exp(alpha)
|
| 57 |
+
x = x + (1.0 / (alpha + self.no_div_by_zero)) * pow(sin(x * alpha), 2)
|
| 58 |
+
|
| 59 |
+
return x
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class SnakeBeta(nn.Module):
|
| 63 |
+
'''
|
| 64 |
+
A modified Snake function which uses separate parameters for the magnitude of the periodic components
|
| 65 |
+
Shape:
|
| 66 |
+
- Input: (B, C, T)
|
| 67 |
+
- Output: (B, C, T), same shape as the input
|
| 68 |
+
Parameters:
|
| 69 |
+
- alpha - trainable parameter that controls frequency
|
| 70 |
+
- beta - trainable parameter that controls magnitude
|
| 71 |
+
References:
|
| 72 |
+
- This activation function is a modified version based on this paper by Liu Ziyin, Tilman Hartwig, Masahito Ueda:
|
| 73 |
+
https://arxiv.org/abs/2006.08195
|
| 74 |
+
Examples:
|
| 75 |
+
>>> a1 = snakebeta(256)
|
| 76 |
+
>>> x = torch.randn(256)
|
| 77 |
+
>>> x = a1(x)
|
| 78 |
+
'''
|
| 79 |
+
def __init__(self, in_features, alpha=1.0, alpha_trainable=True, alpha_logscale=False):
|
| 80 |
+
'''
|
| 81 |
+
Initialization.
|
| 82 |
+
INPUT:
|
| 83 |
+
- in_features: shape of the input
|
| 84 |
+
- alpha - trainable parameter that controls frequency
|
| 85 |
+
- beta - trainable parameter that controls magnitude
|
| 86 |
+
alpha is initialized to 1 by default, higher values = higher-frequency.
|
| 87 |
+
beta is initialized to 1 by default, higher values = higher-magnitude.
|
| 88 |
+
alpha will be trained along with the rest of your model.
|
| 89 |
+
'''
|
| 90 |
+
super(SnakeBeta, self).__init__()
|
| 91 |
+
self.in_features = in_features
|
| 92 |
+
|
| 93 |
+
# initialize alpha
|
| 94 |
+
self.alpha_logscale = alpha_logscale
|
| 95 |
+
if self.alpha_logscale: # log scale alphas initialized to zeros
|
| 96 |
+
self.alpha = Parameter(torch.zeros(in_features) * alpha)
|
| 97 |
+
self.beta = Parameter(torch.zeros(in_features) * alpha)
|
| 98 |
+
else: # linear scale alphas initialized to ones
|
| 99 |
+
self.alpha = Parameter(torch.ones(in_features) * alpha)
|
| 100 |
+
self.beta = Parameter(torch.ones(in_features) * alpha)
|
| 101 |
+
|
| 102 |
+
self.alpha.requires_grad = alpha_trainable
|
| 103 |
+
self.beta.requires_grad = alpha_trainable
|
| 104 |
+
|
| 105 |
+
self.no_div_by_zero = 0.000000001
|
| 106 |
+
|
| 107 |
+
def forward(self, x):
|
| 108 |
+
'''
|
| 109 |
+
Forward pass of the function.
|
| 110 |
+
Applies the function to the input elementwise.
|
| 111 |
+
SnakeBeta ∶= x + 1/b * sin^2 (xa)
|
| 112 |
+
'''
|
| 113 |
+
alpha = self.alpha.unsqueeze(0).unsqueeze(-1) # line up with x to [B, C, T]
|
| 114 |
+
beta = self.beta.unsqueeze(0).unsqueeze(-1)
|
| 115 |
+
if self.alpha_logscale:
|
| 116 |
+
alpha = torch.exp(alpha)
|
| 117 |
+
beta = torch.exp(beta)
|
| 118 |
+
x = x + (1.0 / (beta + self.no_div_by_zero)) * pow(sin(x * alpha), 2)
|
| 119 |
+
|
| 120 |
+
return x
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/alias_free_torch/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Adapted from https://github.com/junjun3518/alias-free-torch under the Apache License 2.0
|
| 2 |
+
# LICENSE is in incl_licenses directory.
|
| 3 |
+
|
| 4 |
+
from .filter import *
|
| 5 |
+
from .resample import *
|
| 6 |
+
from .act import *
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/alias_free_torch/__pycache__/__init__.cpython-313.pyc
ADDED
|
Binary file (286 Bytes). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/alias_free_torch/__pycache__/act.cpython-313.pyc
ADDED
|
Binary file (1.52 kB). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/alias_free_torch/__pycache__/filter.cpython-313.pyc
ADDED
|
Binary file (4.38 kB). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/alias_free_torch/__pycache__/resample.cpython-313.pyc
ADDED
|
Binary file (3.31 kB). View file
|
|
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/alias_free_torch/act.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Adapted from https://github.com/junjun3518/alias-free-torch under the Apache License 2.0
|
| 2 |
+
# LICENSE is in incl_licenses directory.
|
| 3 |
+
|
| 4 |
+
import torch.nn as nn
|
| 5 |
+
from .resample import UpSample1d, DownSample1d
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class Activation1d(nn.Module):
|
| 9 |
+
def __init__(self,
|
| 10 |
+
activation,
|
| 11 |
+
up_ratio: int = 2,
|
| 12 |
+
down_ratio: int = 2,
|
| 13 |
+
up_kernel_size: int = 12,
|
| 14 |
+
down_kernel_size: int = 12):
|
| 15 |
+
super().__init__()
|
| 16 |
+
self.up_ratio = up_ratio
|
| 17 |
+
self.down_ratio = down_ratio
|
| 18 |
+
self.act = activation
|
| 19 |
+
self.upsample = UpSample1d(up_ratio, up_kernel_size)
|
| 20 |
+
self.downsample = DownSample1d(down_ratio, down_kernel_size)
|
| 21 |
+
|
| 22 |
+
# x: [B,C,T]
|
| 23 |
+
def forward(self, x):
|
| 24 |
+
x = self.upsample(x)
|
| 25 |
+
x = self.act(x)
|
| 26 |
+
x = self.downsample(x)
|
| 27 |
+
|
| 28 |
+
return x
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/alias_free_torch/filter.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Adapted from https://github.com/junjun3518/alias-free-torch under the Apache License 2.0
|
| 2 |
+
# LICENSE is in incl_licenses directory.
|
| 3 |
+
|
| 4 |
+
import torch
|
| 5 |
+
import torch.nn as nn
|
| 6 |
+
import torch.nn.functional as F
|
| 7 |
+
import math
|
| 8 |
+
|
| 9 |
+
if 'sinc' in dir(torch):
|
| 10 |
+
sinc = torch.sinc
|
| 11 |
+
else:
|
| 12 |
+
# This code is adopted from adefossez's julius.core.sinc under the MIT License
|
| 13 |
+
# https://adefossez.github.io/julius/julius/core.html
|
| 14 |
+
# LICENSE is in incl_licenses directory.
|
| 15 |
+
def sinc(x: torch.Tensor):
|
| 16 |
+
"""
|
| 17 |
+
Implementation of sinc, i.e. sin(pi * x) / (pi * x)
|
| 18 |
+
__Warning__: Different to julius.sinc, the input is multiplied by `pi`!
|
| 19 |
+
"""
|
| 20 |
+
return torch.where(x == 0,
|
| 21 |
+
torch.tensor(1., device=x.device, dtype=x.dtype),
|
| 22 |
+
torch.sin(math.pi * x) / math.pi / x)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# This code is adopted from adefossez's julius.lowpass.LowPassFilters under the MIT License
|
| 26 |
+
# https://adefossez.github.io/julius/julius/lowpass.html
|
| 27 |
+
# LICENSE is in incl_licenses directory.
|
| 28 |
+
def kaiser_sinc_filter1d(cutoff, half_width, kernel_size): # return filter [1,1,kernel_size]
|
| 29 |
+
even = (kernel_size % 2 == 0)
|
| 30 |
+
half_size = kernel_size // 2
|
| 31 |
+
|
| 32 |
+
#For kaiser window
|
| 33 |
+
delta_f = 4 * half_width
|
| 34 |
+
A = 2.285 * (half_size - 1) * math.pi * delta_f + 7.95
|
| 35 |
+
if A > 50.:
|
| 36 |
+
beta = 0.1102 * (A - 8.7)
|
| 37 |
+
elif A >= 21.:
|
| 38 |
+
beta = 0.5842 * (A - 21)**0.4 + 0.07886 * (A - 21.)
|
| 39 |
+
else:
|
| 40 |
+
beta = 0.
|
| 41 |
+
window = torch.kaiser_window(kernel_size, beta=beta, periodic=False)
|
| 42 |
+
|
| 43 |
+
# ratio = 0.5/cutoff -> 2 * cutoff = 1 / ratio
|
| 44 |
+
if even:
|
| 45 |
+
time = (torch.arange(-half_size, half_size) + 0.5)
|
| 46 |
+
else:
|
| 47 |
+
time = torch.arange(kernel_size) - half_size
|
| 48 |
+
if cutoff == 0:
|
| 49 |
+
filter_ = torch.zeros_like(time)
|
| 50 |
+
else:
|
| 51 |
+
filter_ = 2 * cutoff * window * sinc(2 * cutoff * time)
|
| 52 |
+
# Normalize filter to have sum = 1, otherwise we will have a small leakage
|
| 53 |
+
# of the constant component in the input signal.
|
| 54 |
+
filter_ /= filter_.sum()
|
| 55 |
+
filter = filter_.view(1, 1, kernel_size)
|
| 56 |
+
|
| 57 |
+
return filter
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class LowPassFilter1d(nn.Module):
|
| 61 |
+
def __init__(self,
|
| 62 |
+
cutoff=0.5,
|
| 63 |
+
half_width=0.6,
|
| 64 |
+
stride: int = 1,
|
| 65 |
+
padding: bool = True,
|
| 66 |
+
padding_mode: str = 'replicate',
|
| 67 |
+
kernel_size: int = 12):
|
| 68 |
+
# kernel_size should be even number for stylegan3 setup,
|
| 69 |
+
# in this implementation, odd number is also possible.
|
| 70 |
+
super().__init__()
|
| 71 |
+
if cutoff < -0.:
|
| 72 |
+
raise ValueError("Minimum cutoff must be larger than zero.")
|
| 73 |
+
if cutoff > 0.5:
|
| 74 |
+
raise ValueError("A cutoff above 0.5 does not make sense.")
|
| 75 |
+
self.kernel_size = kernel_size
|
| 76 |
+
self.even = (kernel_size % 2 == 0)
|
| 77 |
+
self.pad_left = kernel_size // 2 - int(self.even)
|
| 78 |
+
self.pad_right = kernel_size // 2
|
| 79 |
+
self.stride = stride
|
| 80 |
+
self.padding = padding
|
| 81 |
+
self.padding_mode = padding_mode
|
| 82 |
+
filter = kaiser_sinc_filter1d(cutoff, half_width, kernel_size)
|
| 83 |
+
self.register_buffer("filter", filter)
|
| 84 |
+
|
| 85 |
+
#input [B, C, T]
|
| 86 |
+
def forward(self, x):
|
| 87 |
+
_, C, _ = x.shape
|
| 88 |
+
|
| 89 |
+
if self.padding:
|
| 90 |
+
x = F.pad(x, (self.pad_left, self.pad_right),
|
| 91 |
+
mode=self.padding_mode)
|
| 92 |
+
out = F.conv1d(x, self.filter.expand(C, -1, -1),
|
| 93 |
+
stride=self.stride, groups=C)
|
| 94 |
+
|
| 95 |
+
return out
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/alias_free_torch/resample.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Adapted from https://github.com/junjun3518/alias-free-torch under the Apache License 2.0
|
| 2 |
+
# LICENSE is in incl_licenses directory.
|
| 3 |
+
|
| 4 |
+
import torch.nn as nn
|
| 5 |
+
from torch.nn import functional as F
|
| 6 |
+
from .filter import LowPassFilter1d
|
| 7 |
+
from .filter import kaiser_sinc_filter1d
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class UpSample1d(nn.Module):
|
| 11 |
+
def __init__(self, ratio=2, kernel_size=None):
|
| 12 |
+
super().__init__()
|
| 13 |
+
self.ratio = ratio
|
| 14 |
+
self.kernel_size = int(6 * ratio // 2) * 2 if kernel_size is None else kernel_size
|
| 15 |
+
self.stride = ratio
|
| 16 |
+
self.pad = self.kernel_size // ratio - 1
|
| 17 |
+
self.pad_left = self.pad * self.stride + (self.kernel_size - self.stride) // 2
|
| 18 |
+
self.pad_right = self.pad * self.stride + (self.kernel_size - self.stride + 1) // 2
|
| 19 |
+
filter = kaiser_sinc_filter1d(cutoff=0.5 / ratio,
|
| 20 |
+
half_width=0.6 / ratio,
|
| 21 |
+
kernel_size=self.kernel_size)
|
| 22 |
+
self.register_buffer("filter", filter)
|
| 23 |
+
|
| 24 |
+
# x: [B, C, T]
|
| 25 |
+
def forward(self, x):
|
| 26 |
+
_, C, _ = x.shape
|
| 27 |
+
|
| 28 |
+
x = F.pad(x, (self.pad, self.pad), mode='replicate')
|
| 29 |
+
x = self.ratio * F.conv_transpose1d(
|
| 30 |
+
x, self.filter.expand(C, -1, -1), stride=self.stride, groups=C)
|
| 31 |
+
x = x[..., self.pad_left:-self.pad_right]
|
| 32 |
+
|
| 33 |
+
return x
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class DownSample1d(nn.Module):
|
| 37 |
+
def __init__(self, ratio=2, kernel_size=None):
|
| 38 |
+
super().__init__()
|
| 39 |
+
self.ratio = ratio
|
| 40 |
+
self.kernel_size = int(6 * ratio // 2) * 2 if kernel_size is None else kernel_size
|
| 41 |
+
self.lowpass = LowPassFilter1d(cutoff=0.5 / ratio,
|
| 42 |
+
half_width=0.6 / ratio,
|
| 43 |
+
stride=ratio,
|
| 44 |
+
kernel_size=self.kernel_size)
|
| 45 |
+
|
| 46 |
+
def forward(self, x):
|
| 47 |
+
xx = self.lowpass(x)
|
| 48 |
+
|
| 49 |
+
return xx
|
custom_nodes/ComfyUI-WanVideoWrapper/Ovi/bigvgan/bigvgan.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
from types import SimpleNamespace
|
| 4 |
+
|
| 5 |
+
from .models import BigVGANVocoder
|
| 6 |
+
|
| 7 |
+
from comfy.utils import load_torch_file
|
| 8 |
+
|
| 9 |
+
# BigVGAN vocoder configuration
|
| 10 |
+
_bigvgan_vocoder_config = {
|
| 11 |
+
'resblock': '1',
|
| 12 |
+
'num_gpus': 0,
|
| 13 |
+
'batch_size': 64,
|
| 14 |
+
'num_mels': 80,
|
| 15 |
+
'learning_rate': 0.0001,
|
| 16 |
+
'adam_b1': 0.8,
|
| 17 |
+
'adam_b2': 0.99,
|
| 18 |
+
'lr_decay': 0.999,
|
| 19 |
+
'seed': 1234,
|
| 20 |
+
'upsample_rates': [4, 4, 2, 2, 2, 2],
|
| 21 |
+
'upsample_kernel_sizes': [8, 8, 4, 4, 4, 4],
|
| 22 |
+
'upsample_initial_channel': 1536,
|
| 23 |
+
'resblock_kernel_sizes': [3, 7, 11],
|
| 24 |
+
'resblock_dilation_sizes': [
|
| 25 |
+
[1, 3, 5],
|
| 26 |
+
[1, 3, 5],
|
| 27 |
+
[1, 3, 5]
|
| 28 |
+
],
|
| 29 |
+
'activation': 'snakebeta',
|
| 30 |
+
'snake_logscale': True,
|
| 31 |
+
'resolutions': [
|
| 32 |
+
[1024, 120, 600],
|
| 33 |
+
[2048, 240, 1200],
|
| 34 |
+
[512, 50, 240]
|
| 35 |
+
],
|
| 36 |
+
'mpd_reshapes': [2, 3, 5, 7, 11],
|
| 37 |
+
'use_spectral_norm': False,
|
| 38 |
+
'discriminator_channel_mult': 1,
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
class BigVGAN(nn.Module):
|
| 42 |
+
|
| 43 |
+
def __init__(self, ckpt_path):
|
| 44 |
+
super().__init__()
|
| 45 |
+
# Convert dictionary to namespace object for attribute access
|
| 46 |
+
vocoder_cfg = SimpleNamespace(**_bigvgan_vocoder_config)
|
| 47 |
+
self.vocoder = BigVGANVocoder(vocoder_cfg).eval()
|
| 48 |
+
vocoder_ckpt = load_torch_file(ckpt_path)
|
| 49 |
+
self.vocoder.load_state_dict(vocoder_ckpt)
|
| 50 |
+
|
| 51 |
+
self.weight_norm_removed = False
|
| 52 |
+
self.remove_weight_norm()
|
| 53 |
+
|
| 54 |
+
@torch.inference_mode()
|
| 55 |
+
def forward(self, x):
|
| 56 |
+
assert self.weight_norm_removed, 'call remove_weight_norm() before inference'
|
| 57 |
+
return self.vocoder(x)
|
| 58 |
+
|
| 59 |
+
def remove_weight_norm(self):
|
| 60 |
+
self.vocoder.remove_weight_norm()
|
| 61 |
+
self.weight_norm_removed = True
|
| 62 |
+
return self
|