v11: JOB_ID for multi-VPS parallel training, auto-detect NVMe
Browse files
job_ml.sh
CHANGED
|
@@ -18,12 +18,13 @@ set -eo pipefail
|
|
| 18 |
|
| 19 |
export HF_TOKEN="${HF_TOKEN:?Set HF_TOKEN}"
|
| 20 |
export TRAIN_STAGE="${TRAIN_STAGE:-flux}"
|
|
|
|
| 21 |
export HF_USER="memoryai"
|
| 22 |
export PROJECT_DIR="/home/adminuser/chungcat"
|
| 23 |
export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
|
| 24 |
export PYTHONPATH="$PROJECT_DIR:${PYTHONPATH:-}"
|
| 25 |
|
| 26 |
-
log() { echo "[$(date +%H:%M:%S)] $1"; }
|
| 27 |
|
| 28 |
###############################################################################
|
| 29 |
backup_checkpoint() {
|
|
@@ -38,7 +39,7 @@ user = os.environ.get("HF_USER", "memoryai")
|
|
| 38 |
repo_id = f"{user}/4k-image-model-checkpoints"
|
| 39 |
|
| 40 |
if stage == "flux":
|
| 41 |
-
ckpt_dir = Path("/data0/checkpoints/
|
| 42 |
elif stage == "sr2":
|
| 43 |
ckpt_dir = Path("/home/adminuser/chungcat/checkpoints/sr_stage2")
|
| 44 |
else:
|
|
@@ -62,7 +63,7 @@ to_upload = final if final.exists() else (checkpoints[-1] if checkpoints else No
|
|
| 62 |
|
| 63 |
if to_upload:
|
| 64 |
path_in_repo = f"{ckpt_dir.name}/{to_upload.name}"
|
| 65 |
-
print(f" Uploading {to_upload.name} -> {repo_id}/{path_in_repo}")
|
| 66 |
upload_folder(folder_path=str(to_upload), repo_id=repo_id, path_in_repo=path_in_repo, repo_type="model")
|
| 67 |
print(" Done!")
|
| 68 |
else:
|
|
@@ -322,11 +323,11 @@ log " Auto-backup started (PID $BACKUP_PID, every 30min)"
|
|
| 322 |
|
| 323 |
# Train using train_flux_lora.py (encodes on-the-fly, no precompute needed)
|
| 324 |
# GPU 0: VAE + text encoders, GPU 1: transformer training
|
| 325 |
-
log " Starting Flux LoRA training (
|
| 326 |
python3 -u "$PROJECT_DIR/scripts/training/train_flux_lora.py" \
|
| 327 |
--model-name "black-forest-labs/FLUX.1-schnell" \
|
| 328 |
--data-dir "$SHARD_DIR" \
|
| 329 |
-
--output-dir "$DATA0/checkpoints/
|
| 330 |
--batch-size 1 \
|
| 331 |
--gradient-accumulation 8 \
|
| 332 |
--learning-rate 1e-4 \
|
|
|
|
| 18 |
|
| 19 |
export HF_TOKEN="${HF_TOKEN:?Set HF_TOKEN}"
|
| 20 |
export TRAIN_STAGE="${TRAIN_STAGE:-flux}"
|
| 21 |
+
export JOB_ID="${JOB_ID:-$(hostname | cut -c1-8)}"
|
| 22 |
export HF_USER="memoryai"
|
| 23 |
export PROJECT_DIR="/home/adminuser/chungcat"
|
| 24 |
export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True
|
| 25 |
export PYTHONPATH="$PROJECT_DIR:${PYTHONPATH:-}"
|
| 26 |
|
| 27 |
+
log() { echo "[$(date +%H:%M:%S)][$JOB_ID] $1"; }
|
| 28 |
|
| 29 |
###############################################################################
|
| 30 |
backup_checkpoint() {
|
|
|
|
| 39 |
repo_id = f"{user}/4k-image-model-checkpoints"
|
| 40 |
|
| 41 |
if stage == "flux":
|
| 42 |
+
ckpt_dir = Path(f"/data0/checkpoints/flux_lora_{os.environ.get('JOB_ID', 'default')}")
|
| 43 |
elif stage == "sr2":
|
| 44 |
ckpt_dir = Path("/home/adminuser/chungcat/checkpoints/sr_stage2")
|
| 45 |
else:
|
|
|
|
| 63 |
|
| 64 |
if to_upload:
|
| 65 |
path_in_repo = f"{ckpt_dir.name}/{to_upload.name}"
|
| 66 |
+
print(f" Uploading {to_upload.name} -> {repo_id}/{path_in_repo} (job: {os.environ.get('JOB_ID', 'default')})")
|
| 67 |
upload_folder(folder_path=str(to_upload), repo_id=repo_id, path_in_repo=path_in_repo, repo_type="model")
|
| 68 |
print(" Done!")
|
| 69 |
else:
|
|
|
|
| 323 |
|
| 324 |
# Train using train_flux_lora.py (encodes on-the-fly, no precompute needed)
|
| 325 |
# GPU 0: VAE + text encoders, GPU 1: transformer training
|
| 326 |
+
log " Starting Flux LoRA training (job: $JOB_ID)..."
|
| 327 |
python3 -u "$PROJECT_DIR/scripts/training/train_flux_lora.py" \
|
| 328 |
--model-name "black-forest-labs/FLUX.1-schnell" \
|
| 329 |
--data-dir "$SHARD_DIR" \
|
| 330 |
+
--output-dir "$DATA0/checkpoints/flux_lora_$JOB_ID" \
|
| 331 |
--batch-size 1 \
|
| 332 |
--gradient-accumulation 8 \
|
| 333 |
--learning-rate 1e-4 \
|