| # Flux LoRA Training with DeepSpeed ZeRO-3 on 2x H100 NVL | |
| # Step 1: Pre-compute embeddings (one-time) | |
| # Step 2: Train with both GPUs in parallel | |
| # | |
| # Usage: bash scripts/training/run_train_flux_deepspeed.sh | |
| set -e | |
| PROJECT_DIR="/home/adminuser/chungcat" | |
| EMBEDDING_DIR="/data0/datasets/processed/flux_train/embeddings" | |
| SHARD_DIR="/data0/datasets/processed/flux_train/shards" | |
| export PYTHONPATH="$PROJECT_DIR:$PYTHONPATH" | |
| export HF_HOME="/home/adminuser/.cache/huggingface" | |
| export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True | |
| # Step 1: Pre-compute embeddings if not done | |
| if [ ! -d "$EMBEDDING_DIR" ] || [ $(ls "$EMBEDDING_DIR"/shard-*.pt 2>/dev/null | wc -l) -eq 0 ]; then | |
| echo "=== Pre-computing embeddings ===" | |
| python3 "$PROJECT_DIR/scripts/training/precompute_embeddings.py" \ | |
| --data-dir "$SHARD_DIR" \ | |
| --output-dir "$EMBEDDING_DIR" \ | |
| --batch-size 8 \ | |
| --device cuda:0 | |
| echo "=== Embeddings ready ===" | |
| fi | |
| # Step 2: Launch DeepSpeed training on 2 GPUs | |
| echo "=== Starting DeepSpeed ZeRO-3 Training ===" | |
| accelerate launch \ | |
| --config_file "$PROJECT_DIR/configs/accelerate_config.yaml" \ | |
| "$PROJECT_DIR/scripts/training/train_flux_deepspeed.py" \ | |
| --embedding-dir "$EMBEDDING_DIR" \ | |
| --output-dir "/data0/checkpoints/flux_lora_ds" \ | |
| --batch-size 1 \ | |
| --gradient-accumulation 8 \ | |
| --learning-rate 1e-4 \ | |
| --lr-warmup-steps 500 \ | |
| --max-train-steps 100000 \ | |
| --save-steps 5000 \ | |
| --lora-rank 128 \ | |
| --lora-alpha 128 | |