trislee02 commited on
Commit
691969f
·
verified ·
1 Parent(s): afb2dae

Create train_lora_p1.sh

Browse files
Files changed (1) hide show
  1. train_lora_p1.sh +99 -0
train_lora_p1.sh ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Define directories and files
4
+ TRAIN_DIR="benchmark_data/lora_format_test"
5
+ OUTPUT_EXP="/cm/archive/trilq3/exps/sota_comparisons/lora_sdxl"
6
+ EVAL_OUTPUT_DIR="/cm/archive/trilq3/output/sota_comparisons/lora_sdxl_fix_placeholder_fix_fix"
7
+ EVALUATION_PROMPT_FILE="benchmark_data/benchmark_prompts.json"
8
+
9
+ # Get list of directories and count them
10
+ FOLDERS=("$TRAIN_DIR"/*)
11
+ TOTAL_DIRS=${#FOLDERS[@]}
12
+ HALF=$((TOTAL_DIRS / 2))
13
+
14
+ echo "Processing first half: 0 to $((HALF-1))"
15
+
16
+ # Loop through first half of directories
17
+ for ((i = 0; i < HALF; i++)); do
18
+ folder="${FOLDERS[$i]}"
19
+ if [[ -d "$folder" ]]; then
20
+ echo "Processing: $folder"
21
+
22
+ FOLDER_NAME=$(basename "$folder")
23
+ INSTANCE_DATA_DIR="$folder/imgs"
24
+
25
+ PLACEHOLDER_STYLE=""
26
+ PLACEHOLDER_CONTENT=""
27
+
28
+ for type in "content" "style"; do
29
+ OUTPUT_DIR="$OUTPUT_EXP/$type/$FOLDER_NAME"
30
+
31
+ PROMPT_FILE="$folder/instance_prompt_$type.txt"
32
+ if [[ ! -f "$PROMPT_FILE" ]]; then
33
+ echo "Warning: Prompt file not found for $FOLDER_NAME, skipping..."
34
+ continue
35
+ fi
36
+
37
+ INSTANCE_PROMPT=$(<"$PROMPT_FILE")
38
+ echo "INSTANCE_PROMPT: $INSTANCE_PROMPT"
39
+
40
+ PLACEHOLDER=$(echo "$INSTANCE_PROMPT" | cut -d' ' -f2-)
41
+ echo "PLACEHOLDER: $PLACEHOLDER"
42
+
43
+ if [[ "$type" == "content" ]]; then
44
+ PLACEHOLDER_CONTENT="$PLACEHOLDER"
45
+ else
46
+ PLACEHOLDER_STYLE="$PLACEHOLDER"
47
+ fi
48
+
49
+
50
+ if [[ -d "$OUTPUT_DIR" ]]; then
51
+ echo "Output directory exists for $FOLDER_NAME, skipping training..."
52
+ continue
53
+ fi
54
+
55
+ mkdir -p "$OUTPUT_DIR"
56
+
57
+
58
+ CUDA_VISIBLE_DEVICES=0 accelerate launch --num_processes=1 --gpu_ids="all" train_dreambooth_lora_sdxl.py \
59
+ --pretrained_model_name_or_path="stabilityai/stable-diffusion-xl-base-1.0" \
60
+ --instance_data_dir="$INSTANCE_DATA_DIR" \
61
+ --output_dir="$OUTPUT_DIR" \
62
+ --instance_prompt="$INSTANCE_PROMPT" \
63
+ --resolution=1024 \
64
+ --rank=64 \
65
+ --train_batch_size=1 \
66
+ --learning_rate=1e-4 \
67
+ --lr_scheduler="constant" \
68
+ --lr_warmup_steps=0 \
69
+ --max_train_steps=200 \
70
+ --checkpointing_steps=200 \
71
+ --seed=0 \
72
+ --gradient_checkpointing \
73
+ --use_8bit_adam \
74
+ --mixed_precision="fp16" \
75
+ --enable_xformers_memory_efficient_attention
76
+ done
77
+
78
+ OUTPUT_RESULT_DIR="$EVAL_OUTPUT_DIR"
79
+ mkdir -p "$OUTPUT_RESULT_DIR"
80
+
81
+ start_time=$(date +%s)
82
+ CUDA_VISIBLE_DEVICES=0 python infer_lora.py \
83
+ --output_path="$OUTPUT_RESULT_DIR" \
84
+ --content_LoRA="$OUTPUT_EXP/content/$FOLDER_NAME" \
85
+ --content_alpha=1.0 \
86
+ --style_LoRA="$OUTPUT_EXP/style/$FOLDER_NAME" \
87
+ --style_alpha=1.0 \
88
+ --num_images_per_prompt=8 \
89
+ --name_concept="$FOLDER_NAME" \
90
+ --placeholder_style="$PLACEHOLDER_STYLE" \
91
+ --placeholder_content="$PLACEHOLDER_CONTENT" \
92
+ --evaluation_prompt_file="$EVALUATION_PROMPT_FILE"
93
+ end_time=$(date +%s)
94
+ echo "Time taken for inference: $((end_time - start_time)) seconds"
95
+ fi
96
+ done
97
+
98
+ # Run evaluation metrics script
99
+ python evaluate_with_metrics.py --result_dir "$EVAL_OUTPUT_DIR" --data_dir "$TRAIN_DIR"