File size: 2,801 Bytes
d79aee0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# SR Training + Auto-backup for VPS 2x H100
# This script runs on the 2-GPU VPS:
#   - Stage 2: SR 1K→2K
#   - Stage 3: SR 2K→4K (after Stage 2 converges)
#   - Auto-backup to HuggingFace every 30 minutes
#
# Usage: bash scripts/training/run_train_sr_2gpu.sh <hf_token>

set -e

HF_TOKEN=${1:-""}
PROJECT_DIR="/home/adminuser/chungcat"

if [ -z "$HF_TOKEN" ]; then
    echo "Usage: bash scripts/training/run_train_sr_2gpu.sh <hf_token>"
    exit 1
fi

# Login HuggingFace
echo "=== Logging into HuggingFace ==="
python3 -c "from huggingface_hub import login; login(token='$HF_TOKEN')"
HF_USER=$(python3 -c "from huggingface_hub import HfApi; print(HfApi().whoami()['name'])")
echo "Logged in as: $HF_USER"

# Start auto-backup in background
echo "=== Starting auto-backup (every 30 min) ==="
pkill -f "backup.py --auto" 2>/dev/null || true
nohup python3 "$PROJECT_DIR/scripts/backup.py" --auto --interval 30 --user "$HF_USER" \
    > "$PROJECT_DIR/logs/backup.log" 2>&1 &
echo "Auto-backup PID: $!"

# Create SR pairs if not exist
SR_PAIRS="$PROJECT_DIR/data/processed/sr_pairs"
if [ ! -d "$SR_PAIRS/1k_input" ] || [ $(ls "$SR_PAIRS/1k_input"/*.png 2>/dev/null | wc -l) -lt 100 ]; then
    echo "=== Creating SR pairs from 4K images ==="
    python3 "$PROJECT_DIR/scripts/data_collection/create_sr_pairs.py" \
        --input-dir "$PROJECT_DIR/data/processed/sr_4k/shards" \
        --output-dir "$SR_PAIRS" 2>&1 | tail -5
fi

# Train Stage 2: 1K→2K on GPU 0
echo "=== Starting SR Stage 2 (1K→2K) on GPU 0 ==="
export CUDA_VISIBLE_DEVICES=0
nohup python3 "$PROJECT_DIR/scripts/training/train_sr.py" \
    --stage 2 \
    --input-dir "$SR_PAIRS/1k_input" \
    --target-dir "$SR_PAIRS/2k_target" \
    --output-dir "$PROJECT_DIR/checkpoints/sr_stage2" \
    --batch-size 4 \
    --learning-rate 2e-4 \
    --max-steps 200000 \
    --save-steps 10000 \
    --base-channels 64 \
    --perceptual-weight 0.1 \
    > "$PROJECT_DIR/logs/train_sr_stage2.log" 2>&1 &
echo "SR Stage 2 PID: $!"

# Train Stage 3: 2K→4K on GPU 1
echo "=== Starting SR Stage 3 (2K→4K) on GPU 1 ==="
export CUDA_VISIBLE_DEVICES=1
nohup python3 "$PROJECT_DIR/scripts/training/train_sr.py" \
    --stage 3 \
    --input-dir "$SR_PAIRS/2k_input" \
    --target-dir "$SR_PAIRS/4k_target" \
    --output-dir "$PROJECT_DIR/checkpoints/sr_stage3" \
    --batch-size 2 \
    --learning-rate 2e-4 \
    --max-steps 200000 \
    --save-steps 10000 \
    --base-channels 64 \
    --perceptual-weight 0.1 \
    > "$PROJECT_DIR/logs/train_sr_stage3.log" 2>&1 &
echo "SR Stage 3 PID: $!"

echo ""
echo "=== All jobs started ==="
echo "Monitor:"
echo "  tail -f $PROJECT_DIR/logs/train_sr_stage2.log"
echo "  tail -f $PROJECT_DIR/logs/train_sr_stage3.log"
echo "  tail -f $PROJECT_DIR/logs/backup.log"
echo "  nvidia-smi"