Artiprocher commited on
Commit
3b93b22
·
verified ·
1 Parent(s): 5d00781

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +143 -68
README.md CHANGED
@@ -6,46 +6,26 @@ frameworks:
6
  - ""
7
  base_model_relation: quantized
8
  ---
9
- # MiniMax-H3-NF4
10
-
11
- The **NF4 quantized version** of the MiniMax-H3 multimodal audio-video generation model (4-bit quantized via `bitsandbytes`), designed for use with [DiffSynth-Studio](https://github.com/modelscope/DiffSynth-Studio). Enables joint "text/image/video/audio → video + audio" generation on machines with limited GPU memory or system RAM.
12
-
13
- ## File Overview
14
-
15
- | File | Size | Function | Shared? |
16
- |---|---|---|---|
17
- | `minimax-h3-fl2va-nf4.safetensors` | ~16 GB | DiT backbone for **FL2VA** task (text / start-end keyframes → video+audio) | FL2VA only |
18
- | `minimax-h3-ref2va-nf4.safetensors` | ~16 GB | DiT backbone for **Ref2VA** task (reference image/video/audio → video+audio) | Ref2VA only |
19
- | `minimax-h3-text-encoder-nf4.safetensors` | ~15 GB | Qwen3-VL text/visual encoder | Shared across tasks |
20
- | `video_vae_nf4.safetensors` | ~1.6 GB | Video VAE decoder | Shared across tasks |
21
- | `audio_vae_nf4.safetensors` | ~271 MB | Audio VAE decoder | Shared across tasks |
22
-
23
- > Note: Choose one DiT model depending on the task; the other three components (text_encoder / video_vae / audio_vae) are shared between both tasks. The framework automatically identifies component types and applies appropriate quantization configurations (including bf16 fallback for a few quantization-sensitive layers) based on file hashes—no manual configuration required.
24
-
25
- ## System Requirements
26
 
27
- - CUDA GPU (NF4 dequantization relies on `bitsandbytes` CUDA kernels)
28
- - Processor and tokenizer must be obtained from the original repository `MiniMax/MiniMax-H3` (see `processor_config` below)
29
 
30
- ### Install DiffSynth-Studio
31
 
32
- Install from source (recommended, ensures latest MiniMax-H3 support), including NF4 quantization dependencies:
33
 
34
- ```bash
35
  git clone https://github.com/modelscope/DiffSynth-Studio.git
36
  cd DiffSynth-Studio
37
- pip install -e ".[quant]"
38
  ```
39
 
40
- ## Usage (Disk Offload, Low VRAM & RAM)
41
-
42
- Weights remain on disk and are streamed into GPU layer-by-layer during inference, minimizing VRAM usage. **Text-to-video+audio (t2v) can run with as little as ~6 GB VRAM.**
43
 
44
- > `vram_limit` (in GB) sets the VRAM threshold—lower values reduce memory usage at the cost of speed.
45
 
46
- > If you have sufficient CPU RAM, set `offload_device` / `offload_dtype` to `"cpu"` / `torch.bfloat16` (i.e., CPU offload). This keeps weights in main memory instead of reading from disk, resulting in faster performance; all other code remains unchanged.
47
 
48
- ### FL2VA Text / Start-End Keyframes → Video + Audio
49
 
50
  ```python
51
  import torch
@@ -54,7 +34,6 @@ from diffsynth.utils.data.audio_video import write_video_audio
54
  from modelscope import dataset_snapshot_download
55
  from PIL import Image
56
 
57
-
58
  vram_config = {
59
  "offload_dtype": "disk",
60
  "offload_device": "disk",
@@ -78,7 +57,6 @@ pipe = MiniMaxH3Pipeline.from_pretrained(
78
  vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 2,
79
  )
80
 
81
- # Text -> Video + Audio
82
  prompt = "A girl is very happy, she is speaking in english: “I enjoy working with Diffsynth-Studio, it's a perfect framework.”"
83
  video, audio = pipe(
84
  prompt=prompt,
@@ -88,33 +66,13 @@ write_video_audio(
88
  video=video, audio=audio,
89
  output_path="t2va.mp4", fps=24, audio_sample_rate=32000,
90
  )
91
-
92
- # Text + First Frame + Last Frame -> Video + Audio
93
- dataset_snapshot_download(dataset_id="DiffSynth-Studio/diffsynth_example_dataset", local_dir="data/diffsynth_example_dataset", allow_file_pattern="minimax_h3/MiniMax-H3-FL2VA/*")
94
- first_frame = Image.open("data/diffsynth_example_dataset/minimax_h3/MiniMax-H3-FL2VA/first.png")
95
- last_frame = Image.open("data/diffsynth_example_dataset/minimax_h3/MiniMax-H3-FL2VA/last.png")
96
- prompt = "A short indoor drama scene of a family argument, vertical video format with short-form video aesthetics, realistic live-action performance, Chinese household or small restaurant interior setting, warm lighting, red decorations and calligraphy scrolls in the background, shallow depth of field, intense emotions, fast-paced editing. Performance requirements: authentic short-video acting style, no exaggerated theatrical tone. The man speaks with anger, grievance, and urgent rebuttal, saying 'What exactly do you want?' The middle-aged woman speaks sharply, assertively, and aggressively demanding, saying 'You must pay up!' There should be strong confrontation between them, escalating in intensity. Visual style: vertical 9:16 aspect ratio, smartphone short-video look, realistic live-action footage, shallow depth of field, warm indoor lighting, mostly medium and close-up shots, frequent shot-reverse-shot editing, background should remain everyday and realistic—no sci-fi, no historical costumes, no animation-like visuals. No subtitles, text, platform watermarks, or overlays should appear in the画面."
97
- video, audio = pipe(
98
- prompt=prompt,
99
- height=832, width=480, num_frames=124, num_inference_steps=50, seed=0,
100
- keyframes=[first_frame, last_frame], keyframe_indices=[0, -1],
101
- )
102
- write_video_audio(
103
- video=video, audio=audio,
104
- output_path="fl2va.mp4", fps=24, audio_sample_rate=32000,
105
- )
106
  ```
107
 
108
- ### Ref2VA Reference Image/Video/Audio → Video + Audio
109
 
110
- Four types of references are supported, which can be combined within a single list (`video` is silent; for videos with sound, use `video_audio`):
111
 
112
- ```python
113
- {"type": "image", "image": PIL.Image}
114
- {"type": "video", "video": list[PIL.Image]} # silent
115
- {"type": "audio", "audio": Tensor[C, L], "sample_rate": int}
116
- {"type": "video_audio", "video": list[PIL.Image], "audio": Tensor[C, L], "sample_rate": int}
117
- ```
118
 
119
  ```python
120
  import torch
@@ -169,7 +127,7 @@ pipe = MiniMaxH3Pipeline.from_pretrained(
169
  # Text + Reference Image -> Video + Audio
170
  dataset_snapshot_download(dataset_id="DiffSynth-Studio/diffsynth_example_dataset", local_dir="data/diffsynth_example_dataset", allow_file_pattern="minimax_h3/MiniMax-H3-Ref2VA/*")
171
  ref_image = Image.open("data/diffsynth_example_dataset/minimax_h3/MiniMax-H3-Ref2VA/0.png").convert("RGB")
172
- prompt = "A website page, UI design of a web page, web animation. The video demonstrates a smooth scrolling effect downward. A highly dynamic and energetic product official website-style landing page UI/UX demonstration video, with the main focus being product image 1. The layout features bold, slanted, oversized sans-serif typography. The background includes fast-paced dynamic lighting effects intertwined with dark carbon fiber or sporty breathable mesh textures in motion. The video showcases a tightly paced, powerful downward scroll effect, along with strong visual interactions such as significant zoom-in and color inversion when hovering over UI elements."
173
  video, audio = pipe(
174
  prompt=prompt,
175
  height=480, width=832, num_frames=124, num_inference_steps=50, seed=42,
@@ -198,20 +156,137 @@ write_video_audio(
198
  )
199
  ```
200
 
201
- ## Common Parameters
 
 
202
 
203
- - `height` / `width`: Resolution, e.g., `480x832` (landscape) or `832x480` (portrait).
204
- - `num_frames`: Number of frames, must satisfy `num_frames % 17 == 5` (e.g., 124).
205
- - `num_inference_steps`: Denoising steps, example uses 50.
206
- - `keyframes` / `keyframe_indices`: FL2VA control for start and end frames (`[0, -1]` means first and last frame).
207
- - `references`: Ref2VA reference list, elements are `{"type": "image|video|audio|video_audio", ...}`.
208
- - Output: `write_video_audio(video, audio, output_path, fps=24, audio_sample_rate=32000)`.
209
 
210
- ## Example Scripts
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
 
212
- Fully runnable scripts in the repository (examples in this README are derived from these):
213
 
214
- - `examples/minimax_h3/model_inference_low_vram/MiniMax-H3-NF4-FL2VA.py`
215
- - `examples/minimax_h3/model_inference_low_vram/MiniMax-H3-NF4-Ref2VA.py`
216
- - `examples/minimax_h3/model_inference/MiniMax-H3-NF4-FL2VA.py` (CPU offload)
217
- - `examples/minimax_h3/model_inference/MiniMax-H3-NF4-Ref2VA.py` (CPU offload)
 
6
  - ""
7
  base_model_relation: quantized
8
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ # MiniMax-H3-NF4
 
11
 
12
+ This model is the **NF4 quantized version** of the video generation model [MiniMax-H3](https://modelscope.cn/models/MiniMax/MiniMax-H3). It utilizes the `bitsandbytes` 4-bit quantization scheme and is designed to be used with [DiffSynth-Studio](https://github.com/modelscope/DiffSynth-Studio), enabling model inference on devices with limited VRAM and RAM.
13
 
14
+ ## Environment Setup
15
 
16
+ ```shell
17
  git clone https://github.com/modelscope/DiffSynth-Studio.git
18
  cd DiffSynth-Studio
19
+ pip install -e ".[all]"
20
  ```
21
 
22
+ ## Inference Code
 
 
23
 
24
+ ### Enable VRAM Management
25
 
26
+ Run the following code to perform inference using DiffSynth-Studio. VRAM management will be automatically enabled. The actual VRAM usage depends on the available VRAM on your GPU; a minimum of 10GB VRAM is required to run.
27
 
28
+ #### FL2VA (Text-to-Video/Audio):
29
 
30
  ```python
31
  import torch
 
34
  from modelscope import dataset_snapshot_download
35
  from PIL import Image
36
 
 
37
  vram_config = {
38
  "offload_dtype": "disk",
39
  "offload_device": "disk",
 
57
  vram_limit=torch.cuda.mem_get_info("cuda")[1] / (1024 ** 3) - 2,
58
  )
59
 
 
60
  prompt = "A girl is very happy, she is speaking in english: “I enjoy working with Diffsynth-Studio, it's a perfect framework.”"
61
  video, audio = pipe(
62
  prompt=prompt,
 
66
  video=video, audio=audio,
67
  output_path="t2va.mp4", fps=24, audio_sample_rate=32000,
68
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  ```
70
 
71
+ #### Ref2VA (Reference-to-Video/Audio):
72
 
73
+ <details>
74
 
75
+ <summary>Expand Code</summary>
 
 
 
 
 
76
 
77
  ```python
78
  import torch
 
127
  # Text + Reference Image -> Video + Audio
128
  dataset_snapshot_download(dataset_id="DiffSynth-Studio/diffsynth_example_dataset", local_dir="data/diffsynth_example_dataset", allow_file_pattern="minimax_h3/MiniMax-H3-Ref2VA/*")
129
  ref_image = Image.open("data/diffsynth_example_dataset/minimax_h3/MiniMax-H3-Ref2VA/0.png").convert("RGB")
130
+ prompt = "A website page, website UI design, website animation, video showing smooth webpage scrolling effect. A highly explosive and dynamic product official website style product landing page UI/UX demo video, the core display subject is product image 1. The page uses bold, powerful, tilted oversized sans-serif fonts for flamboyant typography. The background features dynamic light and shadow with extreme speed sense, dark carbon fiber or sports breathable mesh textures interweaving and changing. The video shows a tight-paced, powerful webpage downward scrolling effect, as well as strong visual zoom and color inversion UI interaction actions when hovering the mouse."
131
  video, audio = pipe(
132
  prompt=prompt,
133
  height=480, width=832, num_frames=124, num_inference_steps=50, seed=42,
 
156
  )
157
  ```
158
 
159
+ </details>
160
+
161
+ ### Extreme Hardware Optimization
162
 
163
+ If your computing device has extremely limited performance, we support enabling direct disk-to-VRAM loading. With this configuration, tensors in the model are loaded from disk to VRAM one by one according to the computation order. This allows the model to run with only 10GB of RAM:
 
 
 
 
 
164
 
165
+ ```diff
166
+ vram_config = {
167
+ + "offload_dtype": "disk",
168
+ + "offload_device": "disk",
169
+ + "onload_dtype": "disk",
170
+ + "onload_device": "disk",
171
+ + "preparing_dtype": "disk",
172
+ + "preparing_device": "disk",
173
+ + "computation_dtype": torch.bfloat16,
174
+ + "computation_device": "cuda",
175
+ }
176
+ pipe = MiniMaxH3Pipeline.from_pretrained(
177
+ torch_dtype=torch.bfloat16,
178
+ device="cuda",
179
+ model_configs=...,
180
+ processor_config=...,
181
+ + vram_limit=0,
182
+ )
183
+ ```
184
+
185
+ We also support running model inference on Mac M-series chips, although this is not recommended:
186
+
187
+ ```diff
188
+ vram_config = {
189
+ + "offload_dtype": "disk",
190
+ + "offload_device": "disk",
191
+ + "onload_dtype": "disk",
192
+ + "onload_device": "disk",
193
+ + "preparing_dtype": "disk",
194
+ + "preparing_device": "disk",
195
+ + "computation_dtype": torch.bfloat16,
196
+ + "computation_device": "mps",
197
+ }
198
+ pipe = MiniMaxH3Pipeline.from_pretrained(
199
+ torch_dtype=torch.bfloat16,
200
+ device="mps",
201
+ model_configs=...,
202
+ processor_config=...,
203
+ + vram_limit=0,
204
+ )
205
+ ```
206
+
207
+ ## Training Code
208
+
209
+ This quantized model supports LoRA training. Please follow the steps below to start the training program.
210
+
211
+ Download the sample dataset:
212
+
213
+ ```shell
214
+ modelscope download --dataset DiffSynth-Studio/diffsynth_example_dataset --include "minimax_h3/MiniMax-H3-FL2VA/*" --local_dir ./data/diffsynth_example_dataset
215
+ ```
216
+
217
+ **Training configuration suitable for Data Center GPUs (e.g., Nvidia H20):** Run the following script to start the LoRA training program. Requires 48GB VRAM.
218
+
219
+ ```shell
220
+ accelerate launch examples/minimax_h3/model_training/train.py \
221
+ --dataset_base_path data/diffsynth_example_dataset/minimax_h3/MiniMax-H3-FL2VA \
222
+ --dataset_metadata_path data/diffsynth_example_dataset/minimax_h3/MiniMax-H3-FL2VA/metadata.csv \
223
+ --data_file_keys "video,input_audio" \
224
+ --extra_inputs "input_audio" \
225
+ --height 480 \
226
+ --width 832 \
227
+ --num_frames 124 \
228
+ --dataset_repeat 100 \
229
+ --model_id_with_origin_paths "DiffSynth-Studio/MiniMax-H3-NF4:minimax-h3-text-encoder-nf4.safetensors,DiffSynth-Studio/MiniMax-H3-NF4:minimax-h3-fl2va-nf4.safetensors,DiffSynth-Studio/MiniMax-H3-NF4:video_vae_nf4.safetensors,DiffSynth-Studio/MiniMax-H3-NF4:audio_vae_nf4.safetensors" \
230
+ --learning_rate 1e-4 \
231
+ --num_epochs 5 \
232
+ --remove_prefix_in_ckpt "pipe.dit." \
233
+ --output_path "./models/train/MiniMax-H3-T2VA-nf4" \
234
+ --lora_base_model "dit" \
235
+ --lora_target_modules "qkv_proj,out_proj" \
236
+ --lora_rank 32 \
237
+ --use_gradient_checkpointing \
238
+ --find_unused_parameters
239
+ ```
240
+
241
+ **Training configuration suitable for Consumer GPUs (e.g., Nvidia RTX 4090):** Run the following scripts to start two-stage split training with gradient checkpointing offload. Requires 24GB VRAM.
242
+
243
+ ```shell
244
+ accelerate launch examples/minimax_h3/model_training/train.py \
245
+ --dataset_base_path data/diffsynth_example_dataset/minimax_h3/MiniMax-H3-FL2VA \
246
+ --dataset_metadata_path data/diffsynth_example_dataset/minimax_h3/MiniMax-H3-FL2VA/metadata.csv \
247
+ --data_file_keys "video,input_audio" \
248
+ --extra_inputs "input_audio" \
249
+ --height 480 \
250
+ --width 832 \
251
+ --num_frames 124 \
252
+ --dataset_repeat 1 \
253
+ --model_id_with_origin_paths "DiffSynth-Studio/MiniMax-H3-NF4:minimax-h3-text-encoder-nf4.safetensors,DiffSynth-Studio/MiniMax-H3-NF4:video_vae_nf4.safetensors,DiffSynth-Studio/MiniMax-H3-NF4:audio_vae_nf4.safetensors" \
254
+ --learning_rate 1e-4 \
255
+ --num_epochs 1 \
256
+ --remove_prefix_in_ckpt "pipe.dit." \
257
+ --output_path "./models/train/MiniMax-H3-T2VA-nf4-split-cache" \
258
+ --lora_base_model "dit" \
259
+ --lora_target_modules "qkv_proj,out_proj" \
260
+ --lora_rank 32 \
261
+ --use_gradient_checkpointing \
262
+ --use_gradient_checkpointing_offload \
263
+ --task "sft:data_process"
264
+
265
+ accelerate launch examples/minimax_h3/model_training/train.py \
266
+ --dataset_base_path "./models/train/MiniMax-H3-T2VA-nf4-split-cache" \
267
+ --data_file_keys "video,input_audio" \
268
+ --extra_inputs "input_audio" \
269
+ --height 480 \
270
+ --width 832 \
271
+ --num_frames 124 \
272
+ --dataset_repeat 100 \
273
+ --model_id_with_origin_paths "DiffSynth-Studio/MiniMax-H3-NF4:minimax-h3-fl2va-nf4.safetensors" \
274
+ --learning_rate 1e-4 \
275
+ --num_epochs 5 \
276
+ --remove_prefix_in_ckpt "pipe.dit." \
277
+ --output_path "./models/train/MiniMax-H3-T2VA-nf4" \
278
+ --lora_base_model "dit" \
279
+ --lora_target_modules "qkv_proj,out_proj" \
280
+ --lora_rank 32 \
281
+ --use_gradient_checkpointing \
282
+ --use_gradient_checkpointing_offload \
283
+ --find_unused_parameters \
284
+ --task "sft:train"
285
+ ```
286
 
287
+ ## References
288
 
289
+ * DiffSynth-Studio Documentation: [Minimax-H3](https://diffsynth-studio-doc.readthedocs.io/en/latest/Model_Details/MiniMax-H3.html)
290
+ * DiffSynth-Studio Documentation: [VRAM Management](https://diffsynth-studio-doc.readthedocs.io/en/latest/Pipeline_Usage/VRAM_management.html)
291
+ * DiffSynth-Studio Documentation: [Two-Stage Split Training](https://diffsynth-studio-doc.readthedocs.io/en/latest/Training/Split_Training.html)
292
+ * DiffSynth-Studio Documentation: [Low VRAM Training](https://diffsynth-studio-doc.readthedocs.io/en/latest/Pipeline_Usage/Model_Training.html#low-vram-training)