Python
added loras accelerators for Ovi
deepbeepmeep16c4dd27627c
diff --git a/README.md b/README.mdindex 6a1153b..6f3c6f7 100644--- a/README.md+++ b/README.md@@ -36,12 +36,14 @@ WanGP supports the Wan (and derived models), Hunyuan Video and LTV Video models-----## 🔥 Latest Updates :-### October 26 2025: WanGP v9.20, Why isn't all my VRAM used ?+### October 26 2025: WanGP v9.21, Why isn't all my VRAM used ?*WanGP exclusive***Wan 2.2 Ovi 10 GB** for all the GPU Poors of the World: *only 6 GB of VRAM to generate 121 frames at 720p*. With 16 GB of VRAM, you may even be able to load all the model in VRAM with *Memory Profile 3*+*update v9.21*: Got FastWan to work with Ovi: it is now 10 times faster ! (not including the VAE)+### October 24 2025: WanGP v9.10, What else will you ever need after this one ?With WanGP v9 you will have enough features to go to a desert island with no internet connection and comes back with a full Hollywood movie.diff --git a/models/wan/ovi_fusion_engine.py b/models/wan/ovi_fusion_engine.pyindex def48d6..452c5b5 100644--- a/models/wan/ovi_fusion_engine.py+++ b/models/wan/ovi_fusion_engine.py@@ -366,3 +366,5 @@ class OviFusionEngine:def custom_compile(self, **compile_kwargs):self.model.custom_compile(compile_kwargs)+ def get_trans_lora(self):+ return self.model.video_model, None\ No newline at end of filediff --git a/models/wan/ovi_handler.py b/models/wan/ovi_handler.pyindex 364d090..31d47bc 100644--- a/models/wan/ovi_handler.py+++ b/models/wan/ovi_handler.py@@ -35,7 +35,7 @@ class family_handler:def query_model_def(base_model_type: str, model_def: Dict[str, Any]):cfg = {"wan_5B_class": True,- "profiles_dir": [""],+ "profiles_dir": ["wan_2_2_ovi"],"group": "wan2_2","fps": 24,"frames_minimum": 121,diff --git a/profiles/wan_2_2_ovi/FastWan 6 Steps.json b/profiles/wan_2_2_ovi/FastWan 6 Steps.jsonnew file mode 100644index 0000000..f6dffbb--- /dev/null+++ b/profiles/wan_2_2_ovi/FastWan 6 Steps.json@@ -0,0 +1,8 @@+{+ "activated_loras": ["https://huggingface.co/DeepBeepMeep/Wan2.2/resolve/main/loras_accelerators/Wan2_2_5B_FastWanFullAttn_lora_rank_128_bf16.safetensors"],+ "guidance_scale": 1,+ "audio_guidance_scale": 1,+ "flow_shift": 6,+ "num_inference_steps": 6,+ "loras_multipliers": "1"+}\ No newline at end of filediff --git a/shared/utils/files_locator.py b/shared/utils/files_locator.pyindex 1e425d0..923559f 100644--- a/shared/utils/files_locator.py+++ b/shared/utils/files_locator.py@@ -19,7 +19,7 @@ def get_download_location(file_name = None):else:return _checkpoints_paths[0]-def locate_folder(folder_name):+def locate_folder(folder_name, error_if_none = True):if os.path.isabs(folder_name):if os.path.isdir(folder_name): return folder_nameelse:@@ -27,11 +27,11 @@ def locate_folder(folder_name):path = os.path.join(folder, folder_name)if os.path.isdir(path):return path-+ if error_if_none: raise Exception(f"Unable to locate folder '{folder_name}'")return None-def locate_file(file_name, create_path_if_none = False):+def locate_file(file_name, create_path_if_none = False, error_if_none = True):if os.path.isabs(file_name):if os.path.isfile(file_name): return file_nameelse:@@ -42,5 +42,6 @@ def locate_file(file_name, create_path_if_none = False):if create_path_if_none:return get_download_location(file_name)+ if error_if_none: raise Exception(f"Unable to locate file '{file_name}'")return Nonediff --git a/wgp.py b/wgp.pyindex 1a6640a..3515998 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.20"+WanGP_version = "9.21"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@@ -2034,7 +2034,7 @@ def get_lora_dir(model_type):lora_dir_1_3B = os.path.join(root_lora_dir, "1.3B")if os.path.isdir(lora_dir_1_3B ):return lora_dir_1_3B- elif base_model_type == "ti2v_2_2":+ elif base_model_type in ["ti2v_2_2", "ovi"]:lora_dir_5B = os.path.join(root_lora_dir, "5B")if os.path.isdir(lora_dir_5B ):return lora_dir_5B@@ -2097,7 +2097,7 @@ if not os.path.isfile(server_config_filename) and os.path.isfile("gradio_config.src_move = [ "models_clip_open-clip-xlm-roberta-large-vit-huge-14-bf16.safetensors", "models_t5_umt5-xxl-enc-bf16.safetensors", "models_t5_umt5-xxl-enc-quanto_int8.safetensors" ]tgt_move = [ "xlm-roberta-large", "umt5-xxl", "umt5-xxl"]for src,tgt in zip(src_move,tgt_move):- src = fl.locate_file(src)+ src = fl.locate_file(src, error_if_none= False)tgt = fl.get_download_location(tgt)if src is not None:try:@@ -2151,7 +2151,7 @@ for path in ["wan2.1_Vace_1.3B_preview_bf16.safetensors", "sky_reels2_diffusion"wan2.1_Vace_14B_mbf16.safetensors", "wan2.1_Vace_14B_quanto_mbf16_int8.safetensors", "wan2.1_FLF2V_720p_14B_quanto_int8.safetensors", "wan2.1_FLF2V_720p_14B_bf16.safetensors", "wan2.1_FLF2V_720p_14B_fp16.safetensors", "wan2.1_Vace_1.3B_mbf16.safetensors", "wan2.1_text2video_1.3B_bf16.safetensors","ltxv_0.9.7_13B_dev_bf16.safetensors"]:- if fl.locate_file(path) is not None:+ if fl.locate_file(path, error_if_none= False) is not None:print(f"Removing old version of model '{path}'. A new version of this model will be downloaded next time you use it.")os.remove( fl.locate_file(path))@@ -2828,7 +2828,7 @@ def get_local_model_filename(model_filename):local_model_filename =os.path.basename(model_filename)else:local_model_filename = model_filename- local_model_filename = fl.locate_file(local_model_filename)+ local_model_filename = fl.locate_file(local_model_filename, error_if_none= False)return local_model_filename@@ -2841,15 +2841,15 @@ def process_files_def(repoId = None, sourceFolderList = None, fileList = None, tif targetFolder is not None and len(targetFolder) == 0: targetFolder = NonetargetRoot = os.path.join(original_targetRoot, targetFolder) if targetFolder is not None else original_targetRootif len(files)==0:- if fl.locate_folder(sourceFolder if targetFolder is None else os.path.join(targetFolder, sourceFolder) ) is None:+ if fl.locate_folder(sourceFolder if targetFolder is None else os.path.join(targetFolder, sourceFolder), error_if_none= False ) is None:snapshot_download(repo_id=repoId, allow_patterns=sourceFolder +"/*", local_dir= targetRoot)else:for onefile in files:if len(sourceFolder) > 0:- if fl.locate_file( (sourceFolder + "/" + onefile) if targetFolder is None else os.path.join(targetFolder, sourceFolder, onefile)) is None:+ if fl.locate_file( (sourceFolder + "/" + onefile) if targetFolder is None else os.path.join(targetFolder, sourceFolder, onefile), error_if_none= False) is None:hf_hub_download(repo_id=repoId, filename=onefile, local_dir = targetRoot, subfolder=sourceFolder)else:- if fl.locate_file(onefile if targetFolder is None else os.path.join(targetFolder, onefile)) is None:+ if fl.locate_file(onefile if targetFolder is None else os.path.join(targetFolder, onefile), error_if_none= False) is None:hf_hub_download(repo_id=repoId, filename=onefile, local_dir = targetRoot)def download_mmaudio():@@ -2963,7 +2963,7 @@ def download_models(model_filename = None, model_type= None, module_type = Falsepreload_URLs = [get_model_filename(model_type=model_type, quantization= text_encoder_quantization, dtype_policy = transformer_dtype_policy, URLs=preload_URLs)] if len(preload_URLs) > 0 else []for url in preload_URLs:- filename = fl.locate_file(os.path.basename(url))+ filename = fl.locate_file(os.path.basename(url), error_if_none= False)if filename is None:filename = fl.get_download_location(os.path.basename(url))if not url.startswith("http"):@@ -4987,16 +4987,21 @@ def generate_video(if len(errors) > 0 : raise gr.Error(errors)loras_selected += [ os.path.join(lora_dir, os.path.basename(lora)) for lora in activated_loras]+ if hasattr(wan_model, "get_trans_lora"):+ trans_lora, trans2_lora = wan_model.get_trans_lora()+ else:+ trans_lora, trans2_lora = trans, trans2+if len(loras_selected) > 0:pinnedLora = loaded_profile !=5 # and transformer_loras_filenames == None False # # #split_linear_modules_map = getattr(trans,"split_linear_modules_map", None)- offload.load_loras_into_model(trans , loras_selected, loras_list_mult_choices_nums, activate_all_loras=True, preprocess_sd=get_loras_preprocessor(trans, base_model_type), pinnedLora=pinnedLora, split_linear_modules_map = split_linear_modules_map)- errors = trans._loras_errors+ offload.load_loras_into_model(trans_lora, loras_selected, loras_list_mult_choices_nums, activate_all_loras=True, preprocess_sd=get_loras_preprocessor(trans, base_model_type), pinnedLora=pinnedLora, split_linear_modules_map = split_linear_modules_map)+ errors = trans_lora._loras_errorsif len(errors) > 0:error_files = [msg for _ , msg in errors]raise gr.Error("Error while loading Loras: " + ", ".join(error_files))- if trans2 is not None:- offload.sync_models_loras(trans, trans2)+ if trans2_lora is not None:+ offload.sync_models_loras(trans_lora, trans2_lora)seed = None if seed == -1 else seed# negative_prompt = "" # not applicable in the inference@@ -5600,10 +5605,11 @@ def generate_video(clear_gen_cache()offloadobj.unload_all()trans.cache = None- offload.unload_loras_from_model(trans)if trans2 is not None:trans2.cache = None- offload.unload_loras_from_model(trans2)+ offload.unload_loras_from_model(trans_lora)+ if trans2_lora is not None:+ offload.unload_loras_from_model(trans2_lora)skip_steps_cache = None# if compile:# cache_size = torch._dynamo.config.cache_size_limit@@ -5848,11 +5854,13 @@ def generate_video(seed = set_seed(-1)clear_status(state)trans.cache = None- offload.unload_loras_from_model(trans)- if not trans2 is None:- trans2.cache = None- offload.unload_loras_from_model(trans2)+ offload.unload_loras_from_model(trans_lora)+ if not trans2_lora is None:+ offload.unload_loras_from_model(trans2_lora)+ if not trans2 is None:+ trans2.cache = None+if len(control_audio_tracks) > 0 or len(source_audio_tracks) > 0:cleanup_temp_audio_files(control_audio_tracks + source_audio_tracks)