DeepBeepMeep commited on
Commit
ad96d08
·
1 Parent(s): d40f8bc

Improved Loras support

Browse files
Files changed (3) hide show
  1. README.md +2 -1
  2. gradio_server.py +28 -27
  3. requirements.txt +1 -1
README.md CHANGED
@@ -19,6 +19,7 @@ In this repository, we present **Wan2.1**, a comprehensive and open suite of vid
19
 
20
 
21
  ## 🔥 Latest News!!
 
22
  * Mar 10, 2025: 👋 Wan2.1GP v1.5: Official Teachache support + Smart Teacache (find automatically best parameters for a requested speed multiplier), 10% speed boost with no quality loss, improved lora presets (they can now include prompts and comments to guide the user)
23
  * Mar 07, 2025: 👋 Wan2.1GP v1.4: Fix Pytorch compilation, now it is really 20% faster when activated
24
  * Mar 04, 2025: 👋 Wan2.1GP v1.3: Support for Image to Video with multiples images for different images / prompts combinations (requires *--multiple-images* switch), and added command line *--preload x* to preload in VRAM x MB of the main diffusion model if you find there is too much unused VRAM and you want to (slightly) accelerate the generation process.
@@ -156,7 +157,7 @@ python gradio_server.py --attention sdpa
156
 
157
  Every lora stored in the subfoler 'loras' for t2v and 'loras_i2v' will be automatically loaded. You will be then able to activate / desactive any of them when running the application by selecting them in the area below "Activated Loras" .
158
 
159
- For each activated Lora, you may specify a *multiplier* that is one float number that corresponds to its weight (default is 1.0) .The multipliers for each Lora shoud be separated by a space character or a carriage return. For instance:\
160
  *1.2 0.8* means that the first lora will have a 1.2 multiplier and the second one will have 0.8.
161
 
162
  Alternatively for each Lora's multiplier you may specify a list of float numbers multipliers separated by a "," (no space) that gives the evolution of this Lora's multiplier over the steps. For instance let's assume there are 30 denoising steps and the multiplier is *0.9,0.8,0.7* then for the steps ranges 0-9, 10-19 and 20-29 the Lora multiplier will be respectively 0.9, 0.8 and 0.7.
 
19
 
20
 
21
  ## 🔥 Latest News!!
22
+ * Mar 13, 2025: 👋 Wan2.1GP v1.6: Better Loras support, accelerated loading Loras. You will need to refresh the requirements *pip install -r requirements.txt*
23
  * Mar 10, 2025: 👋 Wan2.1GP v1.5: Official Teachache support + Smart Teacache (find automatically best parameters for a requested speed multiplier), 10% speed boost with no quality loss, improved lora presets (they can now include prompts and comments to guide the user)
24
  * Mar 07, 2025: 👋 Wan2.1GP v1.4: Fix Pytorch compilation, now it is really 20% faster when activated
25
  * Mar 04, 2025: 👋 Wan2.1GP v1.3: Support for Image to Video with multiples images for different images / prompts combinations (requires *--multiple-images* switch), and added command line *--preload x* to preload in VRAM x MB of the main diffusion model if you find there is too much unused VRAM and you want to (slightly) accelerate the generation process.
 
157
 
158
  Every lora stored in the subfoler 'loras' for t2v and 'loras_i2v' will be automatically loaded. You will be then able to activate / desactive any of them when running the application by selecting them in the area below "Activated Loras" .
159
 
160
+ For each activated Lora, you may specify a *multiplier* that is one float number that corresponds to its weight (default is 1.0) .The multipliers for each Lora should be separated by a space character or a carriage return. For instance:\
161
  *1.2 0.8* means that the first lora will have a 1.2 multiplier and the second one will have 0.8.
162
 
163
  Alternatively for each Lora's multiplier you may specify a list of float numbers multipliers separated by a "," (no space) that gives the evolution of this Lora's multiplier over the steps. For instance let's assume there are 30 denoising steps and the multiplier is *0.9,0.8,0.7* then for the steps ranges 0-9, 10-19 and 20-29 the Lora multiplier will be respectively 0.9, 0.8 and 0.7.
gradio_server.py CHANGED
@@ -291,8 +291,8 @@ offload.default_verboseLevel = verbose_level
291
 
292
  download_models(transformer_filename_i2v if use_image2video else transformer_filename_t2v, text_encoder_filename)
293
 
294
- def sanitize_file_name(file_name):
295
- return file_name.replace("/","").replace("\\","").replace(":","").replace("|","").replace("?","").replace("<","").replace(">","").replace("\"","")
296
 
297
  def extract_preset(lset_name, loras):
298
  lset_name = sanitize_file_name(lset_name)
@@ -338,34 +338,35 @@ def setup_loras(pipe, lora_dir, lora_preselected_preset, split_linear_modules_m
338
  default_loras_choices = []
339
  default_loras_multis_str = ""
340
  loras_presets = []
 
 
341
 
342
- from pathlib import Path
 
343
 
344
- if lora_dir != None :
345
- if not os.path.isdir(lora_dir):
346
- raise Exception("--lora-dir should be a path to a directory that contains Loras")
347
 
348
- default_lora_preset = ""
349
- default_prompt = ""
350
- if lora_dir != None:
351
- import glob
352
- dir_loras = glob.glob( os.path.join(lora_dir , "*.sft") ) + glob.glob( os.path.join(lora_dir , "*.safetensors") )
353
- dir_loras.sort()
354
- loras += [element for element in dir_loras if element not in loras ]
355
 
356
- dir_presets = glob.glob( os.path.join(lora_dir , "*.lset") )
357
- dir_presets.sort()
358
- loras_presets = [ Path(Path(file_path).parts[-1]).stem for file_path in dir_presets]
359
 
360
- if len(loras) > 0:
361
- loras_names = [ Path(lora).stem for lora in loras ]
362
- offload.load_loras_into_model(pipe["transformer"], loras, activate_all_loras=False, split_linear_modules_map = split_linear_modules_map) #lora_multiplier,
363
-
364
- if len(lora_preselected_preset) > 0:
365
- if not os.path.isfile(os.path.join(lora_dir, lora_preselected_preset + ".lset")):
366
- raise Exception(f"Unknown preset '{lora_preselected_preset}'")
367
- default_lora_preset = lora_preselected_preset
368
- default_loras_choices, default_loras_multis_str, default_prompt, _ = extract_preset(default_lora_preset, loras)
369
  if len(default_prompt) == 0:
370
  default_prompt = get_default_prompt(use_image2video)
371
  return loras, loras_names, default_loras_choices, default_loras_multis_str, default_prompt, default_lora_preset, loras_presets
@@ -966,9 +967,9 @@ def generate_video(
966
 
967
  time_flag = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d-%Hh%Mm%Ss")
968
  if os.name == 'nt':
969
- file_name = f"{time_flag}_seed{seed}_{prompt[:50].replace('/','').strip()}.mp4".replace(':',' ').replace('\\',' ')
970
  else:
971
- file_name = f"{time_flag}_seed{seed}_{prompt[:100].replace('/','').strip()}.mp4".replace(':',' ').replace('\\',' ')
972
  video_path = os.path.join(os.getcwd(), "gradio_outputs", file_name)
973
  cache_video(
974
  tensor=sample[None],
 
291
 
292
  download_models(transformer_filename_i2v if use_image2video else transformer_filename_t2v, text_encoder_filename)
293
 
294
+ def sanitize_file_name(file_name, rep =""):
295
+ return file_name.replace("/",rep).replace("\\",rep).replace(":",rep).replace("|",rep).replace("?",rep).replace("<",rep).replace(">",rep).replace("\"",rep)
296
 
297
  def extract_preset(lset_name, loras):
298
  lset_name = sanitize_file_name(lset_name)
 
338
  default_loras_choices = []
339
  default_loras_multis_str = ""
340
  loras_presets = []
341
+ default_lora_preset = ""
342
+ default_prompt = ""
343
 
344
+ if use_image2video or not "1.3B" in transformer_filename_t2v:
345
+ from pathlib import Path
346
 
347
+ if lora_dir != None :
348
+ if not os.path.isdir(lora_dir):
349
+ raise Exception("--lora-dir should be a path to a directory that contains Loras")
350
 
351
+ if lora_dir != None:
352
+ import glob
353
+ dir_loras = glob.glob( os.path.join(lora_dir , "*.sft") ) + glob.glob( os.path.join(lora_dir , "*.safetensors") )
354
+ dir_loras.sort()
355
+ loras += [element for element in dir_loras if element not in loras ]
 
 
356
 
357
+ dir_presets = glob.glob( os.path.join(lora_dir , "*.lset") )
358
+ dir_presets.sort()
359
+ loras_presets = [ Path(Path(file_path).parts[-1]).stem for file_path in dir_presets]
360
 
361
+ if len(loras) > 0:
362
+ loras_names = [ Path(lora).stem for lora in loras ]
363
+ offload.load_loras_into_model(pipe["transformer"], loras, activate_all_loras=False, split_linear_modules_map = split_linear_modules_map) #lora_multiplier,
364
+
365
+ if len(lora_preselected_preset) > 0:
366
+ if not os.path.isfile(os.path.join(lora_dir, lora_preselected_preset + ".lset")):
367
+ raise Exception(f"Unknown preset '{lora_preselected_preset}'")
368
+ default_lora_preset = lora_preselected_preset
369
+ default_loras_choices, default_loras_multis_str, default_prompt, _ = extract_preset(default_lora_preset, loras)
370
  if len(default_prompt) == 0:
371
  default_prompt = get_default_prompt(use_image2video)
372
  return loras, loras_names, default_loras_choices, default_loras_multis_str, default_prompt, default_lora_preset, loras_presets
 
967
 
968
  time_flag = datetime.fromtimestamp(time.time()).strftime("%Y-%m-%d-%Hh%Mm%Ss")
969
  if os.name == 'nt':
970
+ file_name = f"{time_flag}_seed{seed}_{sanitize_file_name(prompt[:50])}.mp4"
971
  else:
972
+ file_name = f"{time_flag}_seed{seed}_{sanitize_file_name(prompt[:100])}.mp4"
973
  video_path = os.path.join(os.getcwd(), "gradio_outputs", file_name)
974
  cache_video(
975
  tensor=sample[None],
requirements.txt CHANGED
@@ -16,5 +16,5 @@ gradio>=5.0.0
16
  numpy>=1.23.5,<2
17
  einops
18
  moviepy==1.0.3
19
- mmgp==3.2.3
20
  peft==0.14.0
 
16
  numpy>=1.23.5,<2
17
  einops
18
  moviepy==1.0.3
19
+ mmgp==3.2.5
20
  peft==0.14.0