maitri01 commited on
Commit
07bc07f
·
verified ·
1 Parent(s): 8b66cc2

Update hackathon_setup.sh

Browse files
Files changed (1) hide show
  1. hackathon_setup.sh +96 -78
hackathon_setup.sh CHANGED
@@ -1,96 +1,114 @@
1
- #!/bin/bash
2
- # =============================================================
3
- # HACKATHON SETUP: STEP 1 OF 2 - TEAM LEAD RUNS FIRST
4
- # =============================================================
5
- # EXECUTION ORDER (IMPORTANT):
6
- # 1. The TEAM LEAD configures and runs THIS script first.
7
- # Run: source hackathon_setup.sh
8
- # Wait until it finishes successfully.
9
- # 2. ONLY AFTER THAT, each remaining team member configures
10
- # and runs teammate.sh from their own JURECA account.
11
- # Run: source teammate.sh
12
- #
13
- # The team lead runs only this script. Teammates run only
14
- # teammate.sh. Do not run both scripts from the same account.
15
- #
16
- # Before running, set TEAM_LEAD to your Juelich username,
17
- # TEAMMATE_1 through TEAMMATE_3 to your teammates' Juelich
18
- # usernames, and TEAM_FOLDER to the agreed team name.
19
- # =============================================================
20
-
21
- # =============================================================
22
- # CONFIGURATION - TEAM LEAD EDITS THESE VALUES
23
- # =============================================================
24
- TEAM_LEAD="" # Your Juelich username
25
- TEAMMATE_1="" # Teammate's Juelich username; leave blank if unused
26
- TEAMMATE_2=""
27
- TEAMMATE_3=""
28
- TEAM_FOLDER="" # Your team name; teammates must use the exact same value
29
- # =============================================================
30
-
31
- RED='\033[0;31m'
32
- GREEN='\033[0;32m'
33
- YELLOW='\033[1;33m'
34
- BLUE='\033[0;34m'
35
- NC='\033[0m'
36
-
37
- _log() { echo -e "${BLUE}[INFO]${NC} $1"; }
38
- _ok() { echo -e "${GREEN}[OK]${NC} $1"; }
39
- _warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
40
- _error() { echo -e "${RED}[ERROR]${NC} $1"; }
41
-
42
- if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
43
- _error "This script must be sourced: source hackathon_setup.sh"
44
- exit 1
45
- fi
46
 
47
- if [[ -z "$TEAM_LEAD" || -z "$TEAM_FOLDER" || "$TEAM_LEAD" == */* || "$TEAM_FOLDER" == */* || "$TEAM_FOLDER" == "." || "$TEAM_FOLDER" == ".." ]]; then
48
- _error "Set valid TEAM_LEAD and TEAM_FOLDER values before running."
49
- return 1
 
50
  fi
51
 
52
- if [[ "$TEAM_LEAD" != "$(id -un)" ]]; then
53
- _error "TEAM_LEAD must match the username running this script: $(id -un)"
54
- return 1
 
 
 
 
 
55
  fi
56
 
57
- # Hugging Face datasets to download (org/repo format)
58
- HF_DATASETS=(
59
- "SprintML/unlearning"
60
- "SprintML/model_equality"
61
- "SprintML/Hackathon_Watermark_Localisation_Task"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  )
 
 
 
 
 
 
 
63
 
64
- PROJECT_NAME="training2666"
65
- SCRATCH_BASE="/p/scratch/$PROJECT_NAME"
66
- TEAM_LEAD_DIR="$SCRATCH_BASE/$TEAM_LEAD"
67
- TEAM_DIR="$TEAM_LEAD_DIR/$TEAM_FOLDER"
68
 
69
- # Build teammates array, skipping blank entries
70
- TEAMMATES=()
71
- for t in "$TEAMMATE_1" "$TEAMMATE_2" "$TEAMMATE_3"; do
72
- [[ -n "$t" ]] && TEAMMATES+=("$t")
73
- done
74
 
75
- if [[ "${#TEAMMATES[@]}" -eq 0 ]]; then
76
- _error "No teammates specified. Add at least one."
77
- return 1
78
- fi
 
 
 
79
 
80
- for t in "${TEAMMATES[@]}"; do
81
- if [[ "$t" == */* || "$t" == "$TEAM_LEAD" ]]; then
82
- _error "Invalid teammate username: $t"
83
- return 1
84
  fi
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  done
86
 
 
 
 
 
 
87
  echo ""
88
  echo "============================================="
89
- echo " Hackathon Setup - Team Lead (Step 1/2)"
90
  echo "============================================="
 
 
 
 
 
 
91
  echo ""
92
- echo " Team lead : $TEAM_LEAD"
93
- echo " Teammates : ${TEAMMATES[*]}"
94
- echo " Lead folder : $TEAM_LEAD_DIR"
95
- echo " Team folder : $TEAM_DIR"
 
96
  echo ""
 
1
+ _log "Step 6/6 - Downloading datasets and creating per-task environments..."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ if [[ -n "$HF_TOKEN" ]]; then
4
+ _ok "HF_TOKEN found - will be used for authentication."
5
+ else
6
+ _log "No HF_TOKEN set - proceeding without (fine for public datasets)."
7
  fi
8
 
9
+ BOOTSTRAP_VENV="$TEAM_DIR/.bootstrap"
10
+ if [[ ! -d "$BOOTSTRAP_VENV" ]]; then
11
+ _log "Creating bootstrap venv for downloads..."
12
+ uv venv -p 3.12 "$BOOTSTRAP_VENV" || return 1
13
+ VIRTUAL_ENV="$BOOTSTRAP_VENV" uv pip install huggingface_hub || return 1
14
+ _ok "Bootstrap venv ready."
15
+ else
16
+ _warn "Bootstrap venv already exists. Skipping."
17
  fi
18
 
19
+ BOOTSTRAP_PYTHON="$BOOTSTRAP_VENV/bin/python"
20
+
21
+ for dataset in "${HF_DATASETS[@]}"; do
22
+ dataset_name="${dataset##*/}"
23
+ dest="$TEAM_DIR/$dataset_name"
24
+ VENV_DIR="$dest/.venv"
25
+ REQ="$dest/requirements.txt"
26
+
27
+ echo ""
28
+ _log "--- Task: $dataset_name ---"
29
+
30
+ if [[ -d "$dest" ]]; then
31
+ _warn " Dataset directory already exists. Skipping download."
32
+ else
33
+ _log " Downloading $dataset..."
34
+ "$BOOTSTRAP_PYTHON" - "$dataset" "$dest" <<'PYEOF'
35
+ import os
36
+ import sys
37
+ from huggingface_hub import snapshot_download
38
+
39
+ snapshot_download(
40
+ repo_id=sys.argv[1],
41
+ repo_type="dataset",
42
+ local_dir=sys.argv[2],
43
+ token=os.environ.get("HF_TOKEN"),
44
  )
45
+ PYEOF
46
+ if [[ $? -ne 0 ]]; then
47
+ _error " Download failed - skipping venv setup."
48
+ continue
49
+ fi
50
+ _ok " Downloaded $dataset_name."
51
+ fi
52
 
53
+ mkdir -p "$dest/output" || { _error "Cannot create output directory"; continue; }
54
+ setfacl -m m:rwx "$dest/output"
55
+ setfacl -d -m m:rwx "$dest/output"
 
56
 
57
+ if [[ -d "$VENV_DIR" ]]; then
58
+ _warn " Venv already exists. Skipping."
59
+ continue
60
+ fi
 
61
 
62
+ if [[ ! -f "$REQ" ]]; then
63
+ _warn " No requirements.txt found in $dataset_name - skipping venv."
64
+ continue
65
+ fi
66
+
67
+ _log " Setting up uv project for $dataset_name..."
68
+ cd "$dest" || { _error " Cannot cd into $dest"; continue; }
69
 
70
+ if [[ ! -f pyproject.toml ]]; then
71
+ uv init -p 3.12 --no-workspace || { _error " uv init failed"; cd "$TEAM_DIR"; continue; }
 
 
72
  fi
73
+
74
+ uv venv -p 3.12 "$VENV_DIR" || { _error " uv venv failed"; cd "$TEAM_DIR"; continue; }
75
+
76
+ # Remove standalone comments and blank lines from requirements.
77
+ # Original behavior uses uv add to create pyproject.toml and uv.lock.
78
+ mapfile -t DEPS < <(grep -vE '^[[:space:]]*(#|$)' "$REQ")
79
+
80
+ if [[ "${#DEPS[@]}" -eq 0 ]]; then
81
+ _warn " requirements.txt is empty - skipping uv add."
82
+ else
83
+ if VIRTUAL_ENV="$VENV_DIR" uv add "${DEPS[@]}"; then
84
+ _ok " Done: pyproject.toml + uv.lock + .venv ready."
85
+ else
86
+ _error " Failed to install requirements for $dataset_name."
87
+ fi
88
+ fi
89
+
90
+ cd "$TEAM_DIR" || return 1
91
  done
92
 
93
+ if [[ -d "$BOOTSTRAP_VENV" ]]; then
94
+ rm -rf "$BOOTSTRAP_VENV"
95
+ _ok "Bootstrap venv removed."
96
+ fi
97
+
98
  echo ""
99
  echo "============================================="
100
+ echo -e "${GREEN} Team lead setup finished!${NC}"
101
  echo "============================================="
102
+ echo " Team access : $TEAM_LEAD + ${TEAMMATES[*]}"
103
+ echo " uv : $(uv --version 2>&1)"
104
+ echo ""
105
+ echo " NEXT: Each remaining team member must now run:"
106
+ echo " source teammate.sh"
107
+ echo " with TEAM_LEAD=$TEAM_LEAD and TEAM_FOLDER=$TEAM_FOLDER"
108
  echo ""
109
+ echo " Activate a task environment:"
110
+ echo " source $TEAM_DIR/<dataset-name>/.venv/bin/activate"
111
+ echo ""
112
+ echo " Submit a job: sbatch job.sh"
113
+ echo "============================================="
114
  echo ""