Python
various fixes
deepbeepmeep0e2d1ebaf4bb
diff --git a/README.md b/README.mdindex e08f0d2..750a152 100644--- a/README.md+++ b/README.md@@ -36,7 +36,7 @@ WanGP supports the Wan (and derived models), Hunyuan Video and LTV Video models-----## 🔥 Latest Updates :-### October 26 2025: WanGP v9.21, Why isn't all my VRAM used ?+### October 29 2025: WanGP v9.21, Why isn't all my VRAM used ?*WanGP exclusive*: VRAM requirements have never been that low !@@ -45,7 +45,17 @@ WanGP supports the Wan (and derived models), Hunyuan Video and LTV Video modelsTo get the x10 speed effect just apply the FastWan Lora Accelerator that comes prepackaged with Ovi (acccessible in the dropdown box Settings at the top)+After thorough testing it appears that *Pytorch 2.8* is causing RAM memory leaks when switching models as it won't release all the RAM. I could not find any workaround. So the default Pytorch version to use with WanGP is back to *Pytorch 2.7*+Unless you want absolutely to use Pytorch compilation which is not stable with Pytorch 2.7 with RTX 50xx , it is recommended to switch back to Pytorch 2.7.1 (tradeoff between 2.8 and 2.7):+```bash+cd Wan2GP+conda activate wan2gp+pip install torch==2.7.1 torchvision torchaudio --index-url https://download.pytorch.org/whl/test/cu128+```+You will need to reinstall SageAttention FlashAttnetion, ...+*update v9.21*: Got FastWan to work with Ovi: it is now 10 times faster ! (not including the VAE)+*update v9.25*: added Chroma Radiance october edition + reverted to pytorch 2.7### October 24 2025: WanGP v9.10, What else will you ever need after this one ?@@ -154,7 +164,7 @@ git clone https://github.com/deepbeepmeep/Wan2GP.gitcd Wan2GPconda create -n wan2gp python=3.10.9conda activate wan2gp-pip install torch==2.8.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/test/cu128+pip install torch==2.7.1 torchvision torchaudio --index-url https://download.pytorch.org/whl/test/cu128pip install -r requirements.txt```diff --git a/defaults/flux_dev_umo.json b/defaults/flux_dev_umo.jsonindex a5e8e7d..12f729c 100644--- a/defaults/flux_dev_umo.json+++ b/defaults/flux_dev_umo.json@@ -1,6 +1,6 @@{"model": {- "name": "Flux 1 UMO Dev 12B",+ "name": "Flux 1 UMO 12B","architecture": "flux_dev_umo","description": "FLUX.1 UMO Dev is a model that can Edit Images with a specialization in combining multiple image references (resized internally at 512x512 max) to produce an Image output. Best Image preservation at 768x768 Resolution Output.","URLs": "flux",diff --git a/docs/INSTALLATION.md b/docs/INSTALLATION.mdindex eff36db..2101876 100644--- a/docs/INSTALLATION.md+++ b/docs/INSTALLATION.md@@ -10,7 +10,8 @@ This guide covers installation for different GPU generations and operating syste## Installation for RTX 10XX to RTX 50XX (Stable)-This installation uses PyTorch 2.8.0 which is well-tested and stable.+This installation uses PyTorch 2.7.0 which is 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 RAM memory leaks have been observed when switching models.### Step 1: Download and Setup Environment@@ -27,8 +28,8 @@ conda activate wan2gp### Step 2: Install PyTorch```shell-# Install PyTorch 2.8.0 with CUDA 12.8-pip install torch==2.8.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/test/cu128+# Install PyTorch 2.7.1 with CUDA 12.8+pip install torch==2.7.1 torchvision torchaudio --index-url https://download.pytorch.org/whl/test/cu128```### Step 3: Install Dependencies@@ -55,7 +56,7 @@ pip install sageattention==1.0.6```shell# Windowspip install triton-windows-pip install https://github.com/woct0rdho/SageAttention/releases/download/v2.2.0-windows.post2/sageattention-2.2.0+cu128torch2.8.0.post2-cp39-abi3-win_amd64.whl+pip install https://github.com/woct0rdho/SageAttention/releases/download/v2.2.0-windows.post3/sageattention-2.2.0+cu128torch2.7.1.post3-cp39-abi3-win_amd64.whl# Linux (manual compilation required)python -m pip install "setuptools<=75.8.2" --force-reinstalldiff --git a/models/chatterbox/models/tokenizers/tokenizer.py b/models/chatterbox/models/tokenizers/tokenizer.pyindex 7a6446f..7966a98 100644--- a/models/chatterbox/models/tokenizers/tokenizer.py+++ b/models/chatterbox/models/tokenizers/tokenizer.py@@ -174,7 +174,7 @@ class ChineseCangjieConverter:# filename="Cangjie5_TC.json",# cache_dir=model_dir# )- cangjie_file = fl.locate_file(os.path.join(model_dir,"Cangjie5_TC.json"))+ cangjie_file = os.path.join(model_dir,"Cangjie5_TC.json")with open(cangjie_file, "r", encoding="utf-8") as fp:data = json.load(fp)diff --git a/models/chatterbox/pipeline.py b/models/chatterbox/pipeline.pyindex 7a891f8..77a7533 100644--- a/models/chatterbox/pipeline.py+++ b/models/chatterbox/pipeline.py@@ -86,7 +86,7 @@ class ChatterboxPipeline:min_p=min_p,top_p=top_p,)- return wav+ return {"x": wav, "audio_sampling_rate": self.sr }def release(self) -> None:if hasattr(self.model, "to"):diff --git a/models/flux/flux_handler.py b/models/flux/flux_handler.pyindex 1e2dfd2..6ec0827 100644--- a/models/flux/flux_handler.py+++ b/models/flux/flux_handler.py@@ -111,22 +111,10 @@ class family_handler():if not torch.is_tensor(tensor):return Nonetensor = tensor.detach()- if tensor.dim() == 4:- if tensor.shape[1] == 1 and tensor.shape[0] in (1, 3, 4):- tensor = tensor[:, 0, ...]- elif tensor.shape[0] == 1 and tensor.shape[1] in (3, 4):- tensor = tensor[0, ...]- if tensor.dim() == 3 and tensor.shape[0] in (3, 4):- image = tensor[:3, ...].to(torch.float32)- else:- height = meta.get("height")- width = meta.get("width")- patch_size = meta.get("patch_size", 16)- if height is None or width is None:- return None- tensor = tensor.to(torch.float32)- image = patches_to_image(tensor, height, width, patch_size)[0]- image = image.clamp(-1, 1).cpu()+ C, T, H, W = tensor.shape+ image = tensor.cpu().clamp(-1, 1)+ image = image.permute(0, 2, 1, 3) # (C, T, H, W) -> (C, H, T, W)+ image = image.reshape(C, H, T * W) # (C, H, T, W) -> (C, H, T*W)image = image.add(1).mul(127.5).clamp(0, 255).to(torch.uint8)image = image.permute(1, 2, 0).numpy()preview = Image.fromarray(image)diff --git a/models/flux/flux_main.py b/models/flux/flux_main.pyindex 509836c..c757624 100644--- a/models/flux/flux_main.py+++ b/models/flux/flux_main.py@@ -180,13 +180,6 @@ class model_factory:)return output_text[0]- def prepare_preview_payload(self, latent, meta=None):- if getattr(self.model, "radiance", False) and isinstance(meta, dict):- data = dict(meta)- data["latents"] = latent- return data- return latent-def generate(self,@@ -211,7 +204,6 @@ class model_factory:denoising_strength = 1.,**bbargs):- radiance = getattr(self.model, "radiance", False)if self._interrupt:return Noneif self.guidance_max_phases < 1: guide_scale = 1@@ -219,14 +211,9 @@ class model_factory:device="cuda"flux_dev_uso = self.name in ['flux-dev-uso']flux_dev_umo = self.name in ['flux-dev-umo']+ radiance = self.name in ['flux-chroma-radiance']flux_kontext_dreamomni2 = self.name in ['flux-dev-kontext-dreamomni2']latent_stiching = flux_dev_uso or flux_dev_umo or flux_kontext_dreamomni2- if radiance and latent_stiching:- raise ValueError("Multi image latent stitching is not supported for Chroma Radiance.")-- if radiance and (input_ref_images or input_frames is not None or input_masks is not None):- raise ValueError("Image conditioning and masking are not supported for Chroma Radiance yet.")-lock_dimensions= Falseinput_ref_images = [] if input_ref_images is None else input_ref_images[:]@@ -303,12 +290,6 @@ class model_factory:noise_channels=noise_channels,)- preview_meta = {- "height": height,- "width": width,- "patch_size": noise_patch_size,- "radiance": radiance,- }radiance_cache = Noneinp.update(prepare_prompt(self.t5, self.clip, batch_size, input_prompt))@@ -346,7 +327,6 @@ class model_factory:unpack_latent=unpack_latent,joint_pass=joint_pass,denoising_strength=denoising_strength,- preview_meta=preview_meta,radiance_cache=radiance_cache,)if x==None: return Nonediff --git a/models/flux/sampling.py b/models/flux/sampling.pyindex d0f3058..a5b4204 100644--- a/models/flux/sampling.py+++ b/models/flux/sampling.py@@ -439,6 +439,7 @@ def prepare_multi_ip(conditions_zero_start = False,set_cond_index = False,res_match_output = True,+ patch_size: int = 2) -> dict[str, Tensor]:diff --git a/plugins/wan2gp-configuration/plugin.py b/plugins/wan2gp-configuration/plugin.pyindex 5e4f740..11a3050 100644--- a/plugins/wan2gp-configuration/plugin.py+++ b/plugins/wan2gp-configuration/plugin.py@@ -215,8 +215,11 @@ class ConfigTabPlugin(WAN2GPPlugin):)def release_ram_and_notify():- self.release_model()- gr.Info("Models unloaded from RAM.")+ if self.is_generation_in_progress():+ gr.Info("Unable to unload Models when a generation is in progress.")+ else:+ self.release_model()+ gr.Info("Models unloaded from RAM.")self.release_RAM_btn.click(fn=release_ram_and_notify)return [self.release_RAM_btn]diff --git a/wgp.py b/wgp.pyindex 9b520f3..b0f7e5f 100644--- a/wgp.py+++ b/wgp.py@@ -78,7 +78,7 @@ global_queue_ref = []AUTOSAVE_FILENAME = "queue.zip"PROMPT_VARS_MAX = 10target_mmgp_version = "3.6.7"-WanGP_version = "9.21"+WanGP_version = "9.25"settings_version = 2.39max_source_video_frames = 3000prompt_enhancer_image_caption_model, prompt_enhancer_image_caption_processor, prompt_enhancer_llm_model, prompt_enhancer_llm_tokenizer = None, None, None, None@@ -155,6 +155,11 @@ def release_model():offloadobj.release()offloadobj = None_flush_torch_memory()+ from accelerate import init_empty_weights+ with init_empty_weights():+ for _ in range(3):+ dummy_tensor = torch.nn.Embedding(256384, 1024)+ dummy_tensor = Nonereload_needed = Truedef get_unique_id():global unique_id@@ -5683,11 +5688,13 @@ def generate_video(print(f"Skipped Steps:{skip_steps_cache.skipped_steps}/{skip_steps_cache.num_steps}" )generated_audio = NoneBGRA_frames = None+ output_audio_sampling_rate= audio_sampling_rateif samples != None:if isinstance(samples, dict):overlapped_latents = samples.get("latent_slice", None)BGRA_frames = samples.get("BGRA_frames", None)generated_audio = samples.get("audio", generated_audio)+ output_audio_sampling_rate = samples.get("audio_sampling_rate", audio_sampling_rate)samples = samples.get("x", None)if samples is not None:samples = samples.to("cpu")@@ -5787,7 +5794,7 @@ def generate_video(if audio_only:import soundfile as sfaudio_path = os.path.join(image_save_path, file_name)- sf.write(audio_path, sample.squeeze(0), audio_sample_rate)+ sf.write(audio_path, sample.squeeze(0), output_audio_sampling_rate)video_path= audio_pathelif is_image:image_path = os.path.join(image_save_path, file_name)