File size: 1,194 Bytes
ab09065
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash
# Watch for new checkpoints and backup immediately
# Runs every 15 minutes, checks if new checkpoint appeared

CKPT_DIR="/data0/checkpoints/flux_lora"
LAST_FILE="/data1/logs/.last_backup_ckpt"
HF_USER="memoryai"
LOG="/data1/logs/checkpoint_backup.log"

while true; do
    sleep 900  # 15 minutes

    # Find latest checkpoint
    LATEST=$(ls -td "$CKPT_DIR"/checkpoint-* "$CKPT_DIR"/final 2>/dev/null | head -1)

    if [ -z "$LATEST" ]; then
        continue
    fi

    # Check if already backed up
    LAST_BACKED=$(cat "$LAST_FILE" 2>/dev/null || echo "")
    if [ "$LATEST" = "$LAST_BACKED" ]; then
        continue
    fi

    # New checkpoint found - backup!
    echo "[$(date)] Backing up: $LATEST" >> "$LOG"

    python3 -c "
from huggingface_hub import upload_folder
import os

latest = '$LATEST'
name = os.path.basename(latest)
repo_id = '$HF_USER/4k-image-model-checkpoints'

print(f'Uploading {name} to {repo_id}...')
upload_folder(
    folder_path=latest,
    repo_id=repo_id,
    path_in_repo=f'flux_lora/{name}',
    repo_type='model',
)
print('Done!')
" >> "$LOG" 2>&1

    echo "$LATEST" > "$LAST_FILE"
    echo "[$(date)] Backup complete: $LATEST" >> "$LOG"
done