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

Create train_lora_p2.sh

Browse files
Files changed (1) hide show
  1. train_lora_p2.sh +103 -0
train_lora_p2.sh ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 second half: $HALF to $((TOTAL_DIRS-1))"
15
+
16
+ # Loop through second half of directories
17
+ for ((i = HALF; i < TOTAL_DIRS; 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
+
32
+ PROMPT_FILE="$folder/instance_prompt_$type.txt"
33
+ if [[ ! -f "$PROMPT_FILE" ]]; then
34
+ echo "Warning: Prompt file not found for $FOLDER_NAME, skipping..."
35
+ continue
36
+ fi
37
+
38
+ INSTANCE_PROMPT=$(<"$PROMPT_FILE")
39
+ echo "INSTANCE_PROMPT: $INSTANCE_PROMPT"
40
+
41
+ PLACEHOLDER=$(echo "$INSTANCE_PROMPT" | cut -d' ' -f2-)
42
+ echo "PLACEHOLDER: $PLACEHOLDER"
43
+
44
+ if [[ "$type" == "content" ]]; then
45
+ PLACEHOLDER_CONTENT="$PLACEHOLDER"
46
+ else
47
+ PLACEHOLDER_STYLE="$PLACEHOLDER"
48
+ fi
49
+
50
+
51
+ if [[ -d "$OUTPUT_DIR" ]]; then
52
+ echo "Output directory exists for $FOLDER_NAME, skipping training..."
53
+ continue
54
+ fi
55
+
56
+ mkdir -p "$OUTPUT_DIR"
57
+
58
+
59
+
60
+
61
+
62
+ CUDA_VISIBLE_DEVICES=3 accelerate launch --num_processes=1 --gpu_ids="all" train_dreambooth_lora_sdxl.py \
63
+ --pretrained_model_name_or_path="stabilityai/stable-diffusion-xl-base-1.0" \
64
+ --instance_data_dir="$INSTANCE_DATA_DIR" \
65
+ --output_dir="$OUTPUT_DIR" \
66
+ --instance_prompt="$INSTANCE_PROMPT" \
67
+ --resolution=1024 \
68
+ --rank=64 \
69
+ --train_batch_size=1 \
70
+ --learning_rate=1e-4 \
71
+ --lr_scheduler="constant" \
72
+ --lr_warmup_steps=0 \
73
+ --max_train_steps=200 \
74
+ --checkpointing_steps=200 \
75
+ --seed=0 \
76
+ --gradient_checkpointing \
77
+ --use_8bit_adam \
78
+ --mixed_precision="fp16" \
79
+ --enable_xformers_memory_efficient_attention
80
+ done
81
+
82
+ OUTPUT_RESULT_DIR="$EVAL_OUTPUT_DIR"
83
+ mkdir -p "$OUTPUT_RESULT_DIR"
84
+
85
+ start_time=$(date +%s)
86
+ CUDA_VISIBLE_DEVICES=3 python infer_lora.py \
87
+ --output_path="$OUTPUT_RESULT_DIR" \
88
+ --content_LoRA="$OUTPUT_EXP/content/$FOLDER_NAME" \
89
+ --content_alpha=1.0 \
90
+ --style_LoRA="$OUTPUT_EXP/style/$FOLDER_NAME" \
91
+ --style_alpha=1.0 \
92
+ --num_images_per_prompt=8 \
93
+ --name_concept="$FOLDER_NAME" \
94
+ --placeholder_style="$PLACEHOLDER_STYLE" \
95
+ --placeholder_content="$PLACEHOLDER_CONTENT" \
96
+ --evaluation_prompt_file="$EVALUATION_PROMPT_FILE"
97
+ end_time=$(date +%s)
98
+ echo "Time taken for inference: $((end_time - start_time)) seconds"
99
+ fi
100
+ done
101
+
102
+ # Run evaluation metrics script
103
+ python evaluate_with_metrics.py --result_dir "$EVAL_OUTPUT_DIR" --data_dir "$TRAIN_DIR"