Skip to content
Python

Vace Lynx Unleashed

DeepBeepMeepbb70ca7d1494
diff --git a/README.md b/README.md
index 637b164..db25ed6 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ WanGP supports the Wan (and derived models), Hunyuan Video and LTV Video models
**Follow DeepBeepMeep on Twitter/X to get the Latest News**: https://x.com/deepbeepmeep
## 🔥 Latest Updates :
-### October 2 2025: WanGP v8.99 - One Last Thing before the Big Unknown ...
+### October 2 2025: WanGP v8.991 - One Last Thing before the Big Unknown ...
This new version hasn't any new model...
@@ -35,6 +35,7 @@ I have created the new Discord Channel **share-your-settings** where you can pos
Last but not least the Lora's documentation has been updated.
+*update 8.991*: full power of *Vace Lynx* unleashed with new combinations such as Landscape + Face / Clothes + Face / Injectd Frame (Start/End frames/...) + Face
### September 30 2025: WanGP v8.9 - Combinatorics
This new version of WanGP introduces **Wan 2.1 Lynx** the best Control Net so far to transfer *Facial Identity*. You will be amazed to recognize your friends even with a completely different hair style. Congrats to the *Byte Dance team* for this achievement. Lynx works quite with well *Fusionix t2v* 10 steps.
diff --git a/defaults/vace_lynx_14B.json b/defaults/vace_lynx_14B.json
index 523d5b3..3584aa9 100644
--- a/defaults/vace_lynx_14B.json
+++ b/defaults/vace_lynx_14B.json
@@ -3,7 +3,7 @@
"name": "Vace Lynx 14B",
"architecture": "vace_lynx_14B",
"modules": [ "vace_14B", "lynx"],
- "description": "The Vace ControlNet model is a powerful model that allows you to control the content of the generated video based of additional custom data : pose or depth video, images or objects you want to see in the video. The Lynx version is specialized in transferring a Person Identity.",
+ "description": "The Vace ControlNet model is a powerful model that allows you to control the content of the generated video based of additional custom data : pose or depth video, images or objects you want to see in the video. The Lynx version is specialized in identity transfer, so the last Image Ref should always contain a close up of the Face of a Person to transfer.",
"URLs": "t2v",
"preload_URLs": "lynx"
}
diff --git a/defaults/vace_standin_14B.json b/defaults/vace_standin_14B.json
index 6fc8a68..b6f6af0 100644
--- a/defaults/vace_standin_14B.json
+++ b/defaults/vace_standin_14B.json
@@ -3,7 +3,7 @@
"name": "Vace Standin 14B",
"architecture": "vace_standin_14B",
"modules": [ "vace_14B", "standin"],
- "description": "The Vace ControlNet model is a powerful model that allows you to control the content of the generated video based of additional custom data : pose or depth video, images or objects you want to see in the video.",
+ "description": "The Vace ControlNet model is a powerful model that allows you to control the content of the generated video based of additional custom data : pose or depth video, images or objects you want to see in the video. The Standin version is specialized in identity transfer, so the last Image Ref should always contain a close up of the Face of a Person to transfer.",
"URLs": "t2v"
}
}
\ No newline at end of file
diff --git a/models/wan/any2video.py b/models/wan/any2video.py
index 6c45509..243dddb 100644
--- a/models/wan/any2video.py
+++ b/models/wan/any2video.py
@@ -686,13 +686,68 @@ class WanAny2V:
if extended_input_dim > 0:
extended_latents[:, :, :source_latents.shape[2]] = source_latents
+ # Lynx
+ if lynx :
+ if original_input_ref_images is None or len(original_input_ref_images) == 0:
+ lynx = False
+ elif "K" in video_prompt_type and len(input_ref_images) <= 1:
+ print("Warning: Missing Lynx Ref Image, make sure 'Inject only People / Objets' is selected or if there is 'Landscape and then People or Objects' there are at least two ref images (one Landscape image followed by face).")
+ lynx = False
+ else:
+ from .lynx.resampler import Resampler
+ from accelerate import init_empty_weights
+ lynx_lite = model_type in ["lynx_lite", "vace_lynx_lite_14B"]
+ ip_hidden_states = ip_hidden_states_uncond = None
+ if True:
+ with init_empty_weights():
+ arc_resampler = Resampler( depth=4, dim=1280, dim_head=64, embedding_dim=512, ff_mult=4, heads=20, num_queries=16, output_dim=2048 if lynx_lite else 5120 )
+ offload.load_model_data(arc_resampler, os.path.join("ckpts", "wan2.1_lynx_lite_arc_resampler.safetensors" if lynx_lite else "wan2.1_lynx_full_arc_resampler.safetensors"))
+ arc_resampler.to(self.device)
+ arcface_embed = face_arc_embeds[None,None,:].to(device=self.device, dtype=torch.float)
+ ip_hidden_states = arc_resampler(arcface_embed).to(self.dtype)
+ ip_hidden_states_uncond = arc_resampler(torch.zeros_like(arcface_embed)).to(self.dtype)
+ arc_resampler = None
+ if not lynx_lite:
+ standin_ref_pos = -1
+ image_ref = original_input_ref_images[standin_ref_pos]
+ from preprocessing.face_preprocessor import FaceProcessor
+ face_processor = FaceProcessor()
+ lynx_ref = face_processor.process(image_ref, resize_to = 256 )
+ lynx_ref_buffer, lynx_ref_buffer_uncond = self.encode_reference_images([lynx_ref], tile_size=VAE_tile_size, any_guidance= any_guidance_at_all)
+ lynx_ref = None
+ gc.collect()
+ torch.cuda.empty_cache()
+ vace_lynx = model_type in ["vace_lynx_14B"]
+ kwargs["lynx_ip_scale"] = control_scale_alt
+ kwargs["lynx_ref_scale"] = control_scale_alt
+
+ #Standin
+ if standin:
+ from preprocessing.face_preprocessor import FaceProcessor
+ standin_ref_pos = 1 if "K" in video_prompt_type else 0
+ if len(original_input_ref_images) < standin_ref_pos + 1:
+ if "I" in video_prompt_type and model_type in ["vace_standin_14B"]:
+ print("Warning: Missing Standin ref image, make sure 'Inject only People / Objets' is selected or if there is 'Landscape and then People or Objects' there are at least two ref images.")
+ else:
+ standin_ref_pos = -1
+ image_ref = original_input_ref_images[standin_ref_pos]
+ face_processor = FaceProcessor()
+ standin_ref = face_processor.process(image_ref, remove_bg = model_type in ["vace_standin_14B"])
+ face_processor = None
+ gc.collect()
+ torch.cuda.empty_cache()
+ standin_freqs = get_nd_rotary_pos_embed((-1, int(target_shape[-2]/2), int(target_shape[-1]/2) ), (-1, int(target_shape[-2]/2 + standin_ref.height/16), int(target_shape[-1]/2 + standin_ref.width/16) ))
+ standin_ref = self.vae.encode([ convert_image_to_tensor(standin_ref).unsqueeze(1) ], VAE_tile_size)[0].unsqueeze(0)
+ kwargs.update({ "standin_freqs": standin_freqs, "standin_ref": standin_ref, })
+
+
# Vace
if vace :
# vace context encode
input_frames = [input_frames.to(self.device)] +([] if input_frames2 is None else [input_frames2.to(self.device)])
input_masks = [input_masks.to(self.device)] + ([] if input_masks2 is None else [input_masks2.to(self.device)])
- if model_type in ["vace_lynx_14B"]:
- input_ref_images = input_ref_masks = None
+ if model_type in ["vace_lynx_14B"] and input_ref_images is not None:
+ input_ref_images,input_ref_masks = input_ref_images[:-1], input_ref_masks[:-1]
input_ref_images = None if input_ref_images is None else [ u.to(self.device) for u in input_ref_images]
input_ref_masks = None if input_ref_masks is None else [ None if u is None else u.to(self.device) for u in input_ref_masks]
ref_images_before = True
@@ -744,57 +799,6 @@ class WanAny2V:
kwargs["freqs"] = freqs
- # Lynx
- if lynx :
- if original_input_ref_images is None or len(original_input_ref_images) == 0:
- lynx = False
- else:
- from .lynx.resampler import Resampler
- from accelerate import init_empty_weights
- lynx_lite = model_type in ["lynx_lite", "vace_lynx_lite_14B"]
- ip_hidden_states = ip_hidden_states_uncond = None
- if True:
- with init_empty_weights():
- arc_resampler = Resampler( depth=4, dim=1280, dim_head=64, embedding_dim=512, ff_mult=4, heads=20, num_queries=16, output_dim=2048 if lynx_lite else 5120 )
- offload.load_model_data(arc_resampler, os.path.join("ckpts", "wan2.1_lynx_lite_arc_resampler.safetensors" if lynx_lite else "wan2.1_lynx_full_arc_resampler.safetensors"))
- arc_resampler.to(self.device)
- arcface_embed = face_arc_embeds[None,None,:].to(device=self.device, dtype=torch.float)
- ip_hidden_states = arc_resampler(arcface_embed).to(self.dtype)
- ip_hidden_states_uncond = arc_resampler(torch.zeros_like(arcface_embed)).to(self.dtype)
- arc_resampler = None
- if not lynx_lite:
- standin_ref_pos = -1
- image_ref = original_input_ref_images[standin_ref_pos]
- from preprocessing.face_preprocessor import FaceProcessor
- face_processor = FaceProcessor()
- lynx_ref = face_processor.process(image_ref, resize_to = 256 )
- lynx_ref_buffer, lynx_ref_buffer_uncond = self.encode_reference_images([lynx_ref], tile_size=VAE_tile_size, any_guidance= any_guidance_at_all)
- lynx_ref = None
- gc.collect()
- torch.cuda.empty_cache()
- vace_lynx = model_type in ["vace_lynx_14B"]
- kwargs["lynx_ip_scale"] = control_scale_alt
- kwargs["lynx_ref_scale"] = control_scale_alt
-
- #Standin
- if standin:
- from preprocessing.face_preprocessor import FaceProcessor
- standin_ref_pos = 1 if "K" in video_prompt_type else 0
- if len(original_input_ref_images) < standin_ref_pos + 1:
- if "I" in video_prompt_type and model_type in ["vace_standin_14B"]:
- print("Warning: Missing Standin ref image, make sure 'Inject only People / Objets' is selected or if there is 'Landscape and then People or Objects' there are at least two ref images.")
- else:
- standin_ref_pos = -1
- image_ref = original_input_ref_images[standin_ref_pos]
- face_processor = FaceProcessor()
- standin_ref = face_processor.process(image_ref, remove_bg = model_type in ["vace_standin_14B"])
- face_processor = None
- gc.collect()
- torch.cuda.empty_cache()
- standin_freqs = get_nd_rotary_pos_embed((-1, int(target_shape[-2]/2), int(target_shape[-1]/2) ), (-1, int(target_shape[-2]/2 + standin_ref.height/16), int(target_shape[-1]/2 + standin_ref.width/16) ))
- standin_ref = self.vae.encode([ convert_image_to_tensor(standin_ref).unsqueeze(1) ], VAE_tile_size)[0].unsqueeze(0)
- kwargs.update({ "standin_freqs": standin_freqs, "standin_ref": standin_ref, })
-
# Steps Skipping
skip_steps_cache = self.model.cache
diff --git a/models/wan/modules/model.py b/models/wan/modules/model.py
index 6c223c8..2185b9c 100644
--- a/models/wan/modules/model.py
+++ b/models/wan/modules/model.py
@@ -97,6 +97,26 @@ def relative_l1_distance(last_tensor, current_tensor):
relative_l1_distance = l1_distance / norm
return relative_l1_distance.to(torch.float32)
+def trim_image_ref(y, ref_images_count, grid_sizes):
+ y_shape = y.shape
+ y = y.reshape(y_shape[0], grid_sizes[0], -1)
+ y = y[:, ref_images_count:]
+ y = y.reshape(y_shape[0], -1, y_shape[-1])
+ grid_sizes_alt = [grid_sizes[0]-ref_images_count, *grid_sizes[1:]]
+ return y, grid_sizes_alt
+
+def fuse_with_image_ref(x, y, ref_images_count, grid_sizes, alpha = 1):
+ y_shape = x.shape
+ y = y.reshape(y_shape[0], grid_sizes[0]-ref_images_count, -1)
+ x = x.reshape(y_shape[0], grid_sizes[0], -1)
+ if alpha == 1:
+ x[:, ref_images_count:] += y
+ else:
+ x[:, ref_images_count:].add_(y, alpha= alpha)
+
+ x = x.reshape(*y_shape)
+ return x
+
class LoRALinearLayer(nn.Module):
def __init__(
self,
@@ -295,6 +315,8 @@ class WanSelfAttention(nn.Module):
if not lynx_ref_buffer is None:
lynx_ref_features = lynx_ref_buffer[self.block_no]
if self.norm_q is not None: ref_query = self.norm_q(q, in_place = False)
+ if ref_images_count > 0:
+ ref_query, _ = trim_image_ref(ref_query, ref_images_count, grid_sizes)
ref_key = self.to_k_ref(lynx_ref_features)
ref_value = self.to_v_ref(lynx_ref_features)
if self.norm_k is not None: ref_key = self.norm_k(ref_key)
@@ -365,7 +387,11 @@ class WanSelfAttention(nn.Module):
del q,k,v
if ref_hidden_states is not None:
- x.add_(ref_hidden_states, alpha= lynx_ref_scale)
+
+ if ref_images_count > 0:
+ x = fuse_with_image_ref(x, ref_hidden_states, ref_images_count, grid_sizes, alpha = lynx_ref_scale)
+ else:
+ x.add_(ref_hidden_states, alpha= lynx_ref_scale)
x = x.flatten(2)
x = self.o(x)
@@ -631,18 +657,11 @@ class WanAttentionBlock(nn.Module):
del y
x += self.audio_cross_attn(ylist, encoder_hidden_states=multitalk_audio, shape=grid_sizes, x_ref_attn_map=x_ref_attn_map)
else:
- y_shape = y.shape
- y = y.reshape(y_shape[0], grid_sizes[0], -1)
- y = y[:, ref_images_count:]
- y = y.reshape(y_shape[0], -1, y_shape[-1])
- grid_sizes_alt = [grid_sizes[0]-ref_images_count, *grid_sizes[1:]]
+ y, grid_sizes_alt = trim_image_ref(y, ref_images_count, grid_sizes)
ylist= [y]
y = None
y = self.audio_cross_attn(ylist, encoder_hidden_states=multitalk_audio, shape=grid_sizes_alt, x_ref_attn_map=x_ref_attn_map)
- y = y.reshape(y_shape[0], grid_sizes[0]-ref_images_count, -1)
- x = x.reshape(y_shape[0], grid_sizes[0], -1)
- x[:, ref_images_count:] += y
- x = x.reshape(y_shape[0], -1, y_shape[-1])
+ x = fuse_with_image_ref(x, y, ref_images_count, grid_sizes)
del y
y = self.norm2(x)
diff --git a/models/wan/wan_handler.py b/models/wan/wan_handler.py
index c8f845d..060398c 100644
--- a/models/wan/wan_handler.py
+++ b/models/wan/wan_handler.py
@@ -254,9 +254,13 @@ class family_handler():
if base_model_type in ["vace_lynx_14B"]:
extra_model_def["set_video_prompt_type"]="Q"
extra_model_def["control_net_weight_alt_name"] = "Lynx"
- extra_model_def["image_ref_choices"] = { "choices": [("None", ""),("Person Face", "I")], "letters_filter": "I"}
- extra_model_def["no_background_removal"] = True
- extra_model_def["fit_into_canvas_image_refs"] = 0
+ extra_model_def["image_ref_choices"]["choices"] = [("None", ""),
+ ("People / Objects", "I"),
+ ("Landscape followed by People / Objects (if any)", "KI"),
+ ("Positioned Frames followed by People / Objects (if any)", "FI"),
+ ]
+ extra_model_def["background_removal_label"]= "Remove Backgrounds behind People / Objects, keep it for Landscape, Lynx Face or Positioned Frames"
+ extra_model_def["no_processing_on_last_images_refs"] = 1
@@ -617,9 +621,9 @@ class family_handler():
inputs["video_prompt_type"] = video_prompt_type
- if base_model_type in ["vace_standin_14B"]:
+ if base_model_type in ["vace_standin_14B", "vace_lynx_14B"]:
image_refs = inputs["image_refs"]
video_prompt_type = inputs["video_prompt_type"]
- if image_refs is not None and len(image_refs) == 1 and "K" in video_prompt_type:
- gr.Info("Warning, Ref Image for Standin Missing: if 'Landscape and then People or Objects' is selected beside the Landscape Image Ref there should be another Image Ref that contains a Face.")
+ if image_refs is not None and len(image_refs) == 1 and "K" in video_prompt_type:
+ gr.Info("Warning, Ref Image that contains the Face to transfer is Missing: if 'Landscape and then People or Objects' is selected beside the Landscape Image Ref there should be another Image Ref that contains a Face.")
diff --git a/shared/utils/utils.py b/shared/utils/utils.py
index a03927e..77e4410 100644
--- a/shared/utils/utils.py
+++ b/shared/utils/utils.py
@@ -273,13 +273,13 @@ def calculate_dimensions_and_resize_image(image, canvas_height, canvas_width, fi
image = image.resize((new_width, new_height), resample=Image.Resampling.LANCZOS)
return image, new_height, new_width
-def resize_and_remove_background(img_list, budget_width, budget_height, rm_background, any_background_ref, fit_into_canvas = 0, block_size= 16, outpainting_dims = None, background_ref_outpainted = True, inpaint_color = 127.5, return_tensor = False ):
+def resize_and_remove_background(img_list, budget_width, budget_height, rm_background, any_background_ref, fit_into_canvas = 0, block_size= 16, outpainting_dims = None, background_ref_outpainted = True, inpaint_color = 127.5, return_tensor = False, ignore_last_refs = 0 ):
if rm_background:
session = new_session()
output_list =[]
output_mask_list =[]
- for i, img in enumerate(img_list):
+ for i, img in enumerate(img_list if ignore_last_refs == 0 else img_list[:-ignore_last_refs]):
width, height = img.size
resized_mask = None
if any_background_ref == 1 and i==0 or any_background_ref == 2:
@@ -312,6 +312,11 @@ def resize_and_remove_background(img_list, budget_width, budget_height, rm_backg
else:
output_list.append(resized_image)
output_mask_list.append(resized_mask)
+ if ignore_last_refs:
+ for img in img_list[-ignore_last_refs:]:
+ output_list.append(convert_image_to_tensor(img).unsqueeze(1) if return_tensor else img)
+ output_mask_list.append(None)
+
return output_list, output_mask_list
def fit_image_into_canvas(ref_img, image_size, canvas_tf_bg =127.5, device ="cpu", full_frame = False, outpainting_dims = None, return_mask = False, return_image = False):
diff --git a/wgp.py b/wgp.py
index 5bf0558..9dc14b8 100644
--- a/wgp.py
+++ b/wgp.py
@@ -5136,7 +5136,8 @@ def generate_video(
block_size=block_size,
outpainting_dims =outpainting_dims,
background_ref_outpainted = model_def.get("background_ref_outpainted", True),
- return_tensor= model_def.get("return_image_refs_tensor", False) )
+ return_tensor= model_def.get("return_image_refs_tensor", False),
+ ignore_last_refs =model_def.get("no_processing_on_last_images_refs",0))
frames_to_inject_parsed = frames_to_inject[ window_start_frame if extract_guide_from_window_start else guide_start_frame: guide_end_frame]
if video_guide is not None or len(frames_to_inject_parsed) > 0 or model_def.get("forced_guide_mask_inputs", False):