deploy_gradio.md 9.58 KB
Newer Older
gushiqiao's avatar
gushiqiao committed
1
# Gradio Deployment Guide
helloyongyang's avatar
helloyongyang committed
2

gushiqiao's avatar
gushiqiao committed
3
4
5
6
## 📖 Overview

Lightx2v is a lightweight video inference and generation engine that provides a web interface based on Gradio, supporting both Image-to-Video and Text-to-Video generation modes.

gushiqiao's avatar
gushiqiao committed
7
8
For Windows systems, we provide a convenient one-click deployment solution with automatic environment configuration and intelligent parameter optimization. Please refer to the [One-Click Gradio Startup (Recommended)](./deploy_local_windows.md/#one-click-gradio-startup-recommended) section for detailed instructions.

gushiqiao's avatar
Fix  
gushiqiao committed
9
![Gradio English Interface](../../../../assets/figs/portabl_windows/pic_gradio_en.png)
gushiqiao's avatar
gushiqiao committed
10

gushiqiao's avatar
gushiqiao committed
11
12
13
14
15
16
17
18
## 📁 File Structure

```
LightX2V/app/
├── gradio_demo.py          # English interface demo
├── gradio_demo_zh.py       # Chinese interface demo
├── run_gradio.sh          # Startup script
├── README.md              # Documentation
gushiqiao's avatar
gushiqiao committed
19
├── outputs/               # Generated video save directory
gushiqiao's avatar
gushiqiao committed
20
21
22
└── inference_logs.log     # Inference logs
```

gushiqiao's avatar
gushiqiao committed
23
24
25
26
27
28
This project contains two main demo files:
- `gradio_demo.py` - English interface version
- `gradio_demo_zh.py` - Chinese interface version

## 🚀 Quick Start

gushiqiao's avatar
gushiqiao committed
29
### Environment Requirements
gushiqiao's avatar
gushiqiao committed
30

gushiqiao's avatar
gushiqiao committed
31
Follow the [Quick Start Guide](../getting_started/quickstart.md) to install the environment
gushiqiao's avatar
gushiqiao committed
32
33
34
35
36
37
38
39
40

#### Recommended Optimization Library Configuration

-[Flash attention](https://github.com/Dao-AILab/flash-attention)
-[Sage attention](https://github.com/thu-ml/SageAttention)
-[vllm-kernel](https://github.com/vllm-project/vllm)
-[sglang-kernel](https://github.com/sgl-project/sglang/tree/main/sgl-kernel)
-[q8-kernel](https://github.com/KONAKONA666/q8_kernels) (only supports ADA architecture GPUs)

Gu Shiqiao's avatar
Gu Shiqiao committed
41
Install according to the project homepage tutorials for each operator as needed.
gushiqiao's avatar
gushiqiao committed
42

Gu Shiqiao's avatar
Gu Shiqiao committed
43
### 📥 Model Download
gushiqiao's avatar
gushiqiao committed
44

Gu Shiqiao's avatar
Gu Shiqiao committed
45
Refer to the [Model Structure Documentation](../getting_started/model_structure.md) to download complete models (including quantized and non-quantized versions) or download only quantized/non-quantized versions.
gushiqiao's avatar
gushiqiao committed
46

Gu Shiqiao's avatar
Gu Shiqiao committed
47
#### wan2.1 Model Directory Structure
gushiqiao's avatar
gushiqiao committed
48

Gu Shiqiao's avatar
Gu Shiqiao committed
49
50
51
52
53
54
55
56
57
58
59
60
```
models/
├── wan2.1_i2v_720p_lightx2v_4step.safetensors                   # Original precision
├── wan2.1_i2v_720p_scaled_fp8_e4m3_lightx2v_4step.safetensors   # FP8 quantization
├── wan2.1_i2v_720p_int8_lightx2v_4step.safetensors              # INT8 quantization
├── wan2.1_i2v_720p_int8_lightx2v_4step_split                    # INT8 quantization block storage directory
├── wan2.1_i2v_720p_scaled_fp8_e4m3_lightx2v_4step_split         # FP8 quantization block storage directory
├── Other weights (e.g., t2v)
├── t5/clip/xlm-roberta-large/google    # text and image encoder
├── vae/lightvae/lighttae               # vae
└── config.json                         # Model configuration file
```
gushiqiao's avatar
gushiqiao committed
61

Gu Shiqiao's avatar
Gu Shiqiao committed
62
#### wan2.2 Model Directory Structure
gushiqiao's avatar
gushiqiao committed
63

Gu Shiqiao's avatar
Gu Shiqiao committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
```
models/
├── wan2.2_i2v_A14b_high_noise_lightx2v_4step_1030.safetensors        # high noise original precision
├── wan2.2_i2v_A14b_high_noise_fp8_e4m3_lightx2v_4step_1030.safetensors    # high noise FP8 quantization
├── wan2.2_i2v_A14b_high_noise_int8_lightx2v_4step_1030.safetensors   # high noise INT8 quantization
├── wan2.2_i2v_A14b_high_noise_int8_lightx2v_4step_1030_split         # high noise INT8 quantization block storage directory
├── wan2.2_i2v_A14b_low_noise_lightx2v_4step.safetensors         # low noise original precision
├── wan2.2_i2v_A14b_low_noise_fp8_e4m3_lightx2v_4step.safetensors     # low noise FP8 quantization
├── wan2.2_i2v_A14b_low_noise_int8_lightx2v_4step.safetensors    # low noise INT8 quantization
├── wan2.2_i2v_A14b_low_noise_int8_lightx2v_4step_split          # low noise INT8 quantization block storage directory
├── t5/clip/xlm-roberta-large/google    # text and image encoder
├── vae/lightvae/lighttae               # vae
└── config.json                         # Model configuration file
```
gushiqiao's avatar
gushiqiao committed
78

Gu Shiqiao's avatar
Gu Shiqiao committed
79
**📝 Download Instructions**:
gushiqiao's avatar
gushiqiao committed
80

Gu Shiqiao's avatar
Gu Shiqiao committed
81
82
83
- Model weights can be downloaded from HuggingFace:
  - [Wan2.1-Distill-Models](https://huggingface.co/lightx2v/Wan2.1-Distill-Models)
  - [Wan2.2-Distill-Models](https://huggingface.co/lightx2v/Wan2.2-Distill-Models)
Gu Shiqiao's avatar
Gu Shiqiao committed
84
- Text and Image Encoders can be downloaded from [Encoders](https://huggingface.co/lightx2v/Encoders)
Gu Shiqiao's avatar
Gu Shiqiao committed
85
86
- VAE can be downloaded from [Autoencoders](https://huggingface.co/lightx2v/Autoencoders)
- For `xxx_split` directories (e.g., `wan2.1_i2v_720p_scaled_fp8_e4m3_lightx2v_4step_split`), which store multiple safetensors by block, suitable for devices with insufficient memory. For example, devices with 16GB or less memory should download according to their own situation.
gushiqiao's avatar
gushiqiao committed
87

gushiqiao's avatar
gushiqiao committed
88
89
90
91
### Startup Methods

#### Method 1: Using Startup Script (Recommended)

gushiqiao's avatar
gushiqiao committed
92
**Linux Environment:**
gushiqiao's avatar
gushiqiao committed
93
94
95
96
97
98
99
```bash
# 1. Edit the startup script to configure relevant paths
cd app/
vim run_gradio.sh

# Configuration items that need to be modified:
# - lightx2v_path: Lightx2v project root directory path
Gu Shiqiao's avatar
Gu Shiqiao committed
100
# - model_path: Model root directory path (contains all model files)
gushiqiao's avatar
gushiqiao committed
101
102
103
104
105
106
107

# 💾 Important note: Recommend pointing model paths to SSD storage locations
# Example: /mnt/ssd/models/ or /data/ssd/models/

# 2. Run the startup script
bash run_gradio.sh

Gu Shiqiao's avatar
Gu Shiqiao committed
108
109
110
# 3. Or start with parameters
bash run_gradio.sh --lang en --port 8032
bash run_gradio.sh --lang zh --port 7862
gushiqiao's avatar
gushiqiao committed
111
112
113
114
115
116
117
118
119
120
```

**Windows Environment:**
```cmd
# 1. Edit the startup script to configure relevant paths
cd app\
notepad run_gradio_win.bat

# Configuration items that need to be modified:
# - lightx2v_path: Lightx2v project root directory path
Gu Shiqiao's avatar
Gu Shiqiao committed
121
# - model_path: Model root directory path (contains all model files)
gushiqiao's avatar
gushiqiao committed
122
123
124
125
126
127
128

# 💾 Important note: Recommend pointing model paths to SSD storage locations
# Example: D:\models\ or E:\models\

# 2. Run the startup script
run_gradio_win.bat

Gu Shiqiao's avatar
Gu Shiqiao committed
129
130
131
# 3. Or start with parameters
run_gradio_win.bat --lang en --port 8032
run_gradio_win.bat --lang zh --port 7862
gushiqiao's avatar
gushiqiao committed
132
133
134
135
```

#### Method 2: Direct Command Line Startup

Gu Shiqiao's avatar
Gu Shiqiao committed
136
137
138
139
```bash
pip install -v git+https://github.com/ModelTC/LightX2V.git
```

gushiqiao's avatar
gushiqiao committed
140
141
**Linux Environment:**

Gu Shiqiao's avatar
Gu Shiqiao committed
142
**English Interface Version:**
gushiqiao's avatar
gushiqiao committed
143
144
```bash
python gradio_demo.py \
Gu Shiqiao's avatar
Gu Shiqiao committed
145
    --model_path /path/to/models \
gushiqiao's avatar
gushiqiao committed
146
147
148
149
    --server_name 0.0.0.0 \
    --server_port 7862
```

Gu Shiqiao's avatar
Gu Shiqiao committed
150
**Chinese Interface Version:**
gushiqiao's avatar
gushiqiao committed
151
```bash
Gu Shiqiao's avatar
Gu Shiqiao committed
152
153
python gradio_demo_zh.py \
    --model_path /path/to/models \
gushiqiao's avatar
gushiqiao committed
154
155
156
157
    --server_name 0.0.0.0 \
    --server_port 7862
```

gushiqiao's avatar
gushiqiao committed
158
159
**Windows Environment:**

Gu Shiqiao's avatar
Gu Shiqiao committed
160
**English Interface Version:**
gushiqiao's avatar
gushiqiao committed
161
162
```cmd
python gradio_demo.py ^
Gu Shiqiao's avatar
Gu Shiqiao committed
163
    --model_path D:\models ^
gushiqiao's avatar
gushiqiao committed
164
165
166
167
    --server_name 127.0.0.1 ^
    --server_port 7862
```

Gu Shiqiao's avatar
Gu Shiqiao committed
168
**Chinese Interface Version:**
gushiqiao's avatar
gushiqiao committed
169
```cmd
Gu Shiqiao's avatar
Gu Shiqiao committed
170
171
python gradio_demo_zh.py ^
    --model_path D:\models ^
gushiqiao's avatar
gushiqiao committed
172
    --server_name 127.0.0.1 ^
gushiqiao's avatar
gushiqiao committed
173
174
175
    --server_port 7862
```

Gu Shiqiao's avatar
Gu Shiqiao committed
176
177
**💡 Tip**: Model type (wan2.1/wan2.2), task type (i2v/t2v), and specific model file selection are all configured in the Web interface.

gushiqiao's avatar
gushiqiao committed
178
179
180
181
## 📋 Command Line Parameters

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
Gu Shiqiao's avatar
Gu Shiqiao committed
182
| `--model_path` | str | ✅ | - | Model root directory path (directory containing all model files) |
gushiqiao's avatar
gushiqiao committed
183
184
| `--server_port` | int | ❌ | 7862 | Server port |
| `--server_name` | str | ❌ | 0.0.0.0 | Server IP address |
Gu Shiqiao's avatar
Gu Shiqiao committed
185
186
187
| `--output_dir` | str | ❌ | ./outputs | Output video save directory |

**💡 Note**: Model type (wan2.1/wan2.2), task type (i2v/t2v), and specific model file selection are all configured in the Web interface.
gushiqiao's avatar
gushiqiao committed
188
189
190

## 🎯 Features

Gu Shiqiao's avatar
Gu Shiqiao committed
191
192
193
194
195
196
197
198
199
### Model Configuration

- **Model Type**: Supports wan2.1 and wan2.2 model architectures
- **Task Type**: Supports Image-to-Video (i2v) and Text-to-Video (t2v) generation modes
- **Model Selection**: Frontend automatically identifies and filters available model files, supports automatic quantization precision detection
- **Encoder Configuration**: Supports selection of T5 text encoder, CLIP image encoder, and VAE decoder
- **Operator Selection**: Supports multiple attention operators and quantization matrix multiplication operators, system automatically sorts by installation status

### Input Parameters
gushiqiao's avatar
gushiqiao committed
200
201
202

- **Prompt**: Describe the expected video content
- **Negative Prompt**: Specify elements you don't want to appear
Gu Shiqiao's avatar
Gu Shiqiao committed
203
- **Input Image**: Upload input image required in i2v mode
gushiqiao's avatar
gushiqiao committed
204
205
- **Resolution**: Supports multiple preset resolutions (480p/540p/720p)
- **Random Seed**: Controls the randomness of generation results
Gu Shiqiao's avatar
Gu Shiqiao committed
206
207
208
- **Inference Steps**: Affects the balance between generation quality and speed (defaults to 4 steps for distilled models)

### Video Parameters
gushiqiao's avatar
gushiqiao committed
209
210
211

- **FPS**: Frames per second
- **Total Frames**: Video length
Gu Shiqiao's avatar
Gu Shiqiao committed
212
- **CFG Scale Factor**: Controls prompt influence strength (1-10, defaults to 1 for distilled models)
gushiqiao's avatar
gushiqiao committed
213
214
- **Distribution Shift**: Controls generation style deviation degree (0-10)

Gu Shiqiao's avatar
Gu Shiqiao committed
215
## 🔧 Auto-Configuration Feature
gushiqiao's avatar
gushiqiao committed
216

Gu Shiqiao's avatar
Gu Shiqiao committed
217
The system automatically configures optimal inference options based on your hardware configuration (GPU VRAM and CPU memory) without manual adjustment. The best configuration is automatically applied on startup, including:
gushiqiao's avatar
gushiqiao committed
218

Gu Shiqiao's avatar
Gu Shiqiao committed
219
220
221
222
- **GPU Memory Optimization**: Automatically enables CPU offloading, VAE tiling inference, etc. based on VRAM size
- **CPU Memory Optimization**: Automatically enables lazy loading, module unloading, etc. based on system memory
- **Operator Selection**: Automatically selects the best installed operators (sorted by priority)
- **Quantization Configuration**: Automatically detects and applies quantization precision based on model file names
gushiqiao's avatar
gushiqiao committed
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237


### Log Viewing

```bash
# View inference logs
tail -f inference_logs.log

# View GPU usage
nvidia-smi

# View system resources
htop
```

gushiqiao's avatar
gushiqiao committed
238
Welcome to submit Issues and Pull Requests to improve this project!
gushiqiao's avatar
gushiqiao committed
239
240

**Note**: Please comply with relevant laws and regulations when using videos generated by this tool, and do not use them for illegal purposes.