File size: 4,216 Bytes
0c2db8c | 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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | #!/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-redhat}"
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}"
STATE_ROOT="${STATE_ROOT:-/home/sf895/SignVerse-2M-runtime}"
HOME_DATASET_DIR="${HOME_DATASET_DIR:-/home/sf895/SignVerse-2M-runtime/dataset}"
SCRATCH_DATASET_DIR="${SCRATCH_DATASET_DIR:-/scratch/$USER/SignVerse-2M-runtime/dataset}"
HOME_RAW_VIDEO_DIR="${HOME_RAW_VIDEO_DIR:-/home/sf895/SignVerse-2M-runtime/raw_video}"
SCRATCH_RAW_VIDEO_DIR="${SCRATCH_RAW_VIDEO_DIR:-/scratch/$USER/SignVerse-2M-runtime/raw_video}"
remaining_stats() {
python3 - <<PY2
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', {}))
size_bytes = 0
for item in folders:
path = item[1] if isinstance(item, tuple) else item
try:
for child in path.rglob('*'):
if child.is_file():
size_bytes += child.stat().st_size
except FileNotFoundError:
continue
print(f"remaining={len(folders)}")
print(f"bytes={size_bytes}")
PY2
}
upstream_busy() {
local download_claims process_claims raw_count
download_claims=$(find "$STATE_ROOT/slurm/state/download_claims" -maxdepth 1 -type f -name '*.claim' 2>/dev/null | wc -l)
process_claims=$(find "$STATE_ROOT/slurm/state/claims" -maxdepth 1 -type f -name '*.claim' 2>/dev/null | wc -l)
raw_count=$(find "$HOME_RAW_VIDEO_DIR" "$SCRATCH_RAW_VIDEO_DIR" -maxdepth 1 -type f \( -name '*.mp4' -o -name '*.mkv' -o -name '*.webm' -o -name '*.mov' \) 2>/dev/null | wc -l)
if [[ "$download_claims" -gt 0 || "$process_claims" -gt 0 || "$raw_count" -gt 0 ]]; then
return 0
fi
return 1
}
while true; do
eval "$(remaining_stats)"
echo "[drain] remaining_unuploaded=$remaining remaining_bytes=$bytes"
if [[ "$remaining" == "0" ]]; then
echo "[drain] backlog cleared"
break
fi
shards="$PARALLEL_SHARDS"
array_parallel="$ARRAY_PARALLEL"
extra_args=()
# Keep each normal shard at or above TARGET_FOLDERS when possible.
# For example, 311 folders should use 7 shards, not 8, so each shard still has >=40 folders.
needed_shards=$(( remaining / TARGET_FOLDERS ))
if (( needed_shards < 1 )); then
needed_shards=1
fi
if (( needed_shards < shards )); then
shards="$needed_shards"
fi
if (( shards < 1 )); then
shards=1
fi
if (( remaining < TARGET_FOLDERS && bytes < TARGET_BYTES )); then
echo "[drain] below upload thresholds; skip upload wave"
break
fi
if (( shards == 1 )); then
array_parallel=""
echo "[drain] single-shard strict 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
|