### Setup Environment with Docker Source: https://github.com/aigc-apps/easyanimate/blob/main/easyanimate/video_caption/README.md Commands to pull the EasyAnimate Docker image, run the container, and clone the repository. ```shell # pull image docker pull mybigpai-public-registry.cn-beijing.cr.aliyuncs.com/easycv/torch_cuda:easyanimate # enter image docker run -it -p 7860:7860 --network host --gpus all --security-opt seccomp:unconfined --shm-size 200g mybigpai-public-registry.cn-beijing.cr.aliyuncs.com/easycv/torch_cuda:easyanimate # clone code git clone https://github.com/aigc-apps/EasyAnimate.git # enter video_caption cd EasyAnimate/easyanimate/video_caption ``` -------------------------------- ### Manually install EasyAnimate and dependencies Source: https://github.com/aigc-apps/easyanimate/blob/main/comfyui/README.md Execute these commands in the terminal to clone the repository and its required helper nodes, then install the necessary Python dependencies. ```bash cd ComfyUI/custom_nodes/ # Git clone the easyanimate itself git clone https://github.com/aigc-apps/EasyAnimate.git # Git clone the video outout node git clone https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite.git git clone https://github.com/kijai/ComfyUI-KJNodes.git cd EasyAnimate/ pip install -r comfyui/requirements.txt ``` -------------------------------- ### Deploy Local OpenAI Compatible Server Source: https://github.com/aigc-apps/easyanimate/blob/main/easyanimate/video_caption/README.md Start a local vLLM server to host the LLM for prompt processing. ```shell # Meta-Llama-3-8B-Instruct is sufficient for this task. # Download it from https://huggingface.co/NousResearch/Meta-Llama-3-8B-Instruct or https://www.modelscope.cn/models/LLM-Research/Meta-Llama-3-8B-Instruct to /path/to/your_llm # deploy the OpenAI compatible server python -m vllm.entrypoints.openai.api_server serve /path/to/your_llm --dtype auto --api-key "your_api_key" ``` -------------------------------- ### Dataset JSON Configuration Source: https://github.com/aigc-apps/easyanimate/blob/main/easyanimate/vae/README.md Examples of defining dataset entries using relative or absolute file paths. ```json [ { "file_path": "videos/00000001.mp4", "text": "A group of young men in suits and sunglasses are walking down a city street.", "type": "video" }, { "file_path": "train/00000001.jpg", "text": "A group of young men in suits and sunglasses are walking down a city street.", "type": "image" }, ..... ] ``` ```json [ { "file_path": "/mnt/data/videos/00000001.mp4", "text": "A group of young men in suits and sunglasses are walking down a city street.", "type": "video" }, { "file_path": "/mnt/data/train/00000001.jpg", "text": "A group of young men in suits and sunglasses are walking down a city street.", "type": "image" }, ..... ] ``` -------------------------------- ### Install HPS Reward Model Dependencies Source: https://github.com/aigc-apps/easyanimate/blob/main/scripts/README_TRAIN_REWARD.md Installs the hpsv2 package and applies necessary patches to the open_clip factory and vocabulary files. ```bash # For HPS reward model only pip install hpsv2 site_packages=$(python -c "import site; print(site.getsitepackages()[0])") wget -O $site_packages/hpsv2/src/open_clip/factory.py https://pai-aigc-photog.oss-cn-hangzhou.aliyuncs.com/easyanimate/package/patches/hpsv2_src_open_clip_factory_patches.py wget -O $site_packages/hpsv2/src/open_clip/ https://github.com/tgxs002/HPSv2/raw/refs/heads/master/hpsv2/src/open_clip/bpe_simple_vocab_16e6.txt.gz ``` -------------------------------- ### Initialize EasyAnimate via Docker Source: https://github.com/aigc-apps/easyanimate/blob/main/README.md Commands to pull the image, launch the container, and prepare the local directory structure for model weights. ```bash # pull image docker pull mybigpai-public-registry.cn-beijing.cr.aliyuncs.com/easycv/torch_cuda:easyanimate # enter image docker run -it -p 7860:7860 --network host --gpus all --security-opt seccomp:unconfined --shm-size 200g mybigpai-public-registry.cn-beijing.cr.aliyuncs.com/easycv/torch_cuda:easyanimate # clone code git clone https://github.com/aigc-apps/EasyAnimate.git # enter EasyAnimate's dir cd EasyAnimate # download weights mkdir models/Diffusion_Transformer mkdir models/Motion_Module mkdir models/Personalized_Model # Please use the hugginface link or modelscope link to download the EasyAnimateV5.1 model. # https://huggingface.co/alibaba-pai/EasyAnimateV5.1-12b-zh-InP # https://modelscope.cn/models/PAI/EasyAnimateV5.1-12b-zh-InP # https://huggingface.co/alibaba-pai/EasyAnimateV5.1-12b-zh # https://modelscope.cn/models/PAI/EasyAnimateV5.1-12b-zh ``` -------------------------------- ### Execute Training Script Source: https://github.com/aigc-apps/easyanimate/blob/main/README.md Command to initiate the training process after configuring environment variables. ```bash sh scripts/train.sh ``` -------------------------------- ### Run Beautiful Prompt with Local Server Source: https://github.com/aigc-apps/easyanimate/blob/main/easyanimate/video_caption/README.md Execute the beautification script against a locally deployed vLLM server. ```shell python -m beautiful_prompt.py \ --model /path/to/your_llm \ --prompt "your_prompt" \ --base_url "http://localhost:8000/v1" \ --api_key "your_api_key" ``` -------------------------------- ### Train EasyAnimateV5.1-InP without DeepSpeed Source: https://github.com/aigc-apps/easyanimate/blob/main/scripts/README_TRAIN.md Launches a training job for the EasyAnimateV5.1-InP model using standard accelerate settings. ```sh export MODEL_NAME="models/Diffusion_Transformer/EasyAnimateV5.1-12b-zh-InP" export DATASET_NAME="datasets/internal_datasets/" export DATASET_META_NAME="datasets/internal_datasets/metadata.json" export NCCL_IB_DISABLE=1 export NCCL_P2P_DISABLE=1 NCCL_DEBUG=INFO # When train model with multi machines, use "--config_file accelerate.yaml" instead of "--mixed_precision='bf16'". accelerate launch --mixed_precision="bf16" scripts/train.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --train_data_dir=$DATASET_NAME \ --train_data_meta=$DATASET_META_NAME \ --config_path "config/easyanimate_video_v5.1_magvit_qwen.yaml" \ --image_sample_size=1024 \ --video_sample_size=256 \ --token_sample_size=512 \ --video_sample_stride=3 \ --video_sample_n_frames=49 \ --train_batch_size=1 \ --video_repeat=1 \ --gradient_accumulation_steps=1 \ --dataloader_num_workers=8 \ --num_train_epochs=100 \ --checkpointing_steps=100 \ --learning_rate=2e-05 \ --lr_scheduler="constant_with_warmup" \ --lr_warmup_steps=100 \ --seed=42 \ --output_dir="output_dir" \ --gradient_checkpointing \ --mixed_precision="bf16" \ --adam_weight_decay=5e-3 \ --adam_epsilon=1e-10 \ --vae_mini_batch=1 \ --max_grad_norm=0.05 \ --random_hw_adapt \ --training_with_video_token_length \ --loss_type="flow" \ --enable_bucket \ --uniform_sampling \ --train_mode="inpaint" \ --trainable_modules "." ``` -------------------------------- ### EasyAnimateV5.1 Model Directory Structure Source: https://github.com/aigc-apps/easyanimate/blob/main/README.md Recommended file system layout for organizing EasyAnimateV5.1 model weights and personalized models. ```text 📦 models/ ├── 📂 Diffusion_Transformer/ │ ├── 📂 EasyAnimateV5.1-12b-zh-InP/ │ └── 📂 EasyAnimateV5.1-12b-zh/ ├── 📂 Personalized_Model/ │ └── your trained trainformer model / your trained lora model (for UI load) ``` -------------------------------- ### Run VAE Training Script Source: https://github.com/aigc-apps/easyanimate/blob/main/easyanimate/vae/README.md Command to execute the VAE training process. ```bash sh scripts/train_vae.sh ``` -------------------------------- ### Launch EasyAnimateV2 Training Source: https://github.com/aigc-apps/easyanimate/blob/main/scripts/README_TRAIN.md Executes the training script for the obsolete EasyAnimateV2 model using accelerate. ```sh export MODEL_NAME="models/Diffusion_Transformer/EasyAnimateV2-XL-2-512x512" export DATASET_NAME="datasets/internal_datasets/" export DATASET_META_NAME="datasets/internal_datasets/metadata.json" export NCCL_IB_DISABLE=1 export NCCL_P2P_DISABLE=1 NCCL_DEBUG=INFO # When train model with multi machines, use "--config_file accelerate.yaml" instead of "--mixed_precision='bf16'". accelerate launch --mixed_precision="bf16" scripts/train.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --train_data_dir=$DATASET_NAME \ --train_data_meta=$DATASET_META_NAME \ --config_path "config/easyanimate_video_v2_magvit_motion_module.yaml" \ --image_sample_size=512 \ --video_sample_size=512 \ --video_sample_stride=1 \ --video_sample_n_frames=144 \ --train_batch_size=1 \ --video_repeat=1 \ --gradient_accumulation_steps=1 \ --dataloader_num_workers=8 \ --num_train_epochs=100 \ --checkpointing_steps=500 \ --learning_rate=2e-05 \ --lr_scheduler="constant_with_warmup" \ --lr_warmup_steps=100 \ --seed=42 \ --output_dir="output_dir" \ --enable_xformers_memory_efficient_attention \ --gradient_checkpointing \ --mixed_precision="bf16" \ --adam_weight_decay=3e-2 \ --adam_epsilon=1e-10 \ --max_grad_norm=3e-2 \ --vae_mini_batch=1 \ --random_frame_crop \ --enable_bucket \ --trainable_modules "transformer_blocks" "proj_out" "long_connect_fc" ``` -------------------------------- ### Download InternVL2 Model Source: https://github.com/aigc-apps/easyanimate/blob/main/easyanimate/video_caption/README.md Downloads the InternVL2 model for video recaptioning using the Hugging Face CLI. ```shell huggingface-cli download OpenGVLab/InternVL2-40B-AWQ --local-dir-use-symlinks False --local-dir /PATH/TO/INTERNVL2_MODEL ``` -------------------------------- ### Train EasyAnimateV5-InP without DeepSpeed Source: https://github.com/aigc-apps/easyanimate/blob/main/scripts/README_TRAIN.md Launches a training job for the EasyAnimateV5-InP model using standard accelerate settings. ```sh export MODEL_NAME="models/Diffusion_Transformer/EasyAnimateV5-12b-zh-InP" export DATASET_NAME="datasets/internal_datasets/" export DATASET_META_NAME="datasets/internal_datasets/metadata.json" export NCCL_IB_DISABLE=1 export NCCL_P2P_DISABLE=1 NCCL_DEBUG=INFO # When train model with multi machines, use "--config_file accelerate.yaml" instead of "--mixed_precision='bf16'". accelerate launch --mixed_precision="bf16" scripts/train.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --train_data_dir=$DATASET_NAME \ --train_data_meta=$DATASET_META_NAME \ --config_path "config/easyanimate_video_v5_magvit_multi_text_encoder.yaml" \ --image_sample_size=1024 \ --video_sample_size=256 \ --token_sample_size=512 \ --video_sample_stride=3 \ --video_sample_n_frames=49 \ --train_batch_size=1 \ --video_repeat=1 \ --gradient_accumulation_steps=1 \ --dataloader_num_workers=8 \ --num_train_epochs=100 \ --checkpointing_steps=100 \ --learning_rate=2e-05 \ --lr_scheduler="constant_with_warmup" \ --lr_warmup_steps=100 \ --seed=42 \ --output_dir="output_dir" \ --gradient_checkpointing \ --mixed_precision="bf16" \ --adam_weight_decay=5e-3 \ --adam_epsilon=1e-10 \ --vae_mini_batch=1 \ --max_grad_norm=0.05 \ --random_hw_adapt \ --training_with_video_token_length \ --loss_type="ddpm" \ --enable_bucket \ --uniform_sampling \ --train_mode="inpaint" \ --trainable_modules "." ``` -------------------------------- ### Prepare Original Prompts JSONL Source: https://github.com/aigc-apps/easyanimate/blob/main/easyanimate/video_caption/README.md Format for the input file containing original prompts for batch processing. ```json {"prompt": "A stylish woman in a black leather jacket, red dress, and boots walks confidently down a damp Tokyo street."} {"prompt": "An underwater world with realistic fish and other creatures of the sea."} {"prompt": "a monarch butterfly perched on a tree trunk in the forest."} {"prompt": "a child in a room with a bottle of wine and a lamp."} {"prompt": "two men in suits walking down a hallway."} ``` -------------------------------- ### Train EasyAnimateV5.1-InP with DeepSpeed Source: https://github.com/aigc-apps/easyanimate/blob/main/scripts/README_TRAIN_LORA.md Training command for EasyAnimateV5.1-InP utilizing DeepSpeed for distributed optimization. ```sh export MODEL_NAME="models/Diffusion_Transformer/EasyAnimateV5.1-12b-zh-InP" export DATASET_NAME="datasets/internal_datasets/" export DATASET_META_NAME="datasets/internal_datasets/metadata.json" export NCCL_IB_DISABLE=1 export NCCL_P2P_DISABLE=1 NCCL_DEBUG=INFO # When train model with multi machines, use "--config_file accelerate.yaml" instead of "--mixed_precision='bf16'". accelerate launch --use_deepspeed --deepspeed_config_file config/zero_stage2_config.json --deepspeed_multinode_launcher standard scripts/train_lora.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --train_data_dir=$DATASET_NAME \ --train_data_meta=$DATASET_META_NAME \ --config_path "config/easyanimate_video_v5.1_magvit_qwen.yaml" \ --image_sample_size=1024 \ --video_sample_size=256 \ --token_sample_size=512 \ --video_sample_stride=3 \ --video_sample_n_frames=49 \ --train_batch_size=1 \ --gradient_accumulation_steps=1 \ --dataloader_num_workers=8 \ --num_train_epochs=100 \ --checkpointing_steps=100 \ --learning_rate=1e-04 \ --seed=42 \ --low_vram \ --output_dir="output_dir" \ --gradient_checkpointing \ --mixed_precision="bf16" \ --adam_weight_decay=5e-3 \ --adam_epsilon=1e-10 \ --vae_mini_batch=1 \ --max_grad_norm=0.05 \ --random_hw_adapt \ --training_with_video_token_length \ --loss_type="flow" \ --enable_bucket \ --use_deepspeed \ --uniform_sampling \ --train_mode="inpaint" ``` -------------------------------- ### Request OpenAI Compatible Server Source: https://github.com/aigc-apps/easyanimate/blob/main/easyanimate/video_caption/README.md Perform prompt beautification by querying an OpenAI-compatible API endpoint. ```shell OPENAI_API_KEY="your_openai_api_key" OPENAI_BASE_URL="your_openai_base_url" python beautiful_prompt.py \ --model "your_model_name" \ --prompt "your_prompt" ``` -------------------------------- ### Train EasyAnimateV5-InP with DeepSpeed Source: https://github.com/aigc-apps/easyanimate/blob/main/scripts/README_TRAIN.md Launches a training job for EasyAnimateV5-InP using DeepSpeed for distributed training. ```sh export MODEL_NAME="models/Diffusion_Transformer/EasyAnimateV5-12b-zh-InP" export DATASET_NAME="datasets/internal_datasets/" export DATASET_META_NAME="datasets/internal_datasets/metadata.json" export NCCL_IB_DISABLE=1 export NCCL_P2P_DISABLE=1 NCCL_DEBUG=INFO # When train model with multi machines, use "--config_file accelerate.yaml" instead of "--mixed_precision='bf16'". accelerate launch --use_deepspeed --deepspeed_config_file config/zero_stage2_config.json --deepspeed_multinode_launcher standard scripts/train.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --train_data_dir=$DATASET_NAME \ --train_data_meta=$DATASET_META_NAME \ --config_path "config/easyanimate_video_v5_magvit_multi_text_encoder.yaml" \ --image_sample_size=1024 \ --video_sample_size=256 \ --token_sample_size=512 \ --video_sample_stride=3 \ --video_sample_n_frames=49 \ --train_batch_size=1 \ --video_repeat=1 \ --gradient_accumulation_steps=1 \ --dataloader_num_workers=8 \ --num_train_epochs=100 \ --checkpointing_steps=100 \ --learning_rate=2e-05 \ --lr_scheduler="constant_with_warmup" \ --lr_warmup_steps=100 \ --seed=42 \ --output_dir="output_dir" \ --gradient_checkpointing \ --mixed_precision="bf16" \ --adam_weight_decay=5e-3 \ --adam_epsilon=1e-10 \ --vae_mini_batch=1 \ --max_grad_norm=0.05 \ --random_hw_adapt \ --training_with_video_token_length \ --loss_type="ddpm" \ --enable_bucket \ --uniform_sampling \ --use_deepspeed \ --train_mode="inpaint" \ --trainable_modules "." ``` -------------------------------- ### Train EasyAnimateV5.1-InP with DeepSpeed Source: https://github.com/aigc-apps/easyanimate/blob/main/scripts/README_TRAIN.md Launches a training job for the EasyAnimateV5.1-InP model utilizing DeepSpeed for distributed training. ```sh export MODEL_NAME="models/Diffusion_Transformer/EasyAnimateV5.1-12b-zh-InP" export DATASET_NAME="datasets/internal_datasets/" export DATASET_META_NAME="datasets/internal_datasets/metadata.json" export NCCL_IB_DISABLE=1 export NCCL_P2P_DISABLE=1 NCCL_DEBUG=INFO # When train model with multi machines, use "--config_file accelerate.yaml" instead of "--mixed_precision='bf16'". accelerate launch --use_deepspeed --deepspeed_config_file config/zero_stage2_config.json --deepspeed_multinode_launcher standard scripts/train.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --train_data_dir=$DATASET_NAME \ --train_data_meta=$DATASET_META_NAME \ --config_path "config/easyanimate_video_v5.1_magvit_qwen.yaml" \ --image_sample_size=1024 \ --video_sample_size=256 \ --token_sample_size=512 \ --video_sample_stride=3 \ --video_sample_n_frames=49 \ --train_batch_size=1 \ --video_repeat=1 \ --gradient_accumulation_steps=1 \ --dataloader_num_workers=8 \ --num_train_epochs=100 \ --checkpointing_steps=100 \ --learning_rate=2e-05 \ --lr_scheduler="constant_with_warmup" \ --lr_warmup_steps=100 \ --seed=42 \ --output_dir="output_dir" \ --gradient_checkpointing \ --mixed_precision="bf16" \ --adam_weight_decay=5e-3 \ --adam_epsilon=1e-10 \ --vae_mini_batch=1 \ --max_grad_norm=0.05 \ --random_hw_adapt \ --training_with_video_token_length \ --loss_type="flow" \ --enable_bucket \ --uniform_sampling \ --use_deepspeed \ --train_mode="inpaint" \ --trainable_modules "." ``` -------------------------------- ### Launch EasyAnimateV3 Training Source: https://github.com/aigc-apps/easyanimate/blob/main/scripts/README_TRAIN.md Executes the training script for EasyAnimateV3 using accelerate with specific model paths and training parameters. ```sh export MODEL_NAME="models/Diffusion_Transformer/EasyAnimateV3-XL-2-InP-512x512" export DATASET_NAME="datasets/internal_datasets/" export DATASET_META_NAME="datasets/internal_datasets/metadata.json" export NCCL_IB_DISABLE=1 export NCCL_P2P_DISABLE=1 NCCL_DEBUG=INFO # When train model with multi machines, use "--config_file accelerate.yaml" instead of "--mixed_precision='bf16'". accelerate launch --mixed_precision="bf16" scripts/train.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --train_data_dir=$DATASET_NAME \ --train_data_meta=$DATASET_META_NAME \ --config_path "config/easyanimate_video_v3_slicevae_motion_module.yaml" \ --image_sample_size=512 \ --video_sample_size=512 \ --video_sample_stride=1 \ --video_sample_n_frames=144 \ --train_batch_size=1 \ --video_repeat=1 \ --gradient_accumulation_steps=1 \ --dataloader_num_workers=8 \ --num_train_epochs=100 \ --checkpointing_steps=500 \ --learning_rate=1e-05 \ --lr_scheduler="constant_with_warmup" \ --lr_warmup_steps=100 \ --seed=42 \ --output_dir="output_dir" \ --enable_xformers_memory_efficient_attention \ --gradient_checkpointing \ --mixed_precision="bf16" \ --adam_weight_decay=3e-2 \ --adam_epsilon=1e-10 \ --max_grad_norm=3e-2 \ --vae_mini_batch=1 \ --random_frame_crop \ --enable_bucket \ --train_mode="inpaint" \ --trainable_modules "transformer_blocks" "proj_out" "long_connect_fc" ``` -------------------------------- ### Run Video Recaptioning Script Source: https://github.com/aigc-apps/easyanimate/blob/main/easyanimate/video_caption/README.md Executes the video recaptioning workflow with specified model paths. ```shell CAPTION_MODEL_PATH=/PATH/TO/INTERNVL2_MODEL REWRITE_MODEL_PATH=/PATH/TO/REWRITE_MODEL sh scripts/stage_3_video_recaptioning.sh ``` -------------------------------- ### Run EasyAnimateV5-12b-zh-InP Inference with Reward LoRA Source: https://github.com/aigc-apps/easyanimate/blob/main/scripts/README_TRAIN_REWARD.md Configures the pipeline with specific GPU memory modes and merges a reward LoRA before generating video frames. ```python import torch from diffusers import DDIMScheduler from omegaconf import OmegaConf from transformers import BertModel, BertTokenizer, T5EncoderModel, T5EncoderModel from easyanimate.models import AutoencoderKLMagvit, EasyAnimateTransformer3DModel from easyanimate.pipeline.pipeline_easyanimate_inpaint import EasyAnimateInpaintPipeline from easyanimate.utils.lora_utils import merge_lora from easyanimate.utils.utils import get_image_to_video_latent, save_videos_grid from easyanimate.utils.fp8_optimization import convert_weight_dtype_wrapper # GPU memory mode, which can be choosen in [model_cpu_offload, model_cpu_offload_and_qfloat8, sequential_cpu_offload]. GPU_memory_mode = "model_cpu_offload" # Download from https://raw.githubusercontent.com/aigc-apps/EasyAnimate/refs/heads/main/config/easyanimate_video_v5_magvit_multi_text_encoder.yaml config_path = "config/easyanimate_video_v5_magvit_multi_text_encoder.yaml" model_path = "alibaba-pai/EasyAnimateV5-12b-zh-InP" lora_path = "alibaba-pai/EasyAnimateV5-Reward-LoRAs/EasyAnimateV5-12b-zh-InP-HPS2.1.safetensors" weight_dtype = torch.bfloat16 lora_weight = 0.7 prompt = "A panda eats bamboo while a monkey swings from branch to branch" sample_size = [512, 512] video_length = 49 config = OmegaConf.load(config_path) transformer_additional_kwargs = OmegaConf.to_container(config['transformer_additional_kwargs']) if weight_dtype == torch.float16: transformer_additional_kwargs["upcast_attention"] = True transformer = EasyAnimateTransformer3DModel.from_pretrained_2d( model_path, subfolder="transformer", transformer_additional_kwargs=transformer_additional_kwargs, torch_dtype=torch.float8_e4m3fn if GPU_memory_mode == "model_cpu_offload_and_qfloat8" else weight_dtype, low_cpu_mem_usage=True, ) vae = AutoencoderKLMagvit.from_pretrained( model_path, subfolder="vae", vae_additional_kwargs=OmegaConf.to_container(config['vae_kwargs']) ).to(weight_dtype) if config['vae_kwargs'].get('vae_type', 'AutoencoderKL') == 'AutoencoderKLMagvit' and weight_dtype == torch.float16: vae.upcast_vae = True pipeline = EasyAnimateInpaintPipeline.from_pretrained( model_path, text_encoder=BertModel.from_pretrained(model_path, subfolder="text_encoder").to(weight_dtype), text_encoder_2=T5EncoderModel.from_pretrained(model_path, subfolder="text_encoder_2").to(weight_dtype), tokenizer=BertTokenizer.from_pretrained(model_path, subfolder="tokenizer"), tokenizer_2=T5Tokenizer.from_pretrained(model_path, subfolder="tokenizer_2"), vae=vae, transformer=transformer, scheduler=DDIMScheduler.from_pretrained(model_path, subfolder="scheduler"), torch_dtype=weight_dtype ) if GPU_memory_mode == "sequential_cpu_offload": pipeline.enable_sequential_cpu_offload() elif GPU_memory_mode == "model_cpu_offload_and_qfloat8": pipeline.enable_model_cpu_offload() for _text_encoder in [pipeline.text_encoder, pipeline.text_encoder_2]: if hasattr(_text_encoder, "visual"): del _text_encoder.visual convert_weight_dtype_wrapper(pipeline.transformer, weight_dtype) else: pipeline.enable_model_cpu_offload() pipeline = merge_lora(pipeline, lora_path, lora_weight, device="cuda", dtype=weight_dtype) generator = torch.Generator(device="cuda").manual_seed(42) input_video, input_video_mask, _ = get_image_to_video_latent(None, None, video_length=video_length, sample_size=sample_size) sample = pipeline( prompt, video_length = video_length, negative_prompt = "bad detailed", height = sample_size[0], width = sample_size[1], generator = generator, guidance_scale = 7.0, num_inference_steps = 50, video = input_video, mask_video = input_video_mask, ).frames save_videos_grid(sample, "samples/output.mp4", fps=8) ``` -------------------------------- ### Run Video Splitting Script Source: https://github.com/aigc-apps/easyanimate/blob/main/easyanimate/video_caption/README.md Executes the video splitting workflow to generate clips from raw video files. ```shell sh scripts/stage_1_video_splitting.sh ``` -------------------------------- ### Configure Training Environment Variables Source: https://github.com/aigc-apps/easyanimate/blob/main/README.md Environment variable settings for scripts/train.sh based on the dataset path format used. ```bash export DATASET_NAME="datasets/internal_datasets/" export DATASET_META_NAME="datasets/internal_datasets/json_of_internal_datasets.json" ``` ```bash export DATASET_NAME="" export DATASET_META_NAME="/mnt/data/json_of_internal_datasets.json" ``` -------------------------------- ### Download LLM for Caption Rewriting Source: https://github.com/aigc-apps/easyanimate/blob/main/easyanimate/video_caption/README.md Downloads a local LLM for rewriting recaption results. ```shell huggingface-cli download NousResearch/Meta-Llama-3-8B-Instruct --local-dir-use-symlinks False --local-dir /PATH/TO/REWRITE_MODEL ``` -------------------------------- ### Train EasyAnimateV5.1 without DeepSpeed Source: https://github.com/aigc-apps/easyanimate/blob/main/scripts/README_TRAIN_CONTROL.md Standard training command for EasyAnimateV5.1 using accelerate. ```sh export MODEL_NAME="models/Diffusion_Transformer/EasyAnimateV5.1-12b-zh-Control" export DATASET_NAME="datasets/internal_datasets/" export DATASET_META_NAME="datasets/internal_datasets/metadata.json" export NCCL_IB_DISABLE=1 export NCCL_P2P_DISABLE=1 NCCL_DEBUG=INFO # When train model with multi machines, use "--config_file accelerate.yaml" instead of "--mixed_precision='bf16'". accelerate launch --mixed_precision="bf16" scripts/train_control.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --train_data_dir=$DATASET_NAME \ --train_data_meta=$DATASET_META_NAME \ --config_path "config/easyanimate_video_v5.1_magvit_qwen.yaml" \ --image_sample_size=1024 \ --video_sample_size=256 \ --token_sample_size=512 \ --video_sample_stride=3 \ --video_sample_n_frames=49 \ --train_batch_size=1 \ --video_repeat=1 \ --gradient_accumulation_steps=1 \ --dataloader_num_workers=8 \ --num_train_epochs=100 \ --checkpointing_steps=100 \ --learning_rate=2e-05 \ --lr_scheduler="constant_with_warmup" \ --lr_warmup_steps=100 \ --seed=42 \ --output_dir="output_dir" \ --gradient_checkpointing \ --mixed_precision="bf16" \ --adam_weight_decay=5e-3 \ --adam_epsilon=1e-10 \ --vae_mini_batch=1 \ --max_grad_norm=0.05 \ --random_hw_adapt \ --training_with_video_token_length \ --enable_bucket \ --uniform_sampling \ --loss_type="flow" \ --train_mode="control_ref" \ --control_ref_image="first_frame" \ --trainable_modules "." ``` -------------------------------- ### Train EasyAnimateV5-InP without DeepSpeed Source: https://github.com/aigc-apps/easyanimate/blob/main/scripts/README_TRAIN_LORA.md Standard training command for the EasyAnimateV5-InP model. ```sh export MODEL_NAME="models/Diffusion_Transformer/EasyAnimateV5-12b-zh-InP" export DATASET_NAME="datasets/internal_datasets/" export DATASET_META_NAME="datasets/internal_datasets/metadata.json" export NCCL_IB_DISABLE=1 export NCCL_P2P_DISABLE=1 NCCL_DEBUG=INFO # When train model with multi machines, use "--config_file accelerate.yaml" instead of "--mixed_precision='bf16'". accelerate launch --mixed_precision="bf16" scripts/train_lora.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --train_data_dir=$DATASET_NAME \ --train_data_meta=$DATASET_META_NAME \ --config_path "config/easyanimate_video_v5_magvit_multi_text_encoder.yaml" \ --image_sample_size=1024 \ --video_sample_size=256 \ --token_sample_size=512 \ --video_sample_stride=3 \ --video_sample_n_frames=49 \ --train_batch_size=1 \ --gradient_accumulation_steps=1 \ --dataloader_num_workers=8 \ --num_train_epochs=100 \ --checkpointing_steps=100 \ --learning_rate=1e-04 \ --seed=42 \ --low_vram \ --output_dir="output_dir" \ --gradient_checkpointing \ --mixed_precision="bf16" \ --adam_weight_decay=5e-3 \ --adam_epsilon=1e-10 \ --vae_mini_batch=1 \ --max_grad_norm=0.05 \ --random_hw_adapt \ --training_with_video_token_length \ --loss_type="ddpm" \ --enable_bucket \ --uniform_sampling \ --train_mode="inpaint" ``` -------------------------------- ### Train EasyAnimateV5.1 with DeepSpeed Source: https://github.com/aigc-apps/easyanimate/blob/main/scripts/README_TRAIN_CONTROL.md Training command for EasyAnimateV5.1 utilizing DeepSpeed for distributed optimization. ```sh export MODEL_NAME="models/Diffusion_Transformer/EasyAnimateV5.1-12b-zh-Control" export DATASET_NAME="datasets/internal_datasets/" export DATASET_META_NAME="datasets/internal_datasets/metadata.json" export NCCL_IB_DISABLE=1 export NCCL_P2P_DISABLE=1 NCCL_DEBUG=INFO # When train model with multi machines, use "--config_file accelerate.yaml" instead of "--mixed_precision='bf16'". accelerate launch --use_deepspeed --deepspeed_config_file config/zero_stage2_config.json --deepspeed_multinode_launcher standard scripts/train_control.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --train_data_dir=$DATASET_NAME \ --train_data_meta=$DATASET_META_NAME \ --config_path "config/easyanimate_video_v5.1_magvit_qwen.yaml" \ --image_sample_size=1024 \ --video_sample_size=256 \ --token_sample_size=512 \ --video_sample_stride=3 \ --video_sample_n_frames=49 \ --train_batch_size=1 \ --video_repeat=1 \ --gradient_accumulation_steps=1 \ --dataloader_num_workers=8 \ --num_train_epochs=100 \ --checkpointing_steps=100 \ --learning_rate=2e-05 \ --lr_scheduler="constant_with_warmup" \ --lr_warmup_steps=100 \ --seed=42 \ --output_dir="output_dir" \ --gradient_checkpointing \ --mixed_precision="bf16" \ --adam_weight_decay=5e-3 \ --adam_epsilon=1e-10 \ --vae_mini_batch=1 \ --max_grad_norm=0.05 \ --random_hw_adapt \ --training_with_video_token_length \ --enable_bucket \ --uniform_sampling \ --loss_type="flow" \ --train_mode="control_ref" \ --control_ref_image="first_frame" \ --use_deepspeed \ --trainable_modules "." ``` -------------------------------- ### Train EasyAnimateV5 with DeepSpeed Source: https://github.com/aigc-apps/easyanimate/blob/main/scripts/README_TRAIN_CONTROL.md Executes the training script using accelerate and DeepSpeed configuration. Ensure environment variables for model and dataset paths are set correctly before running. ```sh export MODEL_NAME="models/Diffusion_Transformer/EasyAnimateV5-12b-zh-Control" export DATASET_NAME="datasets/internal_datasets/" export DATASET_META_NAME="datasets/internal_datasets/metadata.json" export NCCL_IB_DISABLE=1 export NCCL_P2P_DISABLE=1 NCCL_DEBUG=INFO # When train model with multi machines, use "--config_file accelerate.yaml" instead of "--mixed_precision='bf16'". accelerate launch --use_deepspeed --deepspeed_config_file config/zero_stage2_config.json --deepspeed_multinode_launcher standard scripts/train_control.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --train_data_dir=$DATASET_NAME \ --train_data_meta=$DATASET_META_NAME \ --config_path "config/easyanimate_video_v5_magvit_multi_text_encoder.yaml" \ --image_sample_size=1024 \ --video_sample_size=256 \ --token_sample_size=512 \ --video_sample_stride=3 \ --video_sample_n_frames=49 \ --train_batch_size=1 \ --video_repeat=1 \ --gradient_accumulation_steps=1 \ --dataloader_num_workers=8 \ --num_train_epochs=100 \ --checkpointing_steps=100 \ --learning_rate=2e-05 \ --lr_scheduler="constant_with_warmup" \ --lr_warmup_steps=100 \ --seed=42 \ --output_dir="output_dir" \ --gradient_checkpointing \ --mixed_precision="bf16" \ --adam_weight_decay=5e-3 \ --adam_epsilon=1e-10 \ --vae_mini_batch=1 \ --max_grad_norm=0.05 \ --random_hw_adapt \ --training_with_video_token_length \ --loss_type="ddpm" \ --enable_bucket \ --uniform_sampling \ --use_deepspeed \ --trainable_modules "." ``` -------------------------------- ### Run Video Filtering Script Source: https://github.com/aigc-apps/easyanimate/blob/main/easyanimate/video_caption/README.md Executes the video filtering workflow to calculate quality scores for video clips. ```shell sh scripts/stage_2_video_filtering.sh ``` -------------------------------- ### Define Dataset Directory Structure Source: https://github.com/aigc-apps/easyanimate/blob/main/README.md The required directory layout for organizing training videos and images within the project. ```text 📦 project/ ├── 📂 datasets/ │ ├── 📂 internal_datasets/ │ ├── 📂 train/ │ │ ├── 📄 00000001.mp4 │ │ ├── 📄 00000002.jpg │ │ └── 📄 ..... │ └── 📄 json_of_internal_datasets.json ``` -------------------------------- ### Run Batched Inference Source: https://github.com/aigc-apps/easyanimate/blob/main/easyanimate/video_caption/README.md Execute prompt rewriting using a local LLM model. ```shell # Meta-Llama-3-8B-Instruct is sufficient for this task. # Download it from https://huggingface.co/NousResearch/Meta-Llama-3-8B-Instruct or https://www.modelscope.cn/models/LLM-Research/Meta-Llama-3-8B-Instruct to /path/to/your_llm python caption_rewrite.py \ --video_metadata_path datasets/original_prompt.jsonl \ --caption_column "prompt" \ --beautiful_prompt_column "beautiful_prompt" \ --batch_size 1 \ --model_name /path/to/your_llm \ --prompt prompt/beautiful_prompt.txt \ --prefix '"detailed description": ' \ --answer_template "your detailed description here" \ --max_retry_count 10 \ --saved_path datasets/beautiful_prompt.jsonl \ --saved_freq 1 ``` -------------------------------- ### Train EasyAnimateV5 without DeepSpeed Source: https://github.com/aigc-apps/easyanimate/blob/main/scripts/README_TRAIN_CONTROL.md Standard training command for EasyAnimateV5. ```sh export MODEL_NAME="models/Diffusion_Transformer/EasyAnimateV5-12b-zh-Control" export DATASET_NAME="datasets/internal_datasets/" export DATASET_META_NAME="datasets/internal_datasets/metadata.json" export NCCL_IB_DISABLE=1 export NCCL_P2P_DISABLE=1 NCCL_DEBUG=INFO # When train model with multi machines, use "--config_file accelerate.yaml" instead of "--mixed_precision='bf16'". accelerate launch --mixed_precision="bf16" scripts/train_control.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --train_data_dir=$DATASET_NAME \ --train_data_meta=$DATASET_META_NAME \ --config_path "config/easyanimate_video_v5_magvit_multi_text_encoder.yaml" \ --image_sample_size=1024 \ --video_sample_size=256 \ --token_sample_size=512 \ --video_sample_stride=3 \ --video_sample_n_frames=49 \ --train_batch_size=1 \ --video_repeat=1 \ --gradient_accumulation_steps=1 \ --dataloader_num_workers=8 \ --num_train_epochs=100 \ --checkpointing_steps=100 \ --learning_rate=2e-05 \ --lr_scheduler="constant_with_warmup" \ --lr_warmup_steps=100 \ --seed=42 \ --output_dir="output_dir" \ --gradient_checkpointing \ --mixed_precision="bf16" \ --adam_weight_decay=5e-3 \ --adam_epsilon=1e-10 \ --vae_mini_batch=1 \ --max_grad_norm=0.05 \ --random_hw_adapt \ --training_with_video_token_length \ --loss_type="ddpm" \ --enable_bucket \ --uniform_sampling \ --trainable_modules "." ``` -------------------------------- ### Train EasyAnimateV5 with DeepSpeed Source: https://github.com/aigc-apps/easyanimate/blob/main/scripts/README_TRAIN_LORA.md Launches LoRA training for EasyAnimateV5 using DeepSpeed for distributed optimization. ```sh export MODEL_NAME="models/Diffusion_Transformer/EasyAnimateV5-12b-zh-InP" export DATASET_NAME="datasets/internal_datasets/" export DATASET_META_NAME="datasets/internal_datasets/metadata.json" export NCCL_IB_DISABLE=1 export NCCL_P2P_DISABLE=1 NCCL_DEBUG=INFO # When train model with multi machines, use "--config_file accelerate.yaml" instead of "--mixed_precision='bf16'". accelerate launch --use_deepspeed --deepspeed_config_file config/zero_stage2_config.json --deepspeed_multinode_launcher standard scripts/train_lora.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --train_data_dir=$DATASET_NAME \ --train_data_meta=$DATASET_META_NAME \ --config_path "config/easyanimate_video_v5_magvit_multi_text_encoder.yaml" \ --image_sample_size=1024 \ --video_sample_size=256 \ --token_sample_size=512 \ --video_sample_stride=3 \ --video_sample_n_frames=49 \ --train_batch_size=1 \ --video_repeat=1 \ --gradient_accumulation_steps=1 \ --dataloader_num_workers=8 \ --num_train_epochs=100 \ --checkpointing_steps=100 \ --learning_rate=1e-04 \ --seed=42 \ --low_vram \ --output_dir="output_dir" \ --gradient_checkpointing \ --mixed_precision="bf16" \ --adam_weight_decay=5e-3 \ --adam_epsilon=1e-10 \ --vae_mini_batch=1 \ --max_grad_norm=0.05 \ --random_hw_adapt \ --training_with_video_token_length \ --loss_type="ddpm" \ --enable_bucket \ --use_deepspeed \ --uniform_sampling \ --train_mode="inpaint" ``` -------------------------------- ### Train EasyAnimateV4 (Obsolete) Source: https://github.com/aigc-apps/easyanimate/blob/main/scripts/README_TRAIN.md Commands for training EasyAnimateV4 models, with and without DeepSpeed. ```sh export MODEL_NAME="models/Diffusion_Transformer/EasyAnimateV4-XL-2-InP" export DATASET_NAME="datasets/internal_datasets/" export DATASET_META_NAME="datasets/internal_datasets/metadata.json" export NCCL_IB_DISABLE=1 export NCCL_P2P_DISABLE=1 NCCL_DEBUG=INFO # When train model with multi machines, use "--config_file accelerate.yaml" instead of "--mixed_precision='bf16'". accelerate launch --mixed_precision="bf16" scripts/train.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --train_data_dir=$DATASET_NAME \ --train_data_meta=$DATASET_META_NAME \ --config_path "config/easyanimate_video_v4_slicevae_multi_text_encoder.yaml" \ --image_sample_size=512 \ --video_sample_size=512 \ --token_sample_size=512 \ --video_sample_stride=1 \ --video_sample_n_frames=144 \ --train_batch_size=1 \ --video_repeat=1 \ --gradient_accumulation_steps=1 \ --dataloader_num_workers=8 \ --num_train_epochs=100 \ --checkpointing_steps=500 \ --learning_rate=2e-05 \ --lr_scheduler="constant_with_warmup" \ --lr_warmup_steps=100 \ --seed=42 \ --output_dir="output_dir" \ --enable_xformers_memory_efficient_attention \ --gradient_checkpointing \ --mixed_precision="bf16" \ --adam_weight_decay=3e-2 \ --adam_epsilon=1e-10 \ --vae_mini_batch=1 \ --max_grad_norm=0.05 \ --random_hw_adapt \ --training_with_video_token_length \ --motion_sub_loss \ --loss_type="ddpm" \ --random_frame_crop \ --enable_bucket \ --train_mode="inpaint" \ --trainable_modules "." ``` ```sh export MODEL_NAME="models/Diffusion_Transformer/EasyAnimateV4-XL-2-InP" export DATASET_NAME="datasets/internal_datasets/" export DATASET_META_NAME="datasets/internal_datasets/metadata.json" export NCCL_IB_DISABLE=1 export NCCL_P2P_DISABLE=1 NCCL_DEBUG=INFO # When train model with multi machines, use "--config_file accelerate.yaml" instead of "--mixed_precision='bf16'". accelerate launch --use_deepspeed --deepspeed_config_file config/zero_stage2_config.json --deepspeed_multinode_launcher standard scripts/train.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --train_data_dir=$DATASET_NAME \ --train_data_meta=$DATASET_META_NAME \ --config_path "config/easyanimate_video_v4_slicevae_multi_text_encoder.yaml" \ --image_sample_size=512 \ --video_sample_size=512 \ --token_sample_size=512 \ --video_sample_stride=1 \ --video_sample_n_frames=144 \ --train_batch_size=1 \ --video_repeat=1 \ --gradient_accumulation_steps=1 \ --dataloader_num_workers=8 \ --num_train_epochs=100 \ --checkpointing_steps=500 \ --learning_rate=2e-05 \ --lr_scheduler="constant_with_warmup" \ --lr_warmup_steps=100 \ --seed=42 \ --output_dir="output_dir" \ --enable_xformers_memory_efficient_attention \ --gradient_checkpointing \ --mixed_precision="bf16" \ --adam_weight_decay=3e-2 \ --adam_epsilon=1e-10 \ --vae_mini_batch=1 \ --max_grad_norm=0.05 \ --random_hw_adapt \ --training_with_video_token_length \ --motion_sub_loss \ --loss_type="ddpm" \ --random_frame_crop \ --enable_bucket \ --use_deepspeed \ --train_mode="inpaint" \ --trainable_modules "." ``` -------------------------------- ### Dataset Directory Structure Source: https://github.com/aigc-apps/easyanimate/blob/main/easyanimate/vae/README.md The expected file hierarchy for internal datasets. ```text 📦 project/ ├── 📂 datasets/ │ ├── 📂 internal_datasets/ │ ├── 📂 videos/ │ │ ├── 📄 00000001.mp4 │ │ ├── 📄 00000001.jpg │ │ └── 📄 ..... │ └── 📄 json_of_internal_datasets.json ```