SignVerse-2M / slurm /submit_upload_parallel_drain.sh
Sen Fang
Harden runtime state and exclude uploaded videos
bc864be
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="${ROOT_DIR:-/home/sf895/SignVerse-2M}"
SUBMIT_SCRIPT="${SUBMIT_SCRIPT:-$ROOT_DIR/slurm/submit_upload_parallel_slurm.sh}"
PARALLEL_SHARDS="${PARALLEL_SHARDS:-8}"
ARRAY_PARALLEL="${ARRAY_PARALLEL:-8}"
PARTITION="${PARTITION:-main}"
START_STAGGER_MIN="${START_STAGGER_MIN:-1}"
START_STAGGER_MAX="${START_STAGGER_MAX:-3}"
TARGET_BYTES="${TARGET_BYTES:-10737418240}"
TARGET_FOLDERS="${TARGET_FOLDERS:-40}"
SLEEP_BETWEEN_WAVES="${SLEEP_BETWEEN_WAVES:-15}"
PROGRESS_JSON="${PROGRESS_JSON:-/home/sf895/SignVerse-2M-runtime/archive_upload_progress.json}"
HOME_DATASET_DIR="${HOME_DATASET_DIR:-/home/sf895/SignVerse-2M-runtime/dataset}"
SCRATCH_DATASET_DIR="${SCRATCH_DATASET_DIR:-/scratch/$USER/SignVerse-2M-runtime/dataset}"
remaining_unuploaded() {
python3 - <<PY
import json
from pathlib import Path
import sys
sys.path.insert(0, '/cache/home/sf895/SignVerse-2M')
from utils.dataset_pool import list_unuploaded_folder_paths
progress = json.loads(Path(r"$PROGRESS_JSON").read_text())
folders = list_unuploaded_folder_paths(Path(r"$HOME_DATASET_DIR"), Path(r"$SCRATCH_DATASET_DIR"), progress.get('uploaded_folders', {}))
print(len(folders))
PY
}
while true; do
remaining="$(remaining_unuploaded)"
echo "[drain] remaining_unuploaded=$remaining"
if [[ "$remaining" == "0" ]]; then
echo "[drain] backlog cleared"
break
fi
shards="$PARALLEL_SHARDS"
array_parallel="$ARRAY_PARALLEL"
extra_args=()
needed_shards=$(((remaining + TARGET_FOLDERS - 1) / TARGET_FOLDERS))
if (( needed_shards < shards )); then
shards="$needed_shards"
fi
if (( shards < 1 )); then
shards=1
fi
if (( shards == 1 )); then
array_parallel=""
extra_args+=(--allow-small-final-batch --no-require-target-bytes)
echo "[drain] switching to single-shard tail mode"
else
if (( array_parallel > shards )); then
array_parallel="$shards"
fi
echo "[drain] adaptive shard count=$shards"
fi
submit_cmd=(bash "$SUBMIT_SCRIPT"
--parallel-shards "$shards"
--partition "$PARTITION"
--start-stagger-min "$START_STAGGER_MIN"
--start-stagger-max "$START_STAGGER_MAX"
--target-bytes "$TARGET_BYTES"
--target-folders "$TARGET_FOLDERS"
)
if [[ -n "$array_parallel" ]]; then
submit_cmd+=(--array-parallel "$array_parallel")
fi
if (( ${#extra_args[@]} > 0 )); then
submit_cmd+=("${extra_args[@]}")
fi
submit_out="$("${submit_cmd[@]}")"
echo "$submit_out"
job_id="$(awk '/Submitted batch job/{print $4}' <<< "$submit_out" | tail -n1)"
if [[ -z "$job_id" ]]; then
echo "[drain] failed to parse submitted job id" >&2
exit 1
fi
while [[ -n "$(squeue -h -j "$job_id" 2>/dev/null)" ]]; do
sleep "$SLEEP_BETWEEN_WAVES"
done
sleep 2
done