import io import modal import os import subprocess import sys import time import shutil…
- User
import io import modal import os import subprocess import sys import time import shutil from datetime import datetime from typing import Dict, List, Tuple
--- Modal Setup ---
app = modal.App("hunyuan-training") volume = modal.Volume.from_name( "hunyuan-volume", create_if_missing=True ) image = ( modal.Image.from_registry("nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04") .apt_install("git", "wget", "curl", "build-essential") .pip_install( "tomli", "toml", "diffusers", "transformers", "accelerate", "safetensors", "tensorboard", "ftfy", "protobuf==3.20.1", "deepspeed", "huggingface_hub[hf_transfer]", ) .run_commands( "pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 torchaudio==2.0.2+cu118 --extra-index-url https://download.pytorch.org/whl/cu118" ) .env({ "HF_HUB_ENABLE_HF_TRANSFER": "1", "CUDA_HOME": "/usr/local/cuda" }) )
--- Constants ---
GIT_REPO = "https://github.com/tdrussell/diffusion-pipe.git" REMOTE_ROOT = "/root/volume"
--- Helper Functions ---
@app.function(image=image, volumes={REMOTE_ROOT: volume}) def hf_download_repo(repo_id: str, model_type: str, ignore_patterns: List[str] = None): from huggingface_hub import snapshot_download
snapshot_download( repo_id=repo_id, local_dir=f"/root/volume/models/{model_type}", ignore_patterns=ignore_patterns or [], ) print(f"Repository {repo_id} downloaded to /root/volume/models/{model_type}")@app.function(image=image, volumes={REMOTE_ROOT: volume}) def hf_download_file(repo_id: str, filename: str, model_type: str): from huggingface_hub import hf_hub_download
hf_hub_download( repo_id=repo_id, filename=filename, local_dir=f"/root/volume/models/{model_type}", ) print(f"File {filename} from {repo_id} downloaded to /root/volume/models/{model_type}")--- Modal Functions ---
@app.function(image=image, volumes={REMOTE_ROOT: volume}) def download_models(): models_to_download_from_hf_repos: List[Tuple[str, str, List[str]]] = [ ("Kijai/llava-llama-3-8b-text-encoder-tokenizer", "llm"), ("openai/clip-vit-large-patch14", "clip", ["flax_model.msgpack", "pytorch_model.bin", "tf_model.h5"]), # Exclude these files ]
models_to_download_from_hf_files: List[Tuple[str, str, str]] = [ ("Kijai/HunyuanVideo_comfy", "hunyuan_video_720_cfgdistill_fp8_e4m3fn.safetensors", "hunyuan"), ("Kijai/HunyuanVideo_comfy", "hunyuan_video_vae_bf16.safetensors", "hunyuan"), ] # Download entire HF repos print("Downloading entire Hugging Face repositories...") for repo in models_to_download_from_hf_repos: if len(repo) == 3: repo_id, model_type, ignore_patterns = repo elif len(repo) == 2: repo_id, model_type = repo ignore_patterns = [] else: raise ValueError(f"Unexpected tuple length: {len(repo)}") hf_download_repo.remote(repo_id, model_type, ignore_patterns) # Download individual files from Hugging Face print("Downloading individual files from Hugging Face...") for repo_id, filename, model_type in models_to_download_from_hf_files: hf_download_file.remote(repo_id, filename, model_type) - Assistant