- 
                Notifications
    You must be signed in to change notification settings 
- Fork 137
Control lora trainer hunyuan #373
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
          
     Draft
      
      
            neph1
  wants to merge
  60
  commits into
  huggingface:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
neph1:control-lora-trainer-hunyuan
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Draft
                    Changes from 51 commits
      Commits
    
    
            Show all changes
          
          
            60 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      dc85bbf
              
                update
              
              
                a-r-r-o-w 755fee8
              
                Merge branch 'main' into feature/control-lora-trainer
              
              
                a-r-r-o-w 8812036
              
                update
              
              
                a-r-r-o-w e39d255
              
                update
              
              
                a-r-r-o-w 18bd9ce
              
                update
              
              
                a-r-r-o-w 3ef07fc
              
                update
              
              
                a-r-r-o-w ea07973
              
                update
              
              
                a-r-r-o-w 9f3d2cb
              
                add valid names to dataset docs
              
              
                neph1 2af75b1
              
                update
              
              
                a-r-r-o-w 28b86c8
              
                update
              
              
                a-r-r-o-w 84ffbd3
              
                update
              
              
                a-r-r-o-w 1684ee5
              
                update
              
              
                a-r-r-o-w 483e891
              
                update
              
              
                a-r-r-o-w 657fb74
              
                update
              
              
                a-r-r-o-w cd859b3
              
                update
              
              
                a-r-r-o-w 8cea261
              
                update
              
              
                a-r-r-o-w 90d6d38
              
                Merge branch 'main' into feature/control-lora-trainer
              
              
                a-r-r-o-w 45bbf22
              
                fix
              
              
                a-r-r-o-w 825976d
              
                update
              
              
                a-r-r-o-w 053757d
              
                Merge branch 'main' into feature/control-lora-trainer
              
              
                a-r-r-o-w eaafeab
              
                update
              
              
                a-r-r-o-w 9144f28
              
                Merge branch 'feature/control-lora-trainer' of https://github.com/a-r…
              
              
                a-r-r-o-w 3745ae5
              
                update
              
              
                a-r-r-o-w d7ba5e1
              
                Merge branch 'main' of github.com:neph1/finetrainers
              
              
                neph1 7245b5a
              
                update
              
              
                a-r-r-o-w c1c600f
              
                update
              
              
                a-r-r-o-w e1ef448
              
                Merge branch 'main' into feature/control-lora-trainer
              
              
                a-r-r-o-w 8587874
              
                update
              
              
                a-r-r-o-w 495e2b1
              
                Merge branch 'main' into feature/control-lora-trainer
              
              
                a-r-r-o-w 322d610
              
                Merge branch 'feature/control-lora-trainer' into feature/control-lora…
              
              
                a-r-r-o-w 2aeca67
              
                Merge branch 'main' into feature/control-lora-trainer
              
              
                a-r-r-o-w f256ea7
              
                Merge branch 'feature/control-lora-trainer' into feature/control-lora…
              
              
                a-r-r-o-w c9fa316
              
                Merge branch 'main' into feature/control-lora-trainer
              
              
                a-r-r-o-w ea09ef7
              
                Merge branch 'feature/control-lora-trainer' into feature/control-lora…
              
              
                a-r-r-o-w 1722964
              
                Merge branch 'main' of github.com:neph1/finetrainers
              
              
                neph1 c80c995
              
                hunyuan control specification
              
              
                neph1 232508d
              
                hunyuan control lora
              
              
                neph1 2853be5
              
                refactor
              
              
                neph1 d014b04
              
                clean up
              
              
                neph1 7db51c4
              
                free memory for single gpus
              
              
                neph1 f5fb737
              
                init as hunyuan base
              
              
                neph1 b2b77a8
              
                move back transformer to device after pass
              
              
                neph1 916bd33
              
                add todo about updating patch embedding layer
              
              
                neph1 3c53e1e
              
                update x_embed.proj
              
              
                neph1 52a6034
              
                output_names == 1 for sft trainer
              
              
                neph1 197e2fe
              
                Merge branch 'main' of github.com:neph1/finetrainers
              
              
                neph1 022fcfe
              
                Merge branch 'main' of github.com:neph1/finetrainers
              
              
                neph1 7d31522
              
                Merge branch 'main' into control-lora-trainer-hunyuan
              
              
                neph1 d4002ce
              
                apply latest changes
              
              
                neph1 4fcb7c6
              
                remove legacy dataset
              
              
                neph1 d894b05
              
                clean up
              
              
                neph1 9d43e8a
              
                remove hunyuan_common.py
              
              
                neph1 9be0e0c
              
                fix sorting
              
              
                neph1 1e12216
              
                fixes
              
              
                neph1 681a62f
              
                add training script and remove omni
              
              
                neph1 edc50a8
              
                fix quality
              
              
                neph1 09f8b7d
              
                optimize imports
              
              
                neph1 1d6e74f
              
                fixes
              
              
                neph1 12d61f3
              
                move import
              
              
                neph1 3706569
              
                reverting unnecessary hunyuan changes
              
              
                neph1 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            168 changes: 168 additions & 0 deletions
          
          168 
        
  examples/training/control/hunyuan_video/omni_edit/train.sh
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| #!/bin/bash | ||
|  | ||
| set -e -x | ||
|  | ||
| # export TORCH_LOGS="+dynamo,recompiles,graph_breaks" | ||
| # export TORCHDYNAMO_VERBOSE=1 | ||
| export WANDB_MODE="offline" | ||
| export NCCL_P2P_DISABLE=1 | ||
| export NCCL_IB_DISABLE=1 | ||
| export TORCH_NCCL_ENABLE_MONITORING=0 | ||
| export FINETRAINERS_LOG_LEVEL="INFO" | ||
|  | ||
| # Finetrainers supports multiple backends for distributed training. Select your favourite and benchmark the differences! | ||
| # BACKEND="accelerate" | ||
| BACKEND="ptd" | ||
|  | ||
| # In this setting, I'm using 2 GPUs on a 4-GPU node for training | ||
| NUM_GPUS=8 | ||
| CUDA_VISIBLE_DEVICES="0,1,2,3,4,5,6,7" | ||
|  | ||
| # Check the JSON files for the expected JSON format | ||
| TRAINING_DATASET_CONFIG="examples/training/control/cogview4/omni_edit/training.json" | ||
| VALIDATION_DATASET_FILE="examples/training/control/cogview4/omni_edit/validation.json" | ||
|  | ||
| # Depending on how many GPUs you have available, choose your degree of parallelism and technique! | ||
| DDP_1="--parallel_backend $BACKEND --pp_degree 1 --dp_degree 1 --dp_shards 1 --cp_degree 1 --tp_degree 1" | ||
| DDP_2="--parallel_backend $BACKEND --pp_degree 1 --dp_degree 2 --dp_shards 1 --cp_degree 1 --tp_degree 1" | ||
| DDP_4="--parallel_backend $BACKEND --pp_degree 1 --dp_degree 4 --dp_shards 1 --cp_degree 1 --tp_degree 1" | ||
| DDP_8="--parallel_backend $BACKEND --pp_degree 1 --dp_degree 8 --dp_shards 1 --cp_degree 1 --tp_degree 1" | ||
| FSDP_2="--parallel_backend $BACKEND --pp_degree 1 --dp_degree 1 --dp_shards 2 --cp_degree 1 --tp_degree 1" | ||
| FSDP_4="--parallel_backend $BACKEND --pp_degree 1 --dp_degree 1 --dp_shards 4 --cp_degree 1 --tp_degree 1" | ||
| HSDP_2_2="--parallel_backend $BACKEND --pp_degree 1 --dp_degree 2 --dp_shards 2 --cp_degree 1 --tp_degree 1" | ||
|  | ||
| # Parallel arguments | ||
| parallel_cmd=( | ||
| $DDP_1 | ||
| ) | ||
|  | ||
| # Model arguments | ||
| model_cmd=( | ||
| --model_name "hunyuan_video" | ||
| --pretrained_model_name_or_path "hunyuanvideo-community/HunyuanVideo" | ||
| ) | ||
|  | ||
| # Control arguments | ||
| control_cmd=( | ||
| --control_type custom | ||
| --rank 32 | ||
| --lora_alpha 32 | ||
| --target_modules "transformer_blocks.*(to_q|to_k|to_v|to_out.0)" | ||
| ) | ||
|  | ||
| # Dataset arguments | ||
| dataset_cmd=( | ||
| --dataset_config $TRAINING_DATASET_CONFIG | ||
| --dataset_shuffle_buffer_size 16 | ||
| --enable_precomputation | ||
| --precomputation_items 16 | ||
| ) | ||
|  | ||
| # Dataloader arguments | ||
| dataloader_cmd=( | ||
| --dataloader_num_workers 0 | ||
| ) | ||
|  | ||
| # Diffusion arguments | ||
| diffusion_cmd=( | ||
| --flow_weighting_scheme "logit_normal" | ||
| ) | ||
|  | ||
| # Training arguments | ||
| # We target just the attention projections layers for LoRA training here. | ||
| # You can modify as you please and target any layer (regex is supported) | ||
| training_cmd=( | ||
| --training_type control-lora | ||
| --seed 42 | ||
| --batch_size 1 | ||
| --train_steps 10000 | ||
| --gradient_accumulation_steps 4 | ||
| --gradient_checkpointing | ||
| --checkpointing_steps 1000 | ||
| --checkpointing_limit 5 | ||
| # --resume_from_checkpoint 3000 | ||
| --enable_slicing | ||
| --enable_tiling | ||
| ) | ||
|  | ||
| # Optimizer arguments | ||
| optimizer_cmd=( | ||
| --optimizer "adamw" | ||
| --lr 3e-5 | ||
| --lr_scheduler "constant_with_warmup" | ||
| --lr_warmup_steps 2000 | ||
| --lr_num_cycles 1 | ||
| --beta1 0.9 | ||
| --beta2 0.99 | ||
| --weight_decay 1e-4 | ||
| --epsilon 1e-8 | ||
| --max_grad_norm 1.0 | ||
| ) | ||
|  | ||
| # Validation arguments | ||
| validation_cmd=( | ||
| --validation_dataset_file "$VALIDATION_DATASET_FILE" | ||
| --validation_steps 500 | ||
| ) | ||
|  | ||
| # Miscellaneous arguments | ||
| miscellaneous_cmd=( | ||
| --tracker_name "finetrainers" | ||
| --output_dir "/fsx/aryan/lora-training/hunyuanvideo" | ||
| --init_timeout 600 | ||
| --nccl_timeout 600 | ||
| --report_to "none" | ||
| ) | ||
|  | ||
| # Execute the training script | ||
| if [ "$BACKEND" == "accelerate" ]; then | ||
|  | ||
| ACCELERATE_CONFIG_FILE="" | ||
| if [ "$NUM_GPUS" == 1 ]; then | ||
| ACCELERATE_CONFIG_FILE="accelerate_configs/uncompiled_1.yaml" | ||
| elif [ "$NUM_GPUS" == 2 ]; then | ||
| ACCELERATE_CONFIG_FILE="accelerate_configs/uncompiled_2.yaml" | ||
| elif [ "$NUM_GPUS" == 4 ]; then | ||
| ACCELERATE_CONFIG_FILE="accelerate_configs/uncompiled_4.yaml" | ||
| elif [ "$NUM_GPUS" == 8 ]; then | ||
| ACCELERATE_CONFIG_FILE="accelerate_configs/uncompiled_8.yaml" | ||
| fi | ||
|  | ||
| export WORLD_SIZE=$NUM_GPUS | ||
| export RANK=0 | ||
| export MASTER_ADDR=localhost | ||
| export MASTER_PORT=0 | ||
|  | ||
| accelerate launch --config_file "$ACCELERATE_CONFIG_FILE" --gpu_ids $CUDA_VISIBLE_DEVICES train.py \ | ||
| "${parallel_cmd[@]}" \ | ||
| "${model_cmd[@]}" \ | ||
| "${control_cmd[@]}" \ | ||
| "${dataset_cmd[@]}" \ | ||
| "${dataloader_cmd[@]}" \ | ||
| "${diffusion_cmd[@]}" \ | ||
| "${training_cmd[@]}" \ | ||
| "${optimizer_cmd[@]}" \ | ||
| "${miscellaneous_cmd[@]}" | ||
|  | ||
| elif [ "$BACKEND" == "ptd" ]; then | ||
|  | ||
| export CUDA_VISIBLE_DEVICES=$CUDA_VISIBLE_DEVICES | ||
| torchrun \ | ||
| --standalone \ | ||
| --nnodes=1 \ | ||
| --nproc_per_node=$NUM_GPUS \ | ||
| --rdzv_backend c10d \ | ||
| --rdzv_endpoint="localhost:19242" \ | ||
| train.py \ | ||
| "${parallel_cmd[@]}" \ | ||
| "${model_cmd[@]}" \ | ||
| "${control_cmd[@]}" \ | ||
| "${dataset_cmd[@]}" \ | ||
| "${dataloader_cmd[@]}" \ | ||
| "${diffusion_cmd[@]}" \ | ||
| "${training_cmd[@]}" \ | ||
| "${optimizer_cmd[@]}" \ | ||
| "${miscellaneous_cmd[@]}" | ||
| fi | ||
|  | ||
| echo -ne "-------------------- Finished executing script --------------------\n\n" | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1 +1,2 @@ | ||
| from .base_specification import HunyuanVideoModelSpecification | ||
| from .control_specification import HunyuanVideoControlModelSpecification | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far only made it work with compute_posterior false