Skip to content
Python

added flux kein base modesl

DeepBeepMeep672a995c6a12
diff --git a/README.md b/README.md
index ed4f059..347e5dc 100644
--- a/README.md
+++ b/README.md
@@ -33,6 +33,24 @@ WanGP supports the Wan (and derived models) but also Hunyuan Video, Flux, Qwen,
## 🔥 Latest Updates :
+### February 1st 2026: WanGP v10.60, Upgrade Time !
+
+- **LTX 2 Base Tweaks**: new *Quality* features if you found the base model was too fast :
+ - New *Modality Guidance* should improve audio / video (lipsync...) according to *LTX2 team* (beware first *denoising phase* will be 50% slower when used that is if modality guidance> 1)
+ - *CFG star*, *Adaptive Project Guidance* should improve quality and better prompt adherence
+ - *Skip Layer Guidance*: skipping layer 29 during phase may or may not improve quality
+Note that these features are only triggered during first phase of denoising because second phase is distilled denoising no matter what (even on the non distilled model)
+
+
+- **Flux Klein 4B & 9B Base Models**: *Z Image* has its *base model* in WanGP, so it was fair that *Flux Klein* would have its base model too. Base Models require more steps (up 50) and guidance > 1 but are good starting points for finetunes
+
+The real novelty about this new release is that is has been tested and tuned to work with more recent versions of *Python, Pytorch & Cuda*.
+My end goal is to have everbody upgrade to **Python 3.11, Pytorch 2.10, Cuda 13/13.1**.
+Once we are all there it will be much easier to provide precompiled kernels for *Nunchaku* *NVPF4*, *Sage Attention*, *Flash Attention*, ...
+So please follow the *manual upgrade instructions below* (no Pinokio auto upgrade for the moment) and let me know on Discord if it works with all generations of GPUs (starting from RTX10xx to RTX50xx).
+You will find the kernels for this new setup in the **guides/INSTALLATION.md**.
+
+**Note that PyTorch 2.10 represents at last a decent upgrade, no memory leak when switching models (pytorch 2.8) and bad perfs / VRAM peaks with VAE decoding (pytorch 2.9).**
### January 29th 2026: WanGP v10.56, Music for your Hearts
@@ -176,7 +194,7 @@ Get started instantly with [Pinokio App](https://pinokio.computer/)\
It is recommended to use in Pinokio the Community Scripts *wan2gp* or *wan2gp-amd* by **Morpheus** rather than the official Pinokio install.
-**Manual installation:**
+**Manual installation: (old python 3.10, to be deprecated)**
```bash
git clone https://github.com/deepbeepmeep/Wan2GP.git
cd Wan2GP
@@ -186,6 +204,16 @@ pip install torch==2.7.1 torchvision torchaudio --index-url https://download.pyt
pip install -r requirements.txt
```
+**Manual installation: (new python 3.11 setup)**
+```bash
+git clone https://github.com/deepbeepmeep/Wan2GP.git
+cd Wan2GP
+conda create -n wan2gp python=3.11.9
+conda activate wan2gp
+pip install torch==2.10.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu130
+pip install -r requirements.txt
+```
+
**Run the application:**
```bash
python wgp.py
@@ -193,7 +221,7 @@ python wgp.py
First time using WanGP ? Just check the *Guides* tab, and you will find a selection of recommended models to use.
-**Update the application:**
+**Update the application (stay in the old pyton / pytorch version):**
If using Pinokio use Pinokio to update otherwise:
Get in the directory where WanGP is installed and:
```bash
@@ -202,6 +230,17 @@ conda activate wan2gp
pip install -r requirements.txt
```
+**Update the application (upgrade from python 3.10 to 3.11):**
+Get in the directory where WanGP is installed and:
+```bash
+git pull
+conda uninstall -n wan2gp --all ### this will delete the old cuda environment but you could decide it too keep it and create a new conda env with a new name and switch between them
+conda create -n wan2gp python=3.11.9
+conda activate wan2gp
+pip install torch==2.10.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu130
+pip install -r requirements.txt
+```
+
if you get some error messages related to git, you may try the following (beware this will overwrite local changes made to the source code of WanGP):
```bash
git fetch origin && git reset --hard origin/main
diff --git a/defaults/flux2_klein_4b.json b/defaults/flux2_klein_4b.json
index 55d38aa..206bf81 100644
--- a/defaults/flux2_klein_4b.json
+++ b/defaults/flux2_klein_4b.json
@@ -2,7 +2,7 @@
"model": {
"name": "Flux 2 Klein 4B",
"architecture": "flux2_klein_4b",
- "description": "FLUX.2 Klein 4B is a compact rectified flow transformer for image generation and editing.",
+ "description": "FLUX.2 Klein 4B is a balanced rectified flow transformer for image generation and editing. This version is Cfg & Steps Distilled for very fast generations.",
"URLs": [
"https://huggingface.co/DeepBeepMeep/Flux2/resolve/main/flux-2-klein-4b.safetensors",
"https://huggingface.co/DeepBeepMeep/Flux2/resolve/main/flux-2-klein-4b_quanto_bf16_int8.safetensors"
diff --git a/defaults/flux2_klein_9b.json b/defaults/flux2_klein_9b.json
index 4295d95..7e0f565 100644
--- a/defaults/flux2_klein_9b.json
+++ b/defaults/flux2_klein_9b.json
@@ -2,7 +2,7 @@
"model": {
"name": "Flux 2 Klein 9B",
"architecture": "flux2_klein_9b",
- "description": "FLUX.2 Klein 9B is a balanced rectified flow transformer for image generation and editing.",
+ "description": "FLUX.2 Klein 9B is a balanced rectified flow transformer for image generation and editing. This version is Cfg & Steps Distilled for very fast generations.",
"URLs": [
"https://huggingface.co/DeepBeepMeep/Flux2/resolve/main/flux-2-klein-9b.safetensors",
"https://huggingface.co/DeepBeepMeep/Flux2/resolve/main/flux-2-klein-9b_quanto_bf16_int8.safetensors"
@@ -10,7 +10,5 @@
},
"prompt": "a glass greenhouse filled with lush tropical plants, misty air, and dappled light",
"resolution": "1024x1024",
- "batch_size": 1,
- "embedded_guidance_scale": 1,
"num_inference_steps": 4
}
diff --git a/defaults/flux2_klein_base_4b.json b/defaults/flux2_klein_base_4b.json
new file mode 100644
index 0000000..10bf62a
--- /dev/null
+++ b/defaults/flux2_klein_base_4b.json
@@ -0,0 +1,16 @@
+{
+ "model": {
+ "name": "Flux 2 Klein Base 4B",
+ "architecture": "flux2_klein_4b",
+ "description": "FLUX.2 Klein 4B is a balanced rectified flow transformer for image generation and editing. This non distilled version is slower but should produce more diverse images. ",
+ "URLs": [
+ "https://huggingface.co/DeepBeepMeep/Flux2/resolve/main/flux-2-klein-base-4b.safetensors",
+ "https://huggingface.co/DeepBeepMeep/Flux2/resolve/main/flux-2-klein-base-4b_quanto_bf16_int8.safetensors"
+ ],
+ "guidance_max_phases": 1
+ },
+ "prompt": "a glass greenhouse filled with lush tropical plants, misty air, and dappled light",
+ "resolution": "1024x1024",
+ "guidance_scale": 4,
+ "num_inference_steps": 30
+}
\ No newline at end of file
diff --git a/defaults/flux2_klein_base_9b.json b/defaults/flux2_klein_base_9b.json
new file mode 100644
index 0000000..3fa8db5
--- /dev/null
+++ b/defaults/flux2_klein_base_9b.json
@@ -0,0 +1,16 @@
+{
+ "model": {
+ "name": "Flux 2 Klein Base 9B",
+ "architecture": "flux2_klein_9b",
+ "description": "FLUX.2 Klein 9B is a balanced rectified flow transformer for image generation and editing. This non distilled version is slower but should produce more diverse images. ",
+ "URLs": [
+ "https://huggingface.co/DeepBeepMeep/Flux2/resolve/main/flux-2-klein-base-9b.safetensors",
+ "https://huggingface.co/DeepBeepMeep/Flux2/resolve/main/flux-2-klein-base-9b_quanto_bf16_int8.safetensors"
+ ],
+ "guidance_max_phases": 1
+ },
+ "prompt": "a glass greenhouse filled with lush tropical plants, misty air, and dappled light",
+ "resolution": "1024x1024",
+ "guidance_scale": 4,
+ "num_inference_steps": 30
+}
\ No newline at end of file
diff --git a/docs/INSTALLATION.md b/docs/INSTALLATION.md
index 09e1e33..db426cb 100644
--- a/docs/INSTALLATION.md
+++ b/docs/INSTALLATION.md
@@ -22,9 +22,9 @@ This guide covers installation for different GPU generations and operating syste
This installation uses PyTorch 2.6.0, Cuda 12.6 for GTX 10XX - RTX 30XX & PyTorch 2.7.1, Cuda 12.8 for RTX 40XX - 50XX which are well-tested and stable.
-Unless you need absolutely to use Pytorch compilation (with RTX 50xx), it is not recommeneded to use PytTorch 2.8.0 as some System RAM memory leaks have been observed when switching models.
+It is not recommeneded to use neither PytTorch 2.8.0 as some System RAM memory leaks have been observed when switching models nor 2.9.0 which has some Convolution 3D perf issues (VAE VRAM requirements explode)
-If you want to use the NV FP4 optimized kernels for RTX 50xx, you will need PyTorch 2.9.1 with Cuda 13.0
+If you want to use the NV FP4 optimized kernels for RTX 50xx, you will need to upgrade to Python 3.11, PyTorch 2.10 with Cuda 13.0
## Download Repo and Setup Conda Environment
@@ -127,15 +127,18 @@ pip install https://github.com/woct0rdho/SageAttention/releases/download/v2.2.0-
pip install -r requirements.txt
```
-## Installation for 50XX Only PyTorch 2.9.1 Cuda 13.. for NVFP4 optimized kernels
-
-#### Windows Install PyTorch 2.9.1 with CUDA 13.0 for RTX 50XX Only
+## Installation for 50XX Only Python 3.11, PyTorch 2.10.0 Cuda 13. for NVFP4 optimized kernels
+#### Create Python 3.11 environment using Conda
+```
+conda create -n wan2gp python=3.11.9
+```
+#### Windows Install PyTorch 2.10.0 with CUDA 13.0 for RTX 50XX Only
```
-pip install torch==2.9.1 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu130
+pip install torch==2.10.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu130
```
#### Windows Install Triton for RTX 50XX Only
```
-pip install -U "triton-windows<3.4"
+pip install -U triton-windows
```
#### Windows Install Sage2 Attention for RTX 50XX Only
```
@@ -318,34 +321,37 @@ These kernels will offer optimized INT4 / FP4 dequantization.
**Please Note FP4 support is hardware dependent and will work only with RTX 50xx / sm120+ GPUs**
-### Light2xv NVP4 Kernels Wheels for Windows / Python 3.10 / Pytorch 2.9.1 / Cuda 13.8 (RTX 50xx / sm120+ only !)
+### Light2xv NVP4 Kernels Wheels for Python 3.11 / Pytorch 2.10 / Cuda 13 (RTX 50xx / sm120+ only !)
- Windows
```
- pip install https://github.com/deepbeepmeep/kernels/releases/download/Light2xv/lightx2v_kernel-0.0.1+torch2.9.1-cp39-abi3-win_amd64.whl
+ pip install https://github.com/deepbeepmeep/kernels/releases/download/Light2xv/lightx2v_kernel-0.0.2+torch2.10.0-cp311-abi3-win_amd64.whl
```
- Linux
```
- pip install https://github.com/deepbeepmeep/kernels/releases/download/Light2xv/lightx2v_kernel-0.0.1+torch2.9.1cu130-cp39-abi3-linux_x86_64.whl
+ pip install https://github.com/deepbeepmeep/kernels/releases/download/Light2xv/lightx2v_kernel-0.0.2+torch2.10.0-cp311-abi3-linux_x86_64.whl
```
-### Nunchaku INT4/FP4 Kernels Wheels for Python 3.10
-- Windows (Pytorch 2.7.1 / Cuda 12.8)
+### Nunchaku INT4/FP4 Kernels Wheels for Python 3.10 / Pytorch 2.7.1 / Cuda 12.8
+- Windows ()
```
pip install https://github.com/deepbeepmeep/kernels/releases/download/v1.2.0_Nunchaku/nunchaku-1.2.0+torch2.7-cp310-cp310-win_amd64.whl
```
-- Windows (Pytorch 2.9.1 / Cuda 13)
+- Linux (Pytorch 2.7.1 / Cuda 12.8)
```
- pip install https://github.com/deepbeepmeep/kernels/releases/download/v1.2.0_Nunchaku/nunchaku-1.2.0+torch2.9-cp310-cp310-win_amd64.whl
+ pip install https://github.com/deepbeepmeep/kernels/releases/download/v1.2.0_Nunchaku/nunchaku-1.2.0+torch2.7-cp310-cp310-linux_x86_64.whl
```
-- Linux (Pytorch 2.7.1 / Cuda 12.8)
+### Nunchaku INT4/FP4 Kernels Wheels for Python 3.11 / Pytorch 2.10 / Cuda 13
+
+- Windows
```
- pip install https://github.com/deepbeepmeep/kernels/releases/download/v1.2.0_Nunchaku/nunchaku-1.2.0+torch2.7-cp310-cp310-linux_x86_64.whl
+ pip install https://github.com/nunchaku-ai/nunchaku/releases/download/v1.2.1/nunchaku-1.2.1+cu13.0torch2.10-cp311-cp311-win_amd64.whl
```
-- Linux (Pytorch 2.9.1 / Cuda 13)
+
+- Linux
```
- pip install https://github.com/deepbeepmeep/kernels/releases/download/v1.2.0_Nunchaku/nunchaku-1.2.0+torch2.9-cp310-cp310-linux_x86_64.whl
+ pip install https://github.com/nunchaku-ai/nunchaku/releases/download/v1.2.1/nunchaku-1.2.1+cu13.0torch2.10-cp310-cp310-linux_x86_64.whl
```
\ No newline at end of file
diff --git a/models/flux/flux_handler.py b/models/flux/flux_handler.py
index 25d4ac9..272e796 100644
--- a/models/flux/flux_handler.py
+++ b/models/flux/flux_handler.py
@@ -85,19 +85,9 @@ class family_handler():
"flux-model": flux_model,
"flux2": flux2,
}
- nag_supported = base_model_type in [
- "flux_schnell",
- "flux_dev_kontext",
- "flux_dev_umo",
- "flux_dev_uso",
- "flux_dev_kontext_dreamomni2",
- "pi_flux2",
- "flux2_dev",
- "flux",
- "flux2_klein_4b",
- "flux2_klein_9b",
- ]
- if nag_supported:
+ if flux_chroma or flux_chroma_radiance:
+ extra_model_def["guidance_max_phases"] = 1
+ else:
extra_model_def["NAG"] = True
extra_model_def["no_negative_prompt"] = False
supports_inpaint = flux_kontext or flux_schnell or flux_dev or flux2
@@ -164,8 +154,6 @@ class family_handler():
extra_model_def["profiles_dir"] = ["flux2_klein_4b"] if flux2_klein_4b else ["flux2_klein_9b"]
else:
extra_model_def["profiles_dir"] = [] if (flux_schnell or flux2) else ["flux"]
- if flux_chroma or flux_chroma_radiance:
- extra_model_def["guidance_max_phases"] = 1
if flux_chroma_radiance:
extra_model_def["radiance"] = True
elif not flux_schnell and not flux2_klein:
diff --git a/models/flux/flux_main.py b/models/flux/flux_main.py
index 7f632a4..062bfc9 100644
--- a/models/flux/flux_main.py
+++ b/models/flux/flux_main.py
@@ -282,8 +282,6 @@ class model_factory:
except (TypeError, ValueError):
model_mode_int = None
lanpaint_enabled = model_mode_int in (2, 3, 4, 5)
- if flux2:
- guide_scale = 1.0
if self.guidance_max_phases < 1: guide_scale = 1
if n_prompt is None or len(n_prompt) == 0: n_prompt = "low quality, ugly, unfinished, out of focus, deformed, disfigure, blurry, smudged, restricted palette, flat colors"
nag_scale = bbargs.get("NAG_scale", 1.0)
diff --git a/models/ltx2/ltx2.py b/models/ltx2/ltx2.py
index 9c3c0ad..af7b24f 100644
--- a/models/ltx2/ltx2.py
+++ b/models/ltx2/ltx2.py
@@ -644,6 +644,7 @@ class LTX2:
image_end=None,
sampling_steps: int = 40,
guide_scale: float = 4.0,
+ alt_guide_scale: float = 1.0,
frame_num: int = 121,
height: int = 1024,
width: int = 1536,
@@ -670,6 +671,12 @@ class LTX2:
return_latent_slice = kwargs.get("return_latent_slice")
video_prompt_type = kwargs.get("video_prompt_type") or ""
denoising_strength = kwargs.get("denoising_strength")
+ cfg_star_switch = kwargs.get("cfg_star_switch", 0)
+ apg_switch = kwargs.get("apg_switch", 0)
+ slg_switch = kwargs.get("slg_switch", 0)
+ slg_layers = kwargs.get("slg_layers")
+ slg_start = kwargs.get("slg_start", 0.0)
+ slg_end = kwargs.get("slg_end", 1.0)
def _get_frame_dim(video_tensor: torch.Tensor) -> int | None:
if video_tensor.dim() < 2:
@@ -947,6 +954,13 @@ class LTX2:
frame_rate=float(fps),
num_inference_steps=int(sampling_steps),
cfg_guidance_scale=float(guide_scale),
+ cfg_star_switch=cfg_star_switch,
+ apg_switch=apg_switch,
+ slg_switch=slg_switch,
+ slg_layers=slg_layers,
+ slg_start=slg_start,
+ slg_end=slg_end,
+ alt_guidance_scale=float(alt_guide_scale),
images=images,
guiding_images=guiding_images or None,
images_stage2=images_stage2 if stage2_override else None,
@@ -972,6 +986,7 @@ class LTX2:
num_frames=int(frame_num),
frame_rate=float(fps),
images=images,
+ alt_guidance_scale=float(alt_guide_scale),
video_conditioning=video_conditioning,
latent_conditioning_stage2=latent_conditioning_stage2,
tiling_config=tiling_config,
diff --git a/models/ltx2/ltx2_handler.py b/models/ltx2/ltx2_handler.py
index 3130a4c..96458e8 100644
--- a/models/ltx2/ltx2_handler.py
+++ b/models/ltx2/ltx2_handler.py
@@ -127,6 +127,15 @@ class family_handler:
"no_negative_prompt": True,
}
)
+ else:
+ extra_model_def.update(
+ {
+ "adaptive_projected_guidance": True,
+ "cfg_star": True,
+ "skip_layer_guidance": True,
+ "alt_guidance": "Modality Guidance",
+ }
+ )
extra_model_def["guidance_max_phases"] = 2
extra_model_def["visible_phases"] = 0 if distilled else 1
extra_model_def["lock_guidance_phases"] = True
@@ -265,6 +274,15 @@ class family_handler:
}
)
+ if settings_version < 2.45:
+ ui_defaults.update(
+ {
+ "alt_guidance_scale": 1.0,
+ "slg_layers": [29],
+ }
+ )
+
+
@staticmethod
def update_default_settings(base_model_type, model_def, ui_defaults):
ui_defaults.update(
@@ -274,9 +292,12 @@ class family_handler:
"denoising_strength": 1.0,
"masking_strength": 0,
"audio_prompt_type": "",
- }
+ "alt_guidance_scale": 1.0,
+ "slg_layers": [29],
+ }
)
ui_defaults.setdefault("audio_scale", 1.0)
+ ui_defaults.setdefault("alt_guidance_scale", 1.0)
pipeline_kind = model_def.get("ltx2_pipeline", "two_stage")
if pipeline_kind != "distilled":
ui_defaults.setdefault("guidance_phases", 2)
diff --git a/models/ltx2/ltx_core/model/transformer/model.py b/models/ltx2/ltx_core/model/transformer/model.py
index f60e0ef..708a6ca 100644
--- a/models/ltx2/ltx_core/model/transformer/model.py
+++ b/models/ltx2/ltx_core/model/transformer/model.py
@@ -359,19 +359,25 @@ class LTXModel(torch.nn.Module):
self,
video_list: list[TransformerArgs | None],
audio_list: list[TransformerArgs | None],
- perturbations: BatchedPerturbationConfig,
+ perturbations: BatchedPerturbationConfig | list[BatchedPerturbationConfig] | None,
) -> tuple[list[TransformerArgs | None], list[TransformerArgs | None]]:
"""Process transformer blocks for joint-pass CFG."""
+ perturbations_list = perturbations if isinstance(perturbations, list) else None
+ if perturbations_list is not None and len(perturbations_list) != len(video_list):
+ raise ValueError("Perturbations list must match number of joint-pass conditions.")
for block in self.transformer_blocks:
if self.interrupt_check is not None and self.interrupt_check():
self.interrupted = True
return [None] * len(video_list), [None] * len(audio_list)
for idx in range(len(video_list)):
+ condition_perturbations = (
+ perturbations_list[idx] if perturbations_list is not None else perturbations
+ )
video_list[idx], audio_list[idx] = block(
video=video_list[idx],
audio=audio_list[idx],
- perturbations=perturbations,
+ perturbations=condition_perturbations,
)
return video_list, audio_list
@@ -400,7 +406,7 @@ class LTXModel(torch.nn.Module):
self,
video: Modality | list[Modality] | None,
audio: Modality | list[Modality] | None,
- perturbations: BatchedPerturbationConfig,
+ perturbations: BatchedPerturbationConfig | list[BatchedPerturbationConfig] | None,
) -> tuple[torch.Tensor | None | list[torch.Tensor | None], torch.Tensor | None | list[torch.Tensor | None]]:
"""
Forward pass for LTX models.
@@ -419,6 +425,8 @@ class LTXModel(torch.nn.Module):
audio_list = list(audio) if isinstance(audio, (list, tuple)) else [None] * len(video)
if len(video_list) != len(audio_list):
raise ValueError("Joint-pass inputs must have the same number of video and audio entries.")
+ if isinstance(perturbations, list) and len(perturbations) != len(video_list):
+ raise ValueError("Perturbations list must match number of joint-pass conditions.")
if self.model_type.is_video_enabled():
video_args_list = [
@@ -462,6 +470,11 @@ class LTXModel(torch.nn.Module):
]
return vx_list, ax_list
+ if isinstance(perturbations, list):
+ if len(perturbations) != 1:
+ raise ValueError("Non-joint pass expects at most one perturbation config.")
+ perturbations = perturbations[0]
+
video_args = self.video_args_preprocessor.prepare(video) if video is not None else None
audio_args = self.audio_args_preprocessor.prepare(audio) if audio is not None else None
video_out, audio_out = self._process_transformer_blocks(
@@ -507,7 +520,7 @@ class LegacyX0Model(torch.nn.Module):
self,
video: Modality | list[Modality] | None,
audio: Modality | list[Modality] | None,
- perturbations: BatchedPerturbationConfig,
+ perturbations: BatchedPerturbationConfig | list[BatchedPerturbationConfig] | None,
sigma: float,
) -> tuple[torch.Tensor | None | list[torch.Tensor | None], torch.Tensor | None | list[torch.Tensor | None]]:
"""
@@ -551,7 +564,7 @@ class X0Model(torch.nn.Module):
self,
video: Modality | list[Modality] | None,
audio: Modality | list[Modality] | None,
- perturbations: BatchedPerturbationConfig,
+ perturbations: BatchedPerturbationConfig | list[BatchedPerturbationConfig] | None,
) -> tuple[torch.Tensor | None | list[torch.Tensor | None], torch.Tensor | None | list[torch.Tensor | None]]:
"""
Denoise the video and audio according to the sigma.
diff --git a/models/ltx2/ltx_pipelines/distilled.py b/models/ltx2/ltx_pipelines/distilled.py
index 7864625..2ef5ad7 100644
--- a/models/ltx2/ltx_pipelines/distilled.py
+++ b/models/ltx2/ltx_pipelines/distilled.py
@@ -102,6 +102,7 @@ class DistilledPipeline:
num_frames: int,
frame_rate: float,
images: list[tuple[str, int, float]],
+ alt_guidance_scale: float = 1.0,
video_conditioning: list[tuple[str, float]] | None = None,
latent_conditioning_stage2: torch.Tensor | None = None,
tiling_config: TilingConfig | None = None,
@@ -116,6 +117,7 @@ class DistilledPipeline:
return_latent_slice: slice | None = None,
) -> tuple[Iterator[torch.Tensor], torch.Tensor]:
assert_resolution(height=height, width=width, is_two_stage=True)
+ alt_guidance_scale = 1.0
generator = torch.Generator(device=self.device).manual_seed(seed)
mask_generator = torch.Generator(device=self.device).manual_seed(int(seed) + 1)
@@ -179,6 +181,7 @@ class DistilledPipeline:
video_context=video_context,
audio_context=audio_context,
transformer=transformer, # noqa: F821
+ alt_guidance_scale=alt_guidance_scale,
),
mask_context=mask_context,
interrupt_check=interrupt_check,
diff --git a/models/ltx2/ltx_pipelines/ic_lora.py b/models/ltx2/ltx_pipelines/ic_lora.py
index 56cf8fe..0272641 100644
--- a/models/ltx2/ltx_pipelines/ic_lora.py
+++ b/models/ltx2/ltx_pipelines/ic_lora.py
@@ -99,6 +99,7 @@ class ICLoraPipeline:
frame_rate: float,
images: list[tuple[str, int, float]],
video_conditioning: list[tuple[str, float]],
+ alt_guidance_scale: float = 1.0,
enhance_prompt: bool = False,
audio_conditionings: list | None = None,
tiling_config: TilingConfig | None = None,
@@ -110,6 +111,7 @@ class ICLoraPipeline:
masking_strength: float | None = None,
) -> tuple[Iterator[torch.Tensor], torch.Tensor]:
assert_resolution(height=height, width=width, is_two_stage=True)
+ alt_guidance_scale = 1.0
generator = torch.Generator(device=self.device).manual_seed(seed)
mask_generator = torch.Generator(device=self.device).manual_seed(int(seed) + 1)
@@ -179,6 +181,7 @@ class ICLoraPipeline:
video_context=video_context,
audio_context=audio_context,
transformer=transformer, # noqa: F821
+ alt_guidance_scale=alt_guidance_scale,
),
mask_context=mask_context,
interrupt_check=interrupt_check,
@@ -281,6 +284,7 @@ class ICLoraPipeline:
video_context=video_context,
audio_context=audio_context,
transformer=transformer, # noqa: F821
+ alt_guidance_scale=alt_guidance_scale,
),
mask_context=mask_context,
interrupt_check=interrupt_check,
diff --git a/models/ltx2/ltx_pipelines/keyframe_interpolation.py b/models/ltx2/ltx_pipelines/keyframe_interpolation.py
index d3129b1..f0118ea 100644
--- a/models/ltx2/ltx_pipelines/keyframe_interpolation.py
+++ b/models/ltx2/ltx_pipelines/keyframe_interpolation.py
@@ -4,7 +4,7 @@ from collections.abc import Callable, Iterator
import torch
from ..ltx_core.components.diffusion_steps import EulerDiffusionStep
-from ..ltx_core.components.guiders import CFGGuider
+from ..ltx_core.components.guiders import CFGGuider, CFGStarRescalingGuider, LtxAPGGuider
from ..ltx_core.components.noisers import GaussianNoiser
from ..ltx_core.components.protocols import DiffusionStepProtocol
from ..ltx_core.components.schedulers import LTX2Scheduler
@@ -94,6 +94,13 @@ class KeyframeInterpolationPipeline:
num_inference_steps: int,
cfg_guidance_scale: float,
images: list[tuple[str, int, float]],
+ cfg_star_switch: int = 0,
+ apg_switch: int = 0,
+ slg_switch: int = 0,
+ slg_layers: list[int] | None = None,
+ slg_start: float = 0.0,
+ slg_end: float = 1.0,
+ alt_guidance_scale: float = 1.0,
tiling_config: TilingConfig | None = None,
enhance_prompt: bool = False,
audio_conditionings: list | None = None,
@@ -110,7 +117,12 @@ class KeyframeInterpolationPipeline:
mask_generator = torch.Generator(device=self.device).manual_seed(int(seed) + 1)
noiser = GaussianNoiser(generator=generator)
stepper = EulerDiffusionStep()
- cfg_guider = CFGGuider(cfg_guidance_scale)
+ if apg_switch:
+ cfg_guider = LtxAPGGuider(cfg_guidance_scale)
+ elif cfg_star_switch:
+ cfg_guider = CFGStarRescalingGuider(cfg_guidance_scale)
+ else:
+ cfg_guider = CFGGuider(cfg_guidance_scale)
dtype = torch.bfloat16
text_encoder = self.stage_1_model_ledger.text_encoder()
@@ -179,6 +191,11 @@ class KeyframeInterpolationPipeline:
a_context_p,
a_context_n,
transformer=transformer, # noqa: F821
+ alt_guidance_scale=alt_guidance_scale,
+ slg_switch=slg_switch,
+ slg_layers=slg_layers,
+ slg_start=slg_start,
+ slg_end=slg_end,
),
mask_context=mask_context,
interrupt_check=interrupt_check,
@@ -281,6 +298,7 @@ class KeyframeInterpolationPipeline:
video_context=v_context_p,
audio_context=a_context_p,
transformer=transformer, # noqa: F821
+ alt_guidance_scale=1.0,
),
mask_context=mask_context,
interrupt_check=interrupt_check,
diff --git a/models/ltx2/ltx_pipelines/ti2vid_one_stage.py b/models/ltx2/ltx_pipelines/ti2vid_one_stage.py
index 6818569..1cd8622 100644
--- a/models/ltx2/ltx_pipelines/ti2vid_one_stage.py
+++ b/models/ltx2/ltx_pipelines/ti2vid_one_stage.py
@@ -4,7 +4,7 @@ from collections.abc import Callable, Iterator
import torch
from ..ltx_core.components.diffusion_steps import EulerDiffusionStep
-from ..ltx_core.components.guiders import CFGGuider
+from ..ltx_core.components.guiders import CFGGuider, CFGStarRescalingGuider, LtxAPGGuider
from ..ltx_core.components.noisers import GaussianNoiser
from ..ltx_core.components.protocols import DiffusionStepProtocol
from ..ltx_core.components.schedulers import LTX2Scheduler
@@ -81,6 +81,13 @@ class TI2VidOneStagePipeline:
num_inference_steps: int,
cfg_guidance_scale: float,
images: list[tuple[str, int, float]],
+ cfg_star_switch: int = 0,
+ apg_switch: int = 0,
+ slg_switch: int = 0,
+ slg_layers: list[int] | None = None,
+ slg_start: float = 0.0,
+ slg_end: float = 1.0,
+ alt_guidance_scale: float = 1.0,
enhance_prompt: bool = False,
audio_conditionings: list | None = None,
callback: Callable[..., None] | None = None,
@@ -96,7 +103,12 @@ class TI2VidOneStagePipeline:
mask_generator = torch.Generator(device=self.device).manual_seed(int(seed) + 1)
noiser = GaussianNoiser(generator=generator)
stepper = EulerDiffusionStep()
- cfg_guider = CFGGuider(cfg_guidance_scale)
+ if apg_switch:
+ cfg_guider = LtxAPGGuider(cfg_guidance_scale)
+ elif cfg_star_switch:
+ cfg_guider = CFGStarRescalingGuider(cfg_guidance_scale)
+ else:
+ cfg_guider = CFGGuider(cfg_guidance_scale)
dtype = torch.bfloat16
text_encoder = self.model_ledger.text_encoder()
@@ -165,6 +177,11 @@ class TI2VidOneStagePipeline:
a_context_p,
a_context_n,
transformer=transformer, # noqa: F821
+ alt_guidance_scale=alt_guidance_scale,
+ slg_switch=slg_switch,
+ slg_layers=slg_layers,
+ slg_start=slg_start,
+ slg_end=slg_end,
),
mask_context=mask_context,
interrupt_check=interrupt_check,
diff --git a/models/ltx2/ltx_pipelines/ti2vid_two_stages.py b/models/ltx2/ltx_pipelines/ti2vid_two_stages.py
index 44536fc..ea01f42 100644
--- a/models/ltx2/ltx_pipelines/ti2vid_two_stages.py
+++ b/models/ltx2/ltx_pipelines/ti2vid_two_stages.py
@@ -4,7 +4,7 @@ from collections.abc import Callable, Iterator
import torch
from ..ltx_core.components.diffusion_steps import EulerDiffusionStep
-from ..ltx_core.components.guiders import CFGGuider
+from ..ltx_core.components.guiders import CFGGuider, CFGStarRescalingGuider, LtxAPGGuider
from ..ltx_core.components.noisers import GaussianNoiser
from ..ltx_core.components.protocols import DiffusionStepProtocol
from ..ltx_core.components.schedulers import LTX2Scheduler
@@ -128,6 +128,13 @@ class TI2VidTwoStagesPipeline:
num_inference_steps: int,
cfg_guidance_scale: float,
images: list[tuple[str, int, float]],
+ cfg_star_switch: int = 0,
+ apg_switch: int = 0,
+ slg_switch: int = 0,
+ slg_layers: list[int] | None = None,
+ slg_start: float = 0.0,
+ slg_end: float = 1.0,
+ alt_guidance_scale: float = 1.0,
guiding_images: list[tuple[str, int, float]] | None = None,
images_stage2: list[tuple[str, int, float]] | None = None,
video_conditioning: list[tuple[str, float]] | None = None,
@@ -149,7 +156,12 @@ class TI2VidTwoStagesPipeline:
mask_generator = torch.Generator(device=self.device).manual_seed(int(seed) + 1)
noiser = GaussianNoiser(generator=generator)
stepper = EulerDiffusionStep()
- cfg_guider = CFGGuider(cfg_guidance_scale)
+ if apg_switch:
+ cfg_guider = LtxAPGGuider(cfg_guidance_scale)
+ elif cfg_star_switch:
+ cfg_guider = CFGStarRescalingGuider(cfg_guidance_scale)
+ else:
+ cfg_guider = CFGGuider(cfg_guidance_scale)
dtype = torch.bfloat16
text_encoder = self._get_stage_model(1, "text_encoder")
@@ -222,6 +234,11 @@ class TI2VidTwoStagesPipeline:
a_context_p,
a_context_n,
transformer=transformer, # noqa: F821
+ alt_guidance_scale=alt_guidance_scale,
+ slg_switch=slg_switch,
+ slg_layers=slg_layers,
+ slg_start=slg_start,
+ slg_end=slg_end,
),
mask_context=mask_context,
interrupt_check=interrupt_check,
@@ -345,6 +362,7 @@ class TI2VidTwoStagesPipeline:
video_context=v_context_p,
audio_context=a_context_p,
transformer=transformer, # noqa: F821
+ alt_guidance_scale=1.0,
),
mask_context=mask_context,
interrupt_check=interrupt_check,
diff --git a/models/ltx2/ltx_pipelines/utils/helpers.py b/models/ltx2/ltx_pipelines/utils/helpers.py
index 2e0d067..ee4b9ed 100644
--- a/models/ltx2/ltx_pipelines/utils/helpers.py
+++ b/models/ltx2/ltx_pipelines/utils/helpers.py
@@ -18,6 +18,12 @@ from ...ltx_core.conditioning import (
VideoConditionByKeyframeIndex,
VideoConditionByLatentIndex,
)
+from ...ltx_core.guidance.perturbations import (
+ BatchedPerturbationConfig,
+ Perturbation,
+ PerturbationConfig,
+ PerturbationType,
+)
from ...ltx_core.model.transformer import Modality, X0Model
from ...ltx_core.model.video_vae import VideoEncoder, TilingConfig, encode_video as vae_encode_video
from ...ltx_core.text_encoders.gemma import GemmaTextEncoderModelBase
@@ -659,6 +665,54 @@ def modality_from_latent_state(
)
+def _get_batch_size(video_state: LatentState | None, audio_state: LatentState | None) -> int:
+ if video_state is not None:
+ return int(video_state.latent.shape[0])
+ if audio_state is not None:
+ return int(audio_state.latent.shape[0])
+ return 1
+
+
+def _cross_attn_perturbations(batch_size: int) -> BatchedPerturbationConfig:
+ perts = [
+ PerturbationConfig(
+ [
+ Perturbation(PerturbationType.SKIP_A2V_CROSS_ATTN, None),
+ Perturbation(PerturbationType.SKIP_V2A_CROSS_ATTN, None),
+ ]
+ )
+ for _ in range(batch_size)
+ ]
+ return BatchedPerturbationConfig(perts)
+
+
+def _normalize_slg_layers(slg_layers) -> list[int] | None:
+ if slg_layers is None:
+ return None
+ if isinstance(slg_layers, (list, tuple)):
+ return [int(layer) for layer in slg_layers if str(layer).strip() != ""]
+ if isinstance(slg_layers, (int, float)):
+ return [int(slg_layers)]
+ if isinstance(slg_layers, str):
+ return [int(layer.strip()) for layer in slg_layers.split(",") if layer.strip()]
+ return None
+
+
+def _slg_perturbations(batch_size: int, slg_layers: list[int]) -> BatchedPerturbationConfig:
+ perts = [
+ PerturbationConfig(
+ [
+ Perturbation(PerturbationType.SKIP_VIDEO_SELF_ATTN, slg_layers),
+ Perturbation(PerturbationType.SKIP_AUDIO_SELF_ATTN, slg_layers),
+ Perturbation(PerturbationType.SKIP_A2V_CROSS_ATTN, slg_layers),
+ Perturbation(PerturbationType.SKIP_V2A_CROSS_ATTN, slg_layers),
+ ]
+ )
+ for _ in range(batch_size)
+ ]
+ return BatchedPerturbationConfig(perts)
+
+
def timesteps_from_mask(
denoise_mask: torch.Tensor, sigma: float | torch.Tensor, positions: torch.Tensor | None = None
) -> tuple[torch.Tensor, torch.Tensor | None]:
@@ -708,7 +762,10 @@ def timesteps_from_mask(
def simple_denoising_func(
- video_context: torch.Tensor, audio_context: torch.Tensor, transformer: X0Model
+ video_context: torch.Tensor,
+ audio_context: torch.Tensor,
+ transformer: X0Model,
+ alt_guidance_scale: float = 1.0,
) -> DenoisingFunc:
def simple_denoising_step(
video_state: LatentState, audio_state: LatentState, sigmas: torch.Tensor, step_index: int
@@ -719,9 +776,38 @@ def simple_denoising_func(
if transformer is not None:
offload.set_step_no_for_lora(transformer, step_index)
- denoised_video, denoised_audio = transformer(video=pos_video, audio=pos_audio, perturbations=None)
- if denoised_video is None and denoised_audio is None:
+ use_alt = not math.isclose(alt_guidance_scale, 1.0)
+ if not use_alt:
+ denoised_video, denoised_audio = transformer(video=pos_video, audio=pos_audio, perturbations=None)
+ if denoised_video is None and denoised_audio is None:
+ return None, None
+ return denoised_video, denoised_audio
+
+ alt_video = modality_from_latent_state(video_state, video_context, sigma)
+ alt_audio = modality_from_latent_state(audio_state, audio_context, sigma)
+ batch_size = _get_batch_size(video_state, audio_state)
+ perturbations = [None, _cross_attn_perturbations(batch_size)]
+ denoised_video_list, denoised_audio_list = transformer(
+ video=[pos_video, alt_video],
+ audio=[pos_audio, alt_audio],
+ perturbations=perturbations,
+ )
+ if denoised_video_list is None and denoised_audio_list is None:
return None, None
+ pos_denoised_video, alt_denoised_video = denoised_video_list
+ pos_denoised_audio, alt_denoised_audio = denoised_audio_list
+ if pos_denoised_video is None and pos_denoised_audio is None:
+ return None, None
+ denoised_video = pos_denoised_video
+ denoised_audio = pos_denoised_audio
+ if denoised_video is not None and alt_denoised_video is not None:
+ denoised_video = denoised_video + (alt_guidance_scale - 1.0) * (
+ pos_denoised_video - alt_denoised_video
+ )
+ if denoised_audio is not None and alt_denoised_audio is not None:
+ denoised_audio = denoised_audio + (alt_guidance_scale - 1.0) * (
+ pos_denoised_audio - alt_denoised_audio
+ )
return denoised_video, denoised_audio
return simple_denoising_step
@@ -734,6 +820,11 @@ def guider_denoising_func(
a_context_p: torch.Tensor,
a_context_n: torch.Tensor,
transformer: X0Model,
+ alt_guidance_scale: float = 1.0,
+ slg_switch: int = 0,
+ slg_layers: list[int] | None = None,
+ slg_start: float = 0.0,
+ slg_end: float = 1.0,
) -> DenoisingFunc:
def guider_denoising_step(
video_state: LatentState, audio_state: LatentState, sigmas: torch.Tensor, step_index: int
@@ -744,23 +835,72 @@ def guider_denoising_func(
if transformer is not None:
offload.set_step_no_for_lora(transformer, step_index)
- if guider.enabled():
- neg_video = modality_from_latent_state(video_state, v_context_n, sigma)
- neg_audio = modality_from_latent_state(audio_state, a_context_n, sigma)
+ use_cfg = guider.enabled()
+ use_alt = not math.isclose(alt_guidance_scale, 1.0)
+ if use_cfg or use_alt:
+ video_list = [pos_video]
+ audio_list = [pos_audio]
+ perturbations: list[BatchedPerturbationConfig | None] = [None]
+ neg_index = None
+ alt_index = None
+ if use_cfg:
+ neg_video = modality_from_latent_state(video_state, v_context_n, sigma)
+ neg_audio = modality_from_latent_state(audio_state, a_context_n, sigma)
+ neg_index = len(video_list)
+ video_list.append(neg_video)
+ audio_list.append(neg_audio)
+ batch_size = _get_batch_size(video_state, audio_state)
+ slg_layers_norm = _normalize_slg_layers(slg_layers)
+ use_slg = False
+ if slg_switch and slg_layers_norm:
+ total_steps = max(len(sigmas) - 1, 1)
+ start_step = int(slg_start * total_steps)
+ end_step = int(slg_end * total_steps)
+ use_slg = start_step <= step_index < end_step
+ perturbations.append(
+ _slg_perturbations(batch_size, slg_layers_norm) if use_slg else None
+ )
+ if use_alt:
+ alt_video = modality_from_latent_state(video_state, v_context_p, sigma)
+ alt_audio = modality_from_latent_state(audio_state, a_context_p, sigma)
+ alt_index = len(video_list)
+ video_list.append(alt_video)
+ audio_list.append(alt_audio)
+ batch_size = _get_batch_size(video_state, audio_state)
+ perturbations.append(_cross_attn_perturbations(batch_size))
+
denoised_video_list, denoised_audio_list = transformer(
- video=[pos_video, neg_video],
- audio=[pos_audio, neg_audio],
- perturbations=None,
+ video=video_list,
+ audio=audio_list,
+ perturbations=perturbations,
)
if denoised_video_list is None and denoised_audio_list is None:
return None, None
- denoised_video, neg_denoised_video = denoised_video_list
- denoised_audio, neg_denoised_audio = denoised_audio_list
- if denoised_video is None and denoised_audio is None:
+ pos_denoised_video = denoised_video_list[0]
+ pos_denoised_audio = denoised_audio_list[0]
+ neg_denoised_video = denoised_video_list[neg_index] if neg_index is not None else None
+ neg_denoised_audio = denoised_audio_list[neg_index] if neg_index is not None else None
+ if pos_denoised_video is None and pos_denoised_audio is None:
return None, None
- denoised_video = denoised_video + guider.delta(denoised_video, neg_denoised_video)
- denoised_audio = denoised_audio + guider.delta(denoised_audio, neg_denoised_audio)
+ denoised_video = pos_denoised_video
+ denoised_audio = pos_denoised_audio
+ if use_cfg and neg_index is not None:
+ if denoised_video is not None and neg_denoised_video is not None:
+ denoised_video = denoised_video + guider.delta(denoised_video, neg_denoised_video)
+ if denoised_audio is not None and neg_denoised_audio is not None:
+ denoised_audio = denoised_audio + guider.delta(denoised_audio, neg_denoised_audio)
+ if use_alt and alt_index is not None:
+ alt_denoised_video = denoised_video_list[alt_index]
+ alt_denoised_audio = denoised_audio_list[alt_index]
+ if denoised_video is not None and alt_denoised_video is not None:
+ denoised_video = denoised_video + (alt_guidance_scale - 1.0) * (
+ pos_denoised_video - alt_denoised_video
+ )
+ if denoised_audio is not None and alt_denoised_audio is not None:
+ denoised_audio = denoised_audio + (alt_guidance_scale - 1.0) * (
+ pos_denoised_audio - alt_denoised_audio
+ )
neg_video = neg_audio = neg_denoised_video = neg_denoised_audio = None
else:
denoised_video, denoised_audio = transformer(video=pos_video, audio=pos_audio, perturbations=None)
diff --git a/requirements.txt b/requirements.txt
index f58da42..f37df8c 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,6 +1,6 @@
# Core AI stack
diffusers==0.36.0
-transformers==5.0.0 #4.53.1
+transformers==4.54.0 #4.53.1
tokenizers>=0.20.3
accelerate>=1.1.1
tqdm
@@ -64,8 +64,8 @@ pydantic==2.10.6
# Math & modeling
torchdiffeq>=0.2.5
tensordict>=0.6.1
-mmgp==3.7.2
-peft==0.18.1 # 0.15.0
+mmgp==3.7.3
+peft==0.17.0 # 0.15.0
vector-quantize-pytorch
matplotlib
gguf==0.17.1
diff --git a/wgp.py b/wgp.py
index f4e89da..6520636 100644
--- a/wgp.py
+++ b/wgp.py
@@ -84,9 +84,9 @@ AUTOSAVE_PATH = AUTOSAVE_FILENAME
AUTOSAVE_TEMPLATE_PATH = AUTOSAVE_FILENAME
CONFIG_FILENAME = "wgp_config.json"
PROMPT_VARS_MAX = 10
-target_mmgp_version = "3.7.2"
-WanGP_version = "10.56"
-settings_version = 2.44
+target_mmgp_version = "3.7.3"
+WanGP_version = "10.60"
+settings_version = 2.45
max_source_video_frames = 3000
prompt_enhancer_image_caption_model, prompt_enhancer_image_caption_processor, prompt_enhancer_llm_model, prompt_enhancer_llm_tokenizer = None, None, None, None
image_names_list = ["image_start", "image_end", "image_refs"]