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

Add Initial Support for Running HunyuanVideo on Google Colab (Help Needed with OOM Errors) #138

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,36 @@ python3 gradio_server.py --flow-reverse
# SERVER_NAME=0.0.0.0 SERVER_PORT=8081 python3 gradio_server.py --flow-reverse
```


### Running on Google Colab
To run the Gradio Server on Google Colab, follow the steps described in the Download Pretrained Models section first, and then use the following commands:

```bash
# clone
!git clone https://github.com/tencent/HunyuanVideo.git
%cd HunyuanVideo

# setup
!python -m pip install "huggingface_hub[cli]"
!huggingface-cli download tencent/HunyuanVideo --local-dir ./ckpts
!huggingface-cli download xtuner/llava-llama-3-8b-v1_1-transformers --local-dir ./ckpts/llava-llama-3-8b-v1_1-transformers
!python hyvideo/utils/preprocess_text_encoder_tokenizer_utils.py --input_dir ckpts/llava-llama-3-8b-v1_1-transformers --output_dir ckpts/text_encoder
!huggingface-cli download openai/clip-vit-large-patch14 --local-dir ./ckpts/text_encoder_2
!pip install -r requirements.txt
!python -m pip install ninja
# Download and install pre-built flash-attention binaries
# For details, see: https://github.com/kun432/flash-attention-prebuild-wheels
!wget https://github.com/kun432/flash-attention-prebuild-wheels/releases/download/v0.0.0-test/flash_attn-2.6.3+cu121torch2.5-cp310-cp310-linux_x86_64.whl
!pip install --no-dependencies --upgrade flash_attn-2.6.3+cu121torch2.5-cp310-cp310-linux_x86_64.whl
!pip install gradio
!pip install loguru

# start
!python3 gradio_server.py --flow-reverse --share
```

This will provide you with a shareable link to the Gradio interface for generating videos from text prompts in the Colab environment.

### More Configurations

We list some more useful configurations for easy usage:
Expand Down
12 changes: 11 additions & 1 deletion gradio_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from datetime import datetime
import gradio as gr
import random
import sys

from hyvideo.utils.file_utils import save_videos_grid
from hyvideo.config import parse_args
Expand Down Expand Up @@ -135,7 +136,16 @@ def create_demo(model_path, save_path):
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
server_name = os.getenv("SERVER_NAME", "0.0.0.0")
server_port = int(os.getenv("SERVER_PORT", "8081"))

# Check if --share is specified in command line arguments without changing hyvideo/config.py
if "--share" in sys.argv:
sys.argv.remove("--share")
share_flag = True
else:
share_flag = False

args = parse_args()
print(args)

demo = create_demo(args.model_base, args.save_path)
demo.launch(server_name=server_name, server_port=server_port)
demo.launch(server_name=server_name, server_port=server_port, share=share_flag)