RIFLEx support

This commit is contained in:
DeepBeepMeep 2025-03-02 17:48:57 +01:00
parent 3731ab70e1
commit 7a8dcbf63d
5 changed files with 14 additions and 20 deletions

View File

@ -45,25 +45,22 @@ It is an illustration on how one can set up on an existing model some fast and p
For more information on how to use the mmpg module, please go to: https://github.com/deepbeepmeep/mmgp
You will find the original Hunyuan Video repository here: https://github.com/deepbeepmeep/Wan2GP
You will find the original Wan2.1 Video repository here: https://github.com/Wan-Video/Wan2.1
## Installation Guide for Linux and Windows
We provide an `environment.yml` file for setting up a Conda environment.
Conda's installation instructions are available [here](https://docs.anaconda.com/free/miniconda/index.html).
This app has been tested on Python 3.10 / 2.6.0 / Cuda 12.4.\
```shell
# 1 - conda. Prepare and activate a conda environment
conda env create -f environment.yml
conda activate Wan2
# 0 Create a Python 3.10.9 environment or a venv using python
conda create -name Wan2GP python==3.10.9 #if you have conda
# OR
# 1 - venv. Alternatively create a python 3.10 venv and then do the following
# 1 Install pytorch 2.6.0
pip install torch==2.6.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/test/cu124
@ -81,9 +78,6 @@ pip install -e .
# 3.2 optional Flash attention support (easy to install on Linux but much harder on Windows)
python -m pip install flash-attn==2.7.2.post1
```
Note that *Flash attention* and *Sage attention* are quite complex to install on Windows but offers a better memory management (and consequently longer videos) than the default *sdpa attention*.

View File

@ -975,9 +975,9 @@ def create_demo():
gr.Markdown("The VRAM requirements will depend greatly of the resolution and the duration of the video, for instance : 24 GB of VRAM (RTX 3090 / RTX 4090), the limits are as follows:")
gr.Markdown("- 848 x 480 with a 14B model: 80 frames (5s) : 8 GB of VRAM")
gr.Markdown("- 848 x 480 with the 1.3B model: 80 frames (5s) : 5 GB of VRAM")
gr.Markdown("- 1280 x 720 with a 14B model: 192 frames (8s): 11 GB of VRAM")
gr.Markdown("Note that the VAE stages (encoding / decoding at image2video ) or just the decoding at text2video will create a temporary VRAM peak (up to 12GB for 420P and 22 GB for 720P)")
gr.Markdown("It is not recommmended to generate a video longer than 8s even if there is still some VRAM left as some artifact may appear")
gr.Markdown("- 1280 x 720 with a 14B model: 80 frames (5s): 11 GB of VRAM")
gr.Markdown("Note that the VAE stages (encoding / decoding at image2video ) or just the decoding at text2video will create a temporary VRAM peaks (up to 12GB for 420P and 22 GB for 720P)")
gr.Markdown("It is not recommmended to generate a video longer than 8s (128 frames) even if there is still some VRAM left as some artifact may appear")
gr.Markdown("Please note that if your turn on compilation, the first generation step of the first video generation will be slow due to the compilation. Therefore all your tests should be done with compilation turned off.")
@ -996,7 +996,7 @@ def create_demo():
index = 0 if index ==0 else index
transformer_t2v_choice = gr.Dropdown(
choices=[
("WAN 2.1 1.3B Text to Video 16 bits - the small model for fast generations with low VRAM requirements", 0),
("WAN 2.1 1.3B Text to Video 16 bits (recommended)- the small model for fast generations with low VRAM requirements", 0),
("WAN 2.1 14B Text to Video 16 bits - the default engine in its original glory, offers a slightly better image quality but slower and requires more RAM", 1),
("WAN 2.1 14B Text to Video quantized to 8 bits (recommended) - the default engine but quantized", 2),
],

View File

@ -289,7 +289,7 @@ class WanI2V:
# sample videos
latent = noise
freqs = self.model.get_rope_freqs(nb_latent_frames = int((frame_num - 1)/4 + 1), RIFLEx_k = 4 if enable_RIFLEx else None )
freqs = self.model.get_rope_freqs(nb_latent_frames = int((frame_num - 1)/4 + 1), RIFLEx_k = 6 if enable_RIFLEx else None )
arg_c = {
'context': [context[0]],

View File

@ -654,8 +654,8 @@ class WanModel(ModelMixin, ConfigMixin):
assert (dim % num_heads) == 0 and (dim // num_heads) % 2 == 0
freqs = torch.cat([
rope_params_riflex(1024, dim= d - 4 * (d // 6), L_test=nb_latent_frames, k = RIFLEx_k ), #44
freqs = torch.cat([
rope_params_riflex(1024, dim= d - 4 * (d // 6), L_test=nb_latent_frames, k = RIFLEx_k ) if RIFLEx_k != None else rope_params(1024, dim= d - 4 * (d // 6)), #44
rope_params(1024, 2 * (d // 6)), #42
rope_params(1024, 2 * (d // 6)) #42
],dim=1)

View File

@ -240,7 +240,7 @@ class WanT2V:
# k, N_k = identify_k(10000, 44, 26)
# print(f"value nb latent frames={nf}, k={k}, n_k={N_k}")
freqs = self.model.get_rope_freqs(nb_latent_frames = int((frame_num - 1)/4 + 1), RIFLEx_k = 4 if enable_RIFLEx else None )
freqs = self.model.get_rope_freqs(nb_latent_frames = int((frame_num - 1)/4 + 1), RIFLEx_k = 6 if enable_RIFLEx else None )
arg_c = {'context': context, 'seq_len': seq_len, 'freqs': freqs, 'pipeline': self}
arg_null = {'context': context_null, 'seq_len': seq_len, 'freqs': freqs, 'pipeline': self}