Upload folder using huggingface_hub
Browse files- backup/RESTORE.md +45 -0
- backup/VERSIONS.txt +9 -0
- backup/code.tar.gz +3 -0
- backup/constraints.txt +2 -0
- backup/infinitetalk.patch +291 -0
- backup/pip-freeze.txt +173 -0
backup/RESTORE.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Restore InfiniteTalk + FP8 TensorRT on a fresh H100
|
| 2 |
+
|
| 3 |
+
## 1. Code
|
| 4 |
+
tar xzf code.tar.gz -C /workspace
|
| 5 |
+
|
| 6 |
+
## 2. Weights (NOT in this backup - re-download, they are public)
|
| 7 |
+
hf download Wan-AI/Wan2.1-I2V-14B-480P --local-dir /workspace/weights/Wan2.1-I2V-14B-480P
|
| 8 |
+
hf download MeiGen-AI/InfiniteTalk --include "single/*" --local-dir /workspace/weights/InfiniteTalk
|
| 9 |
+
hf download TencentGameMate/chinese-wav2vec2-base --local-dir /workspace/weights/chinese-wav2vec2-base
|
| 10 |
+
hf download TencentGameMate/chinese-wav2vec2-base --revision refs/pr/1 --include "model.safetensors" --local-dir /workspace/weights/chinese-wav2vec2-base
|
| 11 |
+
hf download Kijai/WanVideo_comfy Lightx2v/lightx2v_I2V_14B_480p_cfg_step_distill_rank64_bf16.safetensors --local-dir /workspace/weights/loras
|
| 12 |
+
|
| 13 |
+
## 3. Python env (pin torch, or the CUDA stack gets swapped out from under you)
|
| 14 |
+
uv pip install -c constraints.txt -r pip-freeze.txt
|
| 15 |
+
Key pins: torch==2.8.0+cu128, xformers==0.0.32.post2, transformers==4.51.3,
|
| 16 |
+
flash_attn 2.8.3.post1 (cu12torch2.8, cxx11abiTRUE), and
|
| 17 |
+
export XFORMERS_IGNORE_FLASH_VERSION_CHECK=1
|
| 18 |
+
|
| 19 |
+
## 4. TRT engines
|
| 20 |
+
The engines in engines/ are a CACHE, valid only on the same GPU model + TRT
|
| 21 |
+
version (see VERSIONS.txt). Try them first:
|
| 22 |
+
|
| 23 |
+
python -c "
|
| 24 |
+
import tensorrt as trt
|
| 25 |
+
rt = trt.Runtime(trt.Logger(trt.Logger.ERROR))
|
| 26 |
+
e = rt.deserialize_cuda_engine(open('/workspace/engines/block0.plan','rb').read())
|
| 27 |
+
print('engines OK' if e else 'ENGINES INVALID -> rebuild')"
|
| 28 |
+
|
| 29 |
+
If invalid (different GPU/TRT), rebuild - ~18 min total, fully scripted:
|
| 30 |
+
# a) capture calibration activations (~5 min)
|
| 31 |
+
CAPTURE=1 <run generate_infinitetalk.py once, 81-frame clip> # see notes below
|
| 32 |
+
# b) build 40 FP8 engines (~13 min)
|
| 33 |
+
python /workspace/trt/build_engines.py
|
| 34 |
+
|
| 35 |
+
## 5. Run
|
| 36 |
+
/workspace/start_server.sh # warm server, loads model once
|
| 37 |
+
/workspace/generate.sh <image> <audio> "<prompt>" <name>
|
| 38 |
+
|
| 39 |
+
## Gotchas
|
| 40 |
+
- Engines are STATIC: 81-frame windows @ 448x832 (30,576 tokens) with the 4-step
|
| 41 |
+
I2V LoRA baked in. Change resolution / frame count / LoRA / steps -> rebuild.
|
| 42 |
+
- Under WAN_TRT=1 the PyTorch blocks are DELETED (multitalk.py:689 would
|
| 43 |
+
otherwise drag 27GB back onto the GPU).
|
| 44 |
+
- All 40 engine contexts share ONE scratch buffer (5.85GB); 40 private ones
|
| 45 |
+
would need 234GB.
|
backup/VERSIONS.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Restore ONLY guaranteed on a matching stack:
|
| 2 |
+
NVIDIA H100 NVL, 580.159.03
|
| 3 |
+
torch 2.8.0+cu128
|
| 4 |
+
tensorrt 10.12.0.36
|
| 5 |
+
torch_tensorrt 2.8.0
|
| 6 |
+
cuda 12.8
|
| 7 |
+
xformers 0.0.32.post2
|
| 8 |
+
transformers 4.51.3
|
| 9 |
+
flash_attn 2.8.3.post1
|
backup/code.tar.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:95204f03973fd44c2d3f1d837c28c7b5007f783a9ea6c5fe8f0bae84fd938abd
|
| 3 |
+
size 27309404
|
backup/constraints.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch==2.8.0
|
| 2 |
+
torchvision==0.23.0
|
backup/infinitetalk.patch
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/generate_infinitetalk.py b/generate_infinitetalk.py
|
| 2 |
+
index e83daa8..77426ce 100644
|
| 3 |
+
--- a/generate_infinitetalk.py
|
| 4 |
+
+++ b/generate_infinitetalk.py
|
| 5 |
+
@@ -20,7 +20,10 @@ import wan
|
| 6 |
+
from wan.configs import SIZE_CONFIGS, SUPPORTED_SIZES, WAN_CONFIGS
|
| 7 |
+
from wan.utils.utils import str2bool, is_video, split_wav_librosa
|
| 8 |
+
from wan.utils.multitalk_utils import save_video_ffmpeg
|
| 9 |
+
-from kokoro import KPipeline
|
| 10 |
+
+try:
|
| 11 |
+
+ from kokoro import KPipeline
|
| 12 |
+
+except ImportError: # TTS stack unused when driving from a local audio file
|
| 13 |
+
+ KPipeline = None
|
| 14 |
+
from transformers import Wav2Vec2FeatureExtractor
|
| 15 |
+
from src.audio_analysis.wav2vec2 import Wav2Vec2Model
|
| 16 |
+
from wan.utils.segvideo import shot_detect
|
| 17 |
+
@@ -544,6 +547,89 @@ def generate(args):
|
| 18 |
+
num_persistent_param_in_dit=args.num_persistent_param_in_dit
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
+ if os.environ.get("WAN_TRT") == "1":
|
| 22 |
+
+ # The engines own the transformer stack now: keep the PyTorch blocks off
|
| 23 |
+
+ # the GPU (~27GB) so the 18.6GB of engines fit alongside the rest.
|
| 24 |
+
+ import torch as _t
|
| 25 |
+
+ _n = len(wan_i2v.model.blocks)
|
| 26 |
+
+ wan_i2v.model.blocks = _t.nn.ModuleList([]) # the engines own these now
|
| 27 |
+
+ _t.cuda.empty_cache()
|
| 28 |
+
+ logging.info(f"WAN_TRT: dropped {_n} PyTorch blocks (~27GB); engines own the stack")
|
| 29 |
+
+
|
| 30 |
+
+ if os.environ.get("CAPTURE") == "1":
|
| 31 |
+
+ import sys as _sys
|
| 32 |
+
+ _sys.path.insert(0, "/workspace/trt")
|
| 33 |
+
+ from capture_calib import install_capture
|
| 34 |
+
+ install_capture(wan_i2v.model)
|
| 35 |
+
+
|
| 36 |
+
+ # --- FP8 (H100 native) + torch.compile toggles, applied after LoRA merge ---
|
| 37 |
+
+ if os.environ.get("WAN_FP8") == "1":
|
| 38 |
+
+ import torch as _t
|
| 39 |
+
+ from torchao.quantization import quantize_, Float8DynamicActivationFloat8WeightConfig
|
| 40 |
+
+ _dit = wan_i2v.model
|
| 41 |
+
+ # Only the transformer blocks: the tiny embedders/head stay bf16.
|
| 42 |
+
+ _n = 0
|
| 43 |
+
+ for _blk in _dit.blocks:
|
| 44 |
+
+ quantize_(_blk, Float8DynamicActivationFloat8WeightConfig())
|
| 45 |
+
+ _n += 1
|
| 46 |
+
+ logging.info(f"FP8: quantized {_n} transformer blocks (fp8 dynamic act + fp8 weight)")
|
| 47 |
+
+
|
| 48 |
+
+ if os.environ.get("WAN_COMPILE") == "1":
|
| 49 |
+
+ import torch as _t
|
| 50 |
+
+ _dit = wan_i2v.model
|
| 51 |
+
+ for _i, _blk in enumerate(_dit.blocks):
|
| 52 |
+
+ _dit.blocks[_i] = _t.compile(_blk, dynamic=False)
|
| 53 |
+
+ logging.info(f"compiled {len(_dit.blocks)} transformer blocks")
|
| 54 |
+
+
|
| 55 |
+
+ # --- profiling hook: set PROFILE=1 to time every DiT forward ---
|
| 56 |
+
+ if os.environ.get("PROFILE") == "1":
|
| 57 |
+
+ import time as _time, atexit as _atexit
|
| 58 |
+
+ import torch as _torch
|
| 59 |
+
+ _stats = {"n": 0, "t": 0.0}
|
| 60 |
+
+ _wall0 = _time.perf_counter()
|
| 61 |
+
+ _orig_fwd = wan_i2v.model.forward
|
| 62 |
+
+
|
| 63 |
+
+ _deep = os.environ.get("PROFILE_DEEP") == "1"
|
| 64 |
+
+
|
| 65 |
+
+ def _timed_fwd(*a, **kw):
|
| 66 |
+
+ _torch.cuda.synchronize()
|
| 67 |
+
+ _t0 = _time.perf_counter()
|
| 68 |
+
+ # kernel-level trace of a single steady-state forward (the 2nd)
|
| 69 |
+
+ if _deep and _stats["n"] == 1:
|
| 70 |
+
+ from torch.profiler import profile as _tp, ProfilerActivity as _PA
|
| 71 |
+
+ with _tp(activities=[_PA.CPU, _PA.CUDA], record_shapes=False) as _prof:
|
| 72 |
+
+ out = _orig_fwd(*a, **kw)
|
| 73 |
+
+ _torch.cuda.synchronize()
|
| 74 |
+
+ print("\n======= TOP CUDA KERNELS (one forward) =======")
|
| 75 |
+
+ print(_prof.key_averages().table(
|
| 76 |
+
+ sort_by="self_cuda_time_total", row_limit=28,
|
| 77 |
+
+ max_name_column_width=55))
|
| 78 |
+
+ else:
|
| 79 |
+
+ out = _orig_fwd(*a, **kw)
|
| 80 |
+
+ _torch.cuda.synchronize()
|
| 81 |
+
+ _stats["t"] += _time.perf_counter() - _t0
|
| 82 |
+
+ _stats["n"] += 1
|
| 83 |
+
+ return out
|
| 84 |
+
+
|
| 85 |
+
+ wan_i2v.model.forward = _timed_fwd
|
| 86 |
+
+
|
| 87 |
+
+ def _report():
|
| 88 |
+
+ n, t = _stats["n"], _stats["t"]
|
| 89 |
+
+ wall = _time.perf_counter() - _wall0
|
| 90 |
+
+ peak = _torch.cuda.max_memory_allocated() / 1e9
|
| 91 |
+
+ print("\n================ PROFILE ================")
|
| 92 |
+
+ print(f"DiT forwards : {n}")
|
| 93 |
+
+ print(f"DiT total time : {t:.1f} s")
|
| 94 |
+
+ if n:
|
| 95 |
+
+ print(f"DiT per forward : {t / n * 1000:.0f} ms")
|
| 96 |
+
+ print(f"wall (post-load) : {wall:.1f} s")
|
| 97 |
+
+ if wall > 0:
|
| 98 |
+
+ print(f"DiT share of wall : {t / wall * 100:.0f} %")
|
| 99 |
+
+ print(f"peak VRAM allocated : {peak:.1f} GB")
|
| 100 |
+
+ print("=========================================")
|
| 101 |
+
+
|
| 102 |
+
+ _atexit.register(_report)
|
| 103 |
+
+
|
| 104 |
+
generated_list = []
|
| 105 |
+
with open(args.input_json, 'r', encoding='utf-8') as f:
|
| 106 |
+
input_data = json.load(f)
|
| 107 |
+
diff --git a/wan/modules/multitalk_model.py b/wan/modules/multitalk_model.py
|
| 108 |
+
index 958e930..6eef6f3 100644
|
| 109 |
+
--- a/wan/modules/multitalk_model.py
|
| 110 |
+
+++ b/wan/modules/multitalk_model.py
|
| 111 |
+
@@ -21,6 +21,29 @@ try:
|
| 112 |
+
except:
|
| 113 |
+
USE_SAGEATTN = False
|
| 114 |
+
|
| 115 |
+
+from torch.nn.attention import sdpa_kernel, SDPBackend
|
| 116 |
+
+
|
| 117 |
+
+# cuDNN's Hopper attention beat sageattn 44.6ms vs 58.5ms at our shape.
|
| 118 |
+
+USE_CUDNN_SDPA = os.environ.get("WAN_CUDNN_ATTN", "1") == "1"
|
| 119 |
+
+
|
| 120 |
+
+# --- FP8 TensorRT block stack (WAN_TRT=1) -------------------------------------
|
| 121 |
+
+_TRT_STACK = None
|
| 122 |
+
+_TRT_SEQ_LEN = int(os.environ.get("WAN_TRT_SEQ_LEN", "30576")) # 81 frames @ 448x832
|
| 123 |
+
+
|
| 124 |
+
+
|
| 125 |
+
+def _trt_stack():
|
| 126 |
+
+ """Lazily load the engines; returns None when TRT is off."""
|
| 127 |
+
+ global _TRT_STACK
|
| 128 |
+
+ if os.environ.get("WAN_TRT") != "1":
|
| 129 |
+
+ return None
|
| 130 |
+
+ if _TRT_STACK is None:
|
| 131 |
+
+ import sys
|
| 132 |
+
+ sys.path.insert(0, "/workspace/trt")
|
| 133 |
+
+ from trt_runner import TRTStack
|
| 134 |
+
+ _TRT_STACK = TRTStack()
|
| 135 |
+
+ return _TRT_STACK
|
| 136 |
+
+
|
| 137 |
+
+
|
| 138 |
+
__all__ = ['WanModel']
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
@@ -50,30 +73,52 @@ def rope_params(max_seq_len, dim, theta=10000):
|
| 142 |
+
return freqs
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
+_ROPE_CACHE = {}
|
| 146 |
+
+
|
| 147 |
+
+
|
| 148 |
+
+def _rope_cos_sin(grid_sizes, freqs, device, dtype):
|
| 149 |
+
+ """cos/sin RoPE table for this latent grid, built once and kept on-device."""
|
| 150 |
+
+ f, h, w = (int(v) for v in grid_sizes[0].tolist())
|
| 151 |
+
+ key = (f, h, w, str(device), dtype)
|
| 152 |
+
+ hit = _ROPE_CACHE.get(key)
|
| 153 |
+
+ if hit is not None:
|
| 154 |
+
+ return hit
|
| 155 |
+
+
|
| 156 |
+
+ c = freqs.size(1)
|
| 157 |
+
+ fr = freqs.split([c - 2 * (c // 3), c // 3, c // 3], dim=1)
|
| 158 |
+
+ freqs_i = torch.cat([
|
| 159 |
+
+ fr[0][:f].view(f, 1, 1, -1).expand(f, h, w, -1),
|
| 160 |
+
+ fr[1][:h].view(1, h, 1, -1).expand(f, h, w, -1),
|
| 161 |
+
+ fr[2][:w].view(1, 1, w, -1).expand(f, h, w, -1),
|
| 162 |
+
+ ], dim=-1).reshape(f * h * w, 1, -1) # [L, 1, C/2] complex
|
| 163 |
+
+
|
| 164 |
+
+ cos = freqs_i.real.to(device=device, dtype=dtype).contiguous()
|
| 165 |
+
+ sin = freqs_i.imag.to(device=device, dtype=dtype).contiguous()
|
| 166 |
+
+ _ROPE_CACHE[key] = (cos, sin)
|
| 167 |
+
+ return cos, sin
|
| 168 |
+
+
|
| 169 |
+
+
|
| 170 |
+
@amp.autocast(enabled=False)
|
| 171 |
+
def rope_apply(x, grid_sizes, freqs):
|
| 172 |
+
- s, n, c = x.size(1), x.size(2), x.size(3) // 2
|
| 173 |
+
+ """Real-valued RoPE. Mathematically identical to the complex fp64 version,
|
| 174 |
+
+ minus the per-layer host->device copy and the float64 traffic."""
|
| 175 |
+
+ b, s, n, d = x.shape
|
| 176 |
+
+ cos, sin = _rope_cos_sin(grid_sizes, freqs, x.device, torch.float32)
|
| 177 |
+
+ L = cos.size(0)
|
| 178 |
+
|
| 179 |
+
- freqs = freqs.split([c - 2 * (c // 3), c // 3, c // 3], dim=1)
|
| 180 |
+
+ xf = x[:, :L].float().reshape(b, L, n, d // 2, 2)
|
| 181 |
+
+ x_r, x_i = xf[..., 0], xf[..., 1]
|
| 182 |
+
|
| 183 |
+
- output = []
|
| 184 |
+
- for i, (f, h, w) in enumerate(grid_sizes.tolist()):
|
| 185 |
+
- seq_len = f * h * w
|
| 186 |
+
+ cos_ = cos.unsqueeze(0) # [1, L, 1, C/2]
|
| 187 |
+
+ sin_ = sin.unsqueeze(0)
|
| 188 |
+
|
| 189 |
+
- x_i = torch.view_as_complex(x[i, :s].to(torch.float64).reshape(
|
| 190 |
+
- s, n, -1, 2))
|
| 191 |
+
- freqs_i = torch.cat([
|
| 192 |
+
- freqs[0][:f].view(f, 1, 1, -1).expand(f, h, w, -1),
|
| 193 |
+
- freqs[1][:h].view(1, h, 1, -1).expand(f, h, w, -1),
|
| 194 |
+
- freqs[2][:w].view(1, 1, w, -1).expand(f, h, w, -1)
|
| 195 |
+
- ],
|
| 196 |
+
- dim=-1).reshape(seq_len, 1, -1)
|
| 197 |
+
- freqs_i = freqs_i.to(device=x_i.device)
|
| 198 |
+
- x_i = torch.view_as_real(x_i * freqs_i).flatten(2)
|
| 199 |
+
- x_i = torch.cat([x_i, x[i, seq_len:]])
|
| 200 |
+
+ o_r = x_r * cos_ - x_i * sin_
|
| 201 |
+
+ o_i = x_r * sin_ + x_i * cos_
|
| 202 |
+
+ out = torch.stack([o_r, o_i], dim=-1).flatten(3)
|
| 203 |
+
|
| 204 |
+
- output.append(x_i)
|
| 205 |
+
- return torch.stack(output).float()
|
| 206 |
+
+ if L < s: # keep any padding untouched
|
| 207 |
+
+ out = torch.cat([out, x[:, L:].float()], dim=1)
|
| 208 |
+
+ return out.float()
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
class WanRMSNorm(nn.Module):
|
| 212 |
+
@@ -137,7 +182,7 @@ class WanSelfAttention(nn.Module):
|
| 213 |
+
self.norm_q = WanRMSNorm(dim, eps=eps) if qk_norm else nn.Identity()
|
| 214 |
+
self.norm_k = WanRMSNorm(dim, eps=eps) if qk_norm else nn.Identity()
|
| 215 |
+
|
| 216 |
+
- def forward(self, x, seq_lens, grid_sizes, freqs, ref_target_masks=None):
|
| 217 |
+
+ def forward(self, x, seq_lens, grid_sizes, freqs, ref_target_masks=None, human_num=None):
|
| 218 |
+
b, s, n, d = *x.shape[:2], self.num_heads, self.head_dim
|
| 219 |
+
|
| 220 |
+
# query, key, value function
|
| 221 |
+
@@ -151,7 +196,15 @@ class WanSelfAttention(nn.Module):
|
| 222 |
+
q = rope_apply(q, grid_sizes, freqs)
|
| 223 |
+
k = rope_apply(k, grid_sizes, freqs)
|
| 224 |
+
|
| 225 |
+
- if USE_SAGEATTN:
|
| 226 |
+
+ if USE_CUDNN_SDPA:
|
| 227 |
+
+ # [B, L, H, D] -> [B, H, L, D] for SDPA, and back
|
| 228 |
+
+ qb = q.transpose(1, 2).to(torch.bfloat16)
|
| 229 |
+
+ kb = k.transpose(1, 2).to(torch.bfloat16)
|
| 230 |
+
+ vb = v.transpose(1, 2).to(torch.bfloat16)
|
| 231 |
+
+ with sdpa_kernel(SDPBackend.CUDNN_ATTENTION):
|
| 232 |
+
+ x = F.scaled_dot_product_attention(qb, kb, vb)
|
| 233 |
+
+ x = x.transpose(1, 2).type_as(v)
|
| 234 |
+
+ elif USE_SAGEATTN:
|
| 235 |
+
x = sageattn(q.to(torch.bfloat16), k.to(torch.bfloat16), v, tensor_layout='NHD')
|
| 236 |
+
else:
|
| 237 |
+
x = flash_attention(
|
| 238 |
+
@@ -165,9 +218,15 @@ class WanSelfAttention(nn.Module):
|
| 239 |
+
# output
|
| 240 |
+
x = x.flatten(2)
|
| 241 |
+
x = self.o(x)
|
| 242 |
+
- with torch.no_grad():
|
| 243 |
+
- x_ref_attn_map = get_attn_map_with_target(q.type_as(x), k.type_as(x), grid_sizes[0],
|
| 244 |
+
- ref_target_masks=ref_target_masks)
|
| 245 |
+
+ # The ref-attn map only feeds SingleStreamMutiAttention's multi-speaker routing;
|
| 246 |
+
+ # with one speaker that branch short-circuits and never reads it, so skip building
|
| 247 |
+
+ # a [heads, seq, ref_seq] map (GBs) in every layer.
|
| 248 |
+
+ if human_num == 1:
|
| 249 |
+
+ x_ref_attn_map = None
|
| 250 |
+
+ else:
|
| 251 |
+
+ with torch.no_grad():
|
| 252 |
+
+ x_ref_attn_map = get_attn_map_with_target(q.type_as(x), k.type_as(x), grid_sizes[0],
|
| 253 |
+
+ ref_target_masks=ref_target_masks)
|
| 254 |
+
|
| 255 |
+
return x, x_ref_attn_map
|
| 256 |
+
|
| 257 |
+
@@ -294,7 +353,7 @@ class WanAttentionBlock(nn.Module):
|
| 258 |
+
# self-attention
|
| 259 |
+
y, x_ref_attn_map = self.self_attn(
|
| 260 |
+
(self.norm1(x).float() * (1 + e[1]) + e[0]).type_as(x), seq_lens, grid_sizes,
|
| 261 |
+
- freqs, ref_target_masks=ref_target_masks)
|
| 262 |
+
+ freqs, ref_target_masks=ref_target_masks, human_num=human_num)
|
| 263 |
+
with amp.autocast(dtype=torch.float32):
|
| 264 |
+
x = x + y * e[2]
|
| 265 |
+
|
| 266 |
+
@@ -757,7 +816,14 @@ class WanModel(ModelMixin, ConfigMixin):
|
| 267 |
+
for block in self.blocks:
|
| 268 |
+
x = block(x, **kwargs)
|
| 269 |
+
self.previous_residual_uncond = x - ori_x
|
| 270 |
+
+ elif _trt_stack() is not None and x.shape[1] == _TRT_SEQ_LEN:
|
| 271 |
+
+ cos, sin = _rope_cos_sin(grid_sizes, self.freqs, x.device, torch.float32)
|
| 272 |
+
+ x = _trt_stack()(x, e0, context, audio_embedding.squeeze(0), cos, sin)
|
| 273 |
+
else:
|
| 274 |
+
+ if os.environ.get("WAN_TRT") == "1":
|
| 275 |
+
+ raise RuntimeError(
|
| 276 |
+
+ f"WAN_TRT=1 but seq_len {x.shape[1]} != engine seq_len {_TRT_SEQ_LEN}. "
|
| 277 |
+
+ f"Engines are static; rebuild them for this frame count/resolution.")
|
| 278 |
+
for block in self.blocks:
|
| 279 |
+
x = block(x, **kwargs)
|
| 280 |
+
|
| 281 |
+
diff --git a/wan/multitalk.py b/wan/multitalk.py
|
| 282 |
+
index be7819e..1e9513b 100644
|
| 283 |
+
--- a/wan/multitalk.py
|
| 284 |
+
+++ b/wan/multitalk.py
|
| 285 |
+
@@ -1,6 +1,5 @@
|
| 286 |
+
# Copyright 2024-2025 The Alibaba Wan Team Authors. All rights reserved.
|
| 287 |
+
import gc
|
| 288 |
+
-from inspect import ArgSpec
|
| 289 |
+
import logging
|
| 290 |
+
import json
|
| 291 |
+
import math
|
backup/pip-freeze.txt
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
accelerate==1.14.0
|
| 2 |
+
aiohappyeyeballs==2.7.1
|
| 3 |
+
aiohttp==3.14.1
|
| 4 |
+
aiosignal==1.4.0
|
| 5 |
+
annotated-doc==0.0.4
|
| 6 |
+
annotated-types==0.7.0
|
| 7 |
+
antlr4-python3-runtime==4.9.3
|
| 8 |
+
anyio==4.13.0
|
| 9 |
+
asttokens==3.0.1
|
| 10 |
+
attrs==26.1.0
|
| 11 |
+
audioread==3.1.0
|
| 12 |
+
beautifulsoup4==4.15.0
|
| 13 |
+
certifi==2026.5.20
|
| 14 |
+
cffi==2.1.0
|
| 15 |
+
charset-normalizer==3.4.9
|
| 16 |
+
click==8.4.1
|
| 17 |
+
comm==0.2.3
|
| 18 |
+
cryptography==49.0.0
|
| 19 |
+
dashscope==1.26.3
|
| 20 |
+
debugpy==1.8.21
|
| 21 |
+
decorator==4.4.2
|
| 22 |
+
decord==0.6.0
|
| 23 |
+
diffusers==0.39.0
|
| 24 |
+
DistVAE==0.0.0b5
|
| 25 |
+
dllist==2.0.0
|
| 26 |
+
easydict==1.13
|
| 27 |
+
einops==0.8.2
|
| 28 |
+
executing==2.2.1
|
| 29 |
+
fastapi==0.139.0
|
| 30 |
+
filelock==3.29.1
|
| 31 |
+
flash_attn @ https://github.com/Dao-AILab/flash-attention/releases/download/v2.8.3.post1/flash_attn-2.8.3.post1+cu12torch2.8cxx11abiTRUE-cp312-cp312-linux_x86_64.whl
|
| 32 |
+
frozenlist==1.8.0
|
| 33 |
+
fsspec==2026.4.0
|
| 34 |
+
ftfy==6.3.1
|
| 35 |
+
h11==0.16.0
|
| 36 |
+
hf-xet==1.5.0
|
| 37 |
+
hf_transfer==0.1.9
|
| 38 |
+
httpcore==1.0.9
|
| 39 |
+
httptools==0.8.0
|
| 40 |
+
httpx==0.28.1
|
| 41 |
+
httpx-sse==0.4.3
|
| 42 |
+
huggingface_hub==0.36.2
|
| 43 |
+
idna==3.18
|
| 44 |
+
ImageIO==2.37.3
|
| 45 |
+
imageio-ffmpeg==0.6.0
|
| 46 |
+
importlib_metadata==9.0.0
|
| 47 |
+
ipykernel==7.2.0
|
| 48 |
+
ipython==9.14.1
|
| 49 |
+
ipython_pygments_lexers==1.1.1
|
| 50 |
+
ipywidgets==8.1.8
|
| 51 |
+
jedi==0.20.0
|
| 52 |
+
Jinja2==3.1.6
|
| 53 |
+
joblib==1.5.3
|
| 54 |
+
jupyter_client==8.9.0
|
| 55 |
+
jupyter_core==5.9.1
|
| 56 |
+
jupyterlab_widgets==3.0.16
|
| 57 |
+
lazy-loader==0.5
|
| 58 |
+
librosa==0.11.0
|
| 59 |
+
llvmlite==0.48.0
|
| 60 |
+
loguru==0.7.3
|
| 61 |
+
markdown-it-py==4.2.0
|
| 62 |
+
MarkupSafe==3.0.3
|
| 63 |
+
matplotlib-inline==0.2.2
|
| 64 |
+
mdurl==0.1.2
|
| 65 |
+
ml_dtypes==0.5.4
|
| 66 |
+
moviepy==1.0.3
|
| 67 |
+
mpmath==1.3.0
|
| 68 |
+
msgpack==1.2.1
|
| 69 |
+
multidict==6.7.1
|
| 70 |
+
narwhals==2.23.0
|
| 71 |
+
nest-asyncio==1.6.0
|
| 72 |
+
networkx==3.6.1
|
| 73 |
+
ninja==1.13.0
|
| 74 |
+
numba==0.66.0
|
| 75 |
+
numpy==1.26.4
|
| 76 |
+
nvidia-cublas-cu12==12.8.4.1
|
| 77 |
+
nvidia-cuda-cupti-cu12==12.8.90
|
| 78 |
+
nvidia-cuda-nvrtc-cu12==12.8.93
|
| 79 |
+
nvidia-cuda-runtime-cu12==12.8.90
|
| 80 |
+
nvidia-cudnn-cu12==9.10.2.21
|
| 81 |
+
nvidia-cufft-cu12==11.3.3.83
|
| 82 |
+
nvidia-cufile-cu12==1.13.1.3
|
| 83 |
+
nvidia-curand-cu12==10.3.9.90
|
| 84 |
+
nvidia-cusolver-cu12==11.7.3.90
|
| 85 |
+
nvidia-cusparse-cu12==12.5.8.93
|
| 86 |
+
nvidia-cusparselt-cu12==0.7.1
|
| 87 |
+
nvidia-ml-py==13.610.43
|
| 88 |
+
nvidia-modelopt==0.45.0
|
| 89 |
+
nvidia-nccl-cu12==2.27.3
|
| 90 |
+
nvidia-nvjitlink-cu12==12.8.93
|
| 91 |
+
nvidia-nvtx-cu12==12.8.90
|
| 92 |
+
omegaconf==2.3.1
|
| 93 |
+
onnx==1.22.0
|
| 94 |
+
opencv-python==4.11.0.86
|
| 95 |
+
optimum-quanto==0.2.6
|
| 96 |
+
packaging @ file:///home/conda/feedstock_root/build_artifacts/bld/rattler-build_packaging_1777103621/work
|
| 97 |
+
parso==0.8.7
|
| 98 |
+
pexpect==4.9.0
|
| 99 |
+
pillow==12.2.0
|
| 100 |
+
platformdirs==4.10.0
|
| 101 |
+
pooch==1.9.0
|
| 102 |
+
proglog==0.1.12
|
| 103 |
+
prompt_toolkit==3.0.52
|
| 104 |
+
propcache==0.5.2
|
| 105 |
+
protobuf==7.35.1
|
| 106 |
+
psutil==7.2.2
|
| 107 |
+
ptyprocess==0.7.0
|
| 108 |
+
PuLP==3.3.2
|
| 109 |
+
pure_eval==0.2.3
|
| 110 |
+
pycparser==3.0
|
| 111 |
+
pydantic==2.13.4
|
| 112 |
+
pydantic_core==2.46.4
|
| 113 |
+
Pygments==2.20.0
|
| 114 |
+
pyloudnorm==0.2.0
|
| 115 |
+
python-dateutil==2.9.0.post0
|
| 116 |
+
python-dotenv==1.2.2
|
| 117 |
+
python-multipart==0.0.32
|
| 118 |
+
PyYAML==6.0.3
|
| 119 |
+
pyzmq==27.1.0
|
| 120 |
+
regex==2026.7.10
|
| 121 |
+
requests==2.34.2
|
| 122 |
+
rich==15.0.0
|
| 123 |
+
safetensors==0.8.0
|
| 124 |
+
sageattention==1.0.6
|
| 125 |
+
scenedetect==0.7
|
| 126 |
+
scikit-image==0.26.0
|
| 127 |
+
scikit-learn==1.9.0
|
| 128 |
+
scipy==1.17.1
|
| 129 |
+
sentencepiece==0.2.2
|
| 130 |
+
setuptools==82.0.1
|
| 131 |
+
shellingham==1.5.4
|
| 132 |
+
six==1.17.0
|
| 133 |
+
soundfile==0.14.0
|
| 134 |
+
soupsieve==2.8.4
|
| 135 |
+
soxr==1.1.0
|
| 136 |
+
stack-data==0.6.3
|
| 137 |
+
starlette==1.3.1
|
| 138 |
+
sympy==1.14.0
|
| 139 |
+
tensorrt==10.12.0.36
|
| 140 |
+
tensorrt_cu12==10.12.0.36
|
| 141 |
+
tensorrt_cu12_bindings==10.12.0.36
|
| 142 |
+
tensorrt_cu12_libs==10.12.0.36
|
| 143 |
+
threadpoolctl==3.6.0
|
| 144 |
+
tifffile==2026.3.3
|
| 145 |
+
tokenizers==0.21.4
|
| 146 |
+
torch==2.8.0+cu128
|
| 147 |
+
torch_tensorrt==2.8.0
|
| 148 |
+
torchao==0.17.0
|
| 149 |
+
torchaudio==2.8.0+cu128
|
| 150 |
+
torchcodec==0.7.0+cu128
|
| 151 |
+
torchvision==0.23.0+cu128
|
| 152 |
+
tornado==6.5.6
|
| 153 |
+
tqdm==4.68.0
|
| 154 |
+
traitlets==5.15.1
|
| 155 |
+
transformers==4.51.3
|
| 156 |
+
triton==3.4.0
|
| 157 |
+
typer==0.25.1
|
| 158 |
+
typing-inspection==0.4.2
|
| 159 |
+
typing_extensions==4.15.0
|
| 160 |
+
urllib3==2.7.0
|
| 161 |
+
uvicorn==0.51.0
|
| 162 |
+
uvloop==0.22.1
|
| 163 |
+
watchfiles==1.2.0
|
| 164 |
+
wcwidth==0.7.0
|
| 165 |
+
websocket-client==1.9.0
|
| 166 |
+
websockets==16.1
|
| 167 |
+
wheel==0.47.0
|
| 168 |
+
widgetsnbextension==4.0.15
|
| 169 |
+
xformers==0.0.32.post2
|
| 170 |
+
xfuser==0.4.5
|
| 171 |
+
yarl==1.24.2
|
| 172 |
+
yunchang==0.6.4
|
| 173 |
+
zipp==4.1.0
|