File size: 2,769 Bytes
bc864be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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