Skip to content

Jonnnty/Wan2.2-Animate-14B-Quant-Compression

Repository files navigation

Wan2.2-Animate-14B-Quant-Compression

Mixed-precision quantization scheme (16/8/4bit mixed quantization) for the Wan2.2-Animate-14B model. Compresses the original 35GB base model to 17GB, balancing inference performance and model size.

Prepare

This project is the quantization compression for the Wan-AI/Wan2.2-Animate-14B model. You need to download the code and pre-trained model in advance:

Quantization Schemes

Quantization Strategy Comparison

Quantization Category Specific Targets 16/8/4bit Mixed Quantization (17.3G) 16/8bit Mixed Quantization (18.3G)
1. Image Branch Weights cross_attn.k_img.weight
cross_attn.v_img.weight
4bit Quantization
(with compensation + packing)
8bit Quantization
2. FFN Weights blocks.*.ffn.0.weight
blocks.*.ffn.2.weight
8bit Quantization
Biases: 16bit
8bit Quantization
Biases: 16bit
3. KQV Attention Weights All self_attn and cross_attn weights
(except image branch)
cross_attn.q, cross_attn.o16bit
Others → 8bit
cross_attn.q, cross_attn.o16bit
Others → 8bit
4. Face-Related Weights face_encoder.*.weight
face_adapter.*.weight
8bit Quantization
(except sensitive layers)
8bit Quantization
(except sensitive layers)
5. All Other Weights All weights not in above categories
(modulation, norm, embedding, etc.)
Keep 16bit Keep 16bit

Key Differences Summary

  • Image Branch Weights (only 2 layers):
    • 16/8/4bit Scheme: 4bit quantization with statistical compensation and packing
    • 16/8bit Scheme: Standard 8bit quantization
  • Other Layers: Identical quantization strategies
  • Compression Ratio: 34.5G → 17.3G (50% reduction) vs 34.5G → 18.3G (47% reduction)

Shared Quantization Rules

  1. FFN Weights: 8bit for weights, 16bit for biases
  2. Shallow Q/O Layers: cross_attn.q and cross_attn.o weights remain 16bit
  3. Face Sensitive Layers: Specific sensitive weights remain 16bit
  4. All Biases: All bias terms remain 16bit
  5. Other Modules: All other components remain 16bit

Comparison Results

Animation

Animation Video 1

Animation Video 2

Animation Video 3

Original Model (34.5G) | Mixed-Precision Quantized Model (17.3G)

Click the image to play the video

Replacement

Replacement Video 1

Replacement Video 2

Original Model (34.5G) | Mixed-Precision Quantized Model (17.3G)

Click the image to play the video

Usage Guide

Step 1: Prepare Original Model

  1. Download the original Wan2.2 repository:
git clone https://github.com/Wan-Video/Wan2.2.git

Download the pre-trained Wan2.2-Animate-14B model from Hugging Face.

Step 2: Apply Quantization Patches

Replace the original files with our quantized versions:

# Replace animate.py with our quantized version
cp /animate.py Wan2.2/wan/animate.py

# Replace generate.py with our quantized version
cp /generate.py Wan2.2/generate.py

Step 3: Choose Quantization Scheme

Option 1: 16/8/4bit Mixed Quantization

Run the 16/8/4bit mixed quantization script:

python quantization_with_4bit.py

This will create a quantized/ folder in Wan2.2-Animate-14B/ containing:

quantized/
├── diffusion_pytorch_model-00001-of-00004.safetensors
├── diffusion_pytorch_model-00002-of-00004.safetensors
├── diffusion_pytorch_model-00003-of-00004.safetensors
├── diffusion_pytorch_model-00004-of-00004.safetensors
├── diffusion_pytorch_model.safetensors.index.json
├── advanced_quantization_info.json
└── quantization_info.json

Option 2: 16/8bit Mixed Quantization

Run the 16/8bit mixed quantization script:

python quantization_with_8bit.py

This will also create a quantized/ folder with the quantized model files.

Step 4: Generate Videos with Quantized Model

After quantization, follow the original Wan2.2 instructions to generate videos. The quantized model will be automatically loaded.

About

Mixed-precision quantization scheme (16/8/4bit mixed quantization) for the Wan2.2-Animate-14B model. Compresses the original 35GB base model to 17GB, balancing inference performance and model size.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages