Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding hunyuan hf (support lora finetuning); unified hunyuan hf inference with quantization #135

Merged
merged 47 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a133b58
fix lora cp saving issue
BrianChen1129 Dec 19, 2024
3008adf
Merge branch 'main' of github.com:jzhang38/FastVideo-OSP
BrianChen1129 Dec 19, 2024
a3f8fc2
fix lora save issue
BrianChen1129 Dec 19, 2024
580575c
fix lora save issue
BrianChen1129 Dec 19, 2024
4c16991
Revert "fix lora save issue"
BrianChen1129 Dec 19, 2024
677efd9
fix lora save issue
BrianChen1129 Dec 19, 2024
48fd2d2
Merge branch 'main' of github.com:jzhang38/FastVideo-OSP into yq-lora…
BrianChen1129 Dec 20, 2024
c31f507
debug hunyuan hf sp
BrianChen1129 Dec 23, 2024
ac58b2f
test hunyuan hf
BrianChen1129 Dec 24, 2024
77b690c
add huanyuan hf inference and train
BrianChen1129 Dec 24, 2024
04c1610
support hunyuan hf lora
BrianChen1129 Dec 27, 2024
bfe0448
syn with main
BrianChen1129 Dec 27, 2024
594b65a
syn with main
BrianChen1129 Dec 27, 2024
36560eb
unified hunyuan hf
BrianChen1129 Dec 29, 2024
d25c235
unified hunyuan hf
BrianChen1129 Dec 29, 2024
557dbca
unified hunyuan hf
BrianChen1129 Dec 29, 2024
0c058c3
add lora
BrianChen1129 Jan 7, 2025
cbc52b0
syn with main
BrianChen1129 Jan 7, 2025
f35ea70
unify hunyuan hf inference
BrianChen1129 Jan 7, 2025
cad6e6d
unify hunyuan hf inference
BrianChen1129 Jan 7, 2025
1832042
syn with main
BrianChen1129 Jan 7, 2025
5d21b16
syn
BrianChen1129 Jan 7, 2025
1d7d637
syn
BrianChen1129 Jan 7, 2025
c1cf441
syn
BrianChen1129 Jan 7, 2025
22d499b
syn
BrianChen1129 Jan 7, 2025
e7ea0d7
syn
BrianChen1129 Jan 7, 2025
afe24e2
syn
BrianChen1129 Jan 7, 2025
41f8ac9
syn
BrianChen1129 Jan 8, 2025
3f2fc1a
fix train.py
BrianChen1129 Jan 12, 2025
32a7bb3
update README
BrianChen1129 Jan 12, 2025
79be9b5
syn
BrianChen1129 Jan 12, 2025
5af5b6a
add dataset preparation scripts
BrianChen1129 Jan 13, 2025
54d1e5d
format
BrianChen1129 Jan 13, 2025
2017c08
syn with main; add readme
BrianChen1129 Jan 13, 2025
26e7dc9
syn with main; add readme
BrianChen1129 Jan 13, 2025
9109210
ready for lora release
BrianChen1129 Jan 13, 2025
e357df9
format check
BrianChen1129 Jan 13, 2025
6bb0705
format check
BrianChen1129 Jan 13, 2025
aedb4a2
format check
BrianChen1129 Jan 13, 2025
5a086e9
format check
BrianChen1129 Jan 13, 2025
e819bdb
format check
BrianChen1129 Jan 13, 2025
7fcc414
scripts clean
BrianChen1129 Jan 13, 2025
1d0d787
fix shift issue in scripts
BrianChen1129 Jan 13, 2025
f7c9a37
add change log
BrianChen1129 Jan 13, 2025
a7e5aac
fix huynuan ft scripts val steps
BrianChen1129 Jan 13, 2025
db92841
pr version revision
BrianChen1129 Jan 14, 2025
a44972b
ready for lora pr
BrianChen1129 Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Comparison between original FastHunyuan, LLM-INT8 quantized FastHunyuan and NF4
https://github.com/user-attachments/assets/cf89efb5-5f68-4949-a085-f41c1ef26c94

## Change Log
- ```2025/01/13```: Support Lora finetuning for HunyuanVideo.
- ```2024/12/25```: Enable single 4090 inference for `FastHunyuan`, please rerun the installation steps to update the environment.
- ```2024/12/17```: `FastVideo` v1.0 is released.

Expand All @@ -55,7 +56,7 @@ We now support NF4 and LLM-INT8 quantized inference using BitsAndBytes for FastH
# Download the model weight
python scripts/huggingface/download_hf.py --repo_id=FastVideo/FastHunyuan-diffusers --local_dir=data/FastHunyuan-diffusers --repo_type=model
# CLI inference
bash scripts/inference/inference_diffusers_hunyuan.sh
bash scripts/inference/inference_hunyuan_hf_quantization.sh
```
For more information about the VRAM requirements for BitsAndBytes quantization, please refer to the table below (timing measured on an H100 GPU):

Expand Down Expand Up @@ -120,15 +121,44 @@ Then you can run the finetune with:
bash scripts/finetune/finetune_mochi.sh # for mochi
```
**Note that for finetuning, we did not tune the hyperparameters in the provided script**
### ⚡ Lora Finetune
Currently, we only provide Lora Finetune for Mochi model, the command for Lora Finetune is
### ⚡ Lora Finetune
Demos and prompts of Black-Myth-Wukong can be found in [here](https://huggingface.co/FastVideo/Hunyuan-Black-Myth-Wukong-lora-weight). You can download the Lora weight through:
```bash
python scripts/huggingface/download_hf.py --repo_id=FastVideo/Hunyuan-Black-Myth-Wukong-lora-weight --local_dir=data/Hunyuan-Black-Myth-Wukong-lora-weight --repo_type=model
```
Currently, both Mochi and Hunyuan models support Lora finetuning through diffusers. To generate personalized videos from your own dataset, you'll need to follow three main steps: dataset preparation, finetuning, and inference.

#### Dataset Preparation
We provide scripts to better help you get started to train on your own characters!
You can run this to organize your dataset to get the videos2caption.json before preprocess. Specify your video folder and corresponding caption folder(Caption files should be .txt files and have the same name with its video):
```
python scripts/dataset_preparation/prepare_json_file.py --video_dir data/input_videos/ --prompt_dir data/captions/ --output_path data/output_folder/videos2caption.json --verbose
```
Also, we provide script to resize your videos:
```
python scripts/data_preprocess/resize_videos.py \
--input_dir data/raw_videos/ \
--output_dir data/resized_videos/ \
--width 1280 \
--height 720 \
--fps 30
```
#### Finetuning
After basic dataset preparation and preprocess, you can start to finetune your model using Lora:
```
bash scripts/finetune/finetune_hunyuan_hf_lora.sh
bash scripts/finetune/finetune_mochi_lora.sh
```
### Minimum Hardware Requirement
#### Finetuning
For inference with Lora checkpoint, you can run the following scripts with Additional parameter --lora_checkpoint_dir:
```
bash scripts/inference/inference_hunyuan_hf.sh
bash scripts/inference/inference_mochi_hf.sh
```
#### Minimum Hardware Requirement
- 40 GB GPU memory each for 2 GPUs with lora
- 30 GB GPU memory each for 2 GPUs with CPU offload and lora.
### Finetune with Both Image and Video
#### Finetune with Both Image and Video
Our codebase support finetuning with both image and video.
```bash
bash scripts/finetune/finetune_hunyuan.sh
Expand Down
Loading
Loading