maitri01 commited on
Commit
deed508
Β·
verified Β·
1 Parent(s): d5f6439

Create hackathon_setup.sh

Browse files
Files changed (1) hide show
  1. hackathon_setup.sh +306 -0
hackathon_setup.sh ADDED
@@ -0,0 +1,306 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # =============================================================
3
+ # Hackathon Full Environment Setup Script
4
+ # Make changes in CONFIGURATION section before running
5
+ # Run with: source hackathon_setup.sh
6
+ # =============================================================
7
+
8
+ RED='\033[0;31m'
9
+ GREEN='\033[0;32m'
10
+ YELLOW='\033[1;33m'
11
+ BLUE='\033[0;34m'
12
+ NC='\033[0m'
13
+
14
+ _log() { echo -e "${BLUE}[INFO]${NC} $1"; }
15
+ _ok() { echo -e "${GREEN}[OK]${NC} $1"; }
16
+ _warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
17
+ _error() { echo -e "${RED}[ERROR]${NC} $1"; }
18
+
19
+ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
20
+ _error "This script must be sourced: source hackathon_setup.sh"
21
+ exit 1
22
+ fi
23
+
24
+ # =============================================================
25
+ # CONFIGURATION β€” edit before running
26
+ # =============================================================
27
+
28
+ # Your JUDOOR username (folder owner)
29
+ OWNER=""
30
+
31
+ # Teammates (1 to 3, leave unused ones blank "")
32
+ TEAMMATE_1=""
33
+ TEAMMATE_2=""
34
+ TEAMMATE_3=""
35
+
36
+ # Your personal folder in $SCRATCH (created first, locked to you + team)
37
+ YOUR_FOLDER="test" # <-- replace with your username or custom name
38
+
39
+ # Team folder inside your folder (shared with teammates)
40
+ TEAM_FOLDER="team_cispa" # <-- replace with your team_name
41
+
42
+ # HuggingFace datasets to download (org/repo format)
43
+ HF_DATASETS=(
44
+ "maitri01/llm_watermark_removal"
45
+ ""
46
+ )
47
+
48
+ # =============================================================
49
+
50
+ SCRATCH_BASE="/p/scratch/training2614"
51
+ YOUR_DIR="$SCRATCH_BASE/$YOUR_FOLDER"
52
+ TEAM_DIR="$YOUR_DIR/$TEAM_FOLDER"
53
+
54
+ # Build teammates array β€” skip any blank entries
55
+ TEAMMATES=()
56
+ for t in "$TEAMMATE_1" "$TEAMMATE_2" "$TEAMMATE_3"; do
57
+ [[ -n "$t" ]] && TEAMMATES+=("$t")
58
+ done
59
+
60
+ if [[ "${#TEAMMATES[@]}" -eq 0 ]]; then
61
+ _error "No teammates specified. Add at least one."
62
+ return 1
63
+ fi
64
+
65
+ echo ""
66
+ echo "============================================="
67
+ echo " Hackathon Environment Setup"
68
+ echo "============================================="
69
+ echo ""
70
+ echo " Owner : $OWNER"
71
+ echo " Teammates : ${TEAMMATES[*]}"
72
+ echo " Your folder: $YOUR_DIR"
73
+ echo " Team folder: $TEAM_DIR"
74
+ echo ""
75
+
76
+ # -------------------------------------------------------------
77
+ # STEP 1: Check cluster
78
+ # -------------------------------------------------------------
79
+ _log "Step 1/6 - Checking cluster environment..."
80
+
81
+ if ! command -v jutil &> /dev/null; then
82
+ _error "jutil not found. Are you on JURECA?"
83
+ echo " SSH in: ssh <username>@jureca.fz-juelich.de"
84
+ return 1
85
+ fi
86
+ _ok "jutil found β€” on JURECA."
87
+
88
+ # -------------------------------------------------------------
89
+ # STEP 2: Activate project
90
+ # -------------------------------------------------------------
91
+ _log "Step 2/6 - Activating project training2614..."
92
+
93
+ jutil env activate -p training2614
94
+
95
+ if [[ -z "$PROJECT" ]]; then
96
+ _error "\$PROJECT empty after activation."
97
+ echo " Try manually: jutil env activate -p training2614"
98
+ return 1
99
+ fi
100
+ _ok "Project activated. \$PROJECT = $PROJECT"
101
+
102
+ # -------------------------------------------------------------
103
+ # STEP 3: Create folders
104
+ # -------------------------------------------------------------
105
+ _log "Step 3/6 - Creating folders in scratch..."
106
+
107
+ cd "$SCRATCH_BASE" || { _error "Cannot cd to $SCRATCH_BASE"; return 1; }
108
+
109
+ if [[ -d "$YOUR_FOLDER" ]]; then
110
+ _warn "Folder $YOUR_FOLDER already exists. Skipping mkdir."
111
+ else
112
+ mkdir "$YOUR_FOLDER"
113
+ _ok "Created $YOUR_FOLDER β€” left open (no permission restrictions)."
114
+ fi
115
+
116
+ if [[ -d "$TEAM_DIR" ]]; then
117
+ _warn "Team folder $TEAM_FOLDER already exists. Skipping mkdir."
118
+ else
119
+ mkdir "$TEAM_DIR"
120
+ _ok "Created $TEAM_FOLDER inside $YOUR_FOLDER."
121
+ fi
122
+
123
+ mkdir -p "$TEAM_DIR/output"
124
+ _ok "Created output/ for SLURM logs."
125
+
126
+ # -------------------------------------------------------------
127
+ # STEP 4: Set ACLs β€” owner + teammates get full access
128
+ # -------------------------------------------------------------
129
+ _log "Step 4/6 - Setting ACLs..."
130
+
131
+ # Block group and others from all future files
132
+ setfacl -m d:g::--- "$TEAM_DIR"
133
+ setfacl -m d:o::--- "$TEAM_DIR"
134
+
135
+ _grant_access() {
136
+ local uname="$1"
137
+ local dir="$2"
138
+ setfacl -m u:"$uname":rwx "$dir" # current folder
139
+ setfacl -d -m u:"$uname":rwx "$dir" # future files inherit
140
+ setfacl -R -m u:"$uname":rwx "$dir" # all existing files/subdirs
141
+ setfacl -R -d -m u:"$uname":rwx "$dir" # future files in subdirs
142
+ setfacl -R -m m:rwx "$dir" # fix mask so writes aren't blocked
143
+ }
144
+
145
+ for uname in "$OWNER" "${TEAMMATES[@]}"; do
146
+ _log " Granting access to: $uname"
147
+ _grant_access "$uname" "$TEAM_DIR"
148
+ _ok " ACL set for $uname"
149
+ done
150
+
151
+ _log "Final ACL:"
152
+ getfacl "$TEAM_DIR"
153
+
154
+ # -------------------------------------------------------------
155
+ # STEP 5: Install uv + configure shared cache
156
+ # -------------------------------------------------------------
157
+ _log "Step 5/6 - Installing uv and configuring shared cache..."
158
+
159
+ if command -v uv &> /dev/null; then
160
+ _warn "uv already installed. Skipping."
161
+ else
162
+ curl -LsSf https://astral.sh/uv/install.sh | sh
163
+ if [[ -f "$HOME/.local/bin/env" ]]; then
164
+ source "$HOME/.local/bin/env"
165
+ _ok "uv installed."
166
+ else
167
+ _error "uv install finished but env file not found."
168
+ return 1
169
+ fi
170
+ fi
171
+
172
+ UV_BASE="$TEAM_DIR/.uv"
173
+ HF_CACHE="$TEAM_DIR/.cache"
174
+ mkdir -p "$UV_BASE" "$HF_CACHE"
175
+
176
+ if grep -q "UV_CACHE_DIR.*$TEAM_FOLDER" ~/.bashrc; then
177
+ _warn "uv/HF cache config already in ~/.bashrc. Skipping."
178
+ else
179
+ cat << EOF >> ~/.bashrc
180
+
181
+ # uv + HF cache config β€” shared team env (added by hackathon_setup.sh)
182
+ export UV_CACHE_DIR=$UV_BASE/cache
183
+ export UV_TOOL_DIR=$UV_BASE/tools
184
+ export UV_PYTHON_INSTALL_DIR=$UV_BASE/python
185
+ export HF_HOME=$HF_CACHE
186
+ export HUGGINGFACE_HUB_CACHE=$HF_CACHE/hub
187
+ EOF
188
+ _ok "uv + HF cache paths written to ~/.bashrc"
189
+ fi
190
+
191
+ export UV_CACHE_DIR="$UV_BASE/cache"
192
+ export UV_TOOL_DIR="$UV_BASE/tools"
193
+ export UV_PYTHON_INSTALL_DIR="$UV_BASE/python"
194
+ export HF_HOME="$HF_CACHE"
195
+ export HUGGINGFACE_HUB_CACHE="$HF_CACHE/hub"
196
+
197
+ # -------------------------------------------------------------
198
+ # STEP 6: Download each dataset then create its per-task uv env
199
+ # -------------------------------------------------------------
200
+ _log "Step 6/6 - Downloading datasets and creating per-task environments..."
201
+
202
+ if [[ -n "$HF_TOKEN" ]]; then
203
+ _ok "HF_TOKEN found β€” will be used for authentication."
204
+ else
205
+ _log "No HF_TOKEN set β€” proceeding without (fine for public datasets)."
206
+ fi
207
+
208
+ # Bootstrap venv just for downloading β€” deleted after use
209
+ BOOTSTRAP_VENV="$TEAM_DIR/.bootstrap"
210
+ if [[ ! -d "$BOOTSTRAP_VENV" ]]; then
211
+ _log "Creating bootstrap venv for downloads..."
212
+ uv venv -p 3.12 "$BOOTSTRAP_VENV"
213
+ VIRTUAL_ENV="$BOOTSTRAP_VENV" uv pip install huggingface_hub
214
+ _ok "Bootstrap venv ready."
215
+ else
216
+ _warn "Bootstrap venv already exists. Skipping."
217
+ fi
218
+
219
+ BOOTSTRAP_PYTHON="$BOOTSTRAP_VENV/bin/python"
220
+
221
+ for dataset in "${HF_DATASETS[@]}"; do
222
+ dataset_name="${dataset##*/}"
223
+ dest="$TEAM_DIR/$dataset_name"
224
+ VENV_DIR="$dest/.venv"
225
+ REQ="$dest/requirements.txt"
226
+
227
+ echo ""
228
+ _log "--- Task: $dataset_name ---"
229
+
230
+ # 1. Download dataset
231
+ if [[ -d "$dest" ]]; then
232
+ _warn " Already downloaded. Skipping."
233
+ else
234
+ _log " Downloading $dataset..."
235
+ "$BOOTSTRAP_PYTHON" - <<PYEOF
236
+ import os
237
+ from huggingface_hub import snapshot_download
238
+ snapshot_download(
239
+ repo_id="$dataset",
240
+ repo_type="dataset",
241
+ local_dir="$dest",
242
+ token=os.environ.get("HF_TOKEN"),
243
+ )
244
+ PYEOF
245
+ if [[ $? -ne 0 ]]; then
246
+ _error " Download failed β€” skipping venv setup."
247
+ continue
248
+ fi
249
+ _ok " Downloaded $dataset_name."
250
+ fi
251
+
252
+ # 2. Create proper per-task uv project + venv from requirements.txt
253
+ if [[ -d "$VENV_DIR" ]]; then
254
+ _warn " Venv already exists. Skipping."
255
+ continue
256
+ fi
257
+
258
+ if [[ ! -f "$REQ" ]]; then
259
+ _warn " No requirements.txt found in $dataset_name β€” skipping venv."
260
+ continue
261
+ fi
262
+
263
+ _log " Setting up uv project for $dataset_name..."
264
+ cd "$dest" || { _error " Cannot cd into $dest"; continue; }
265
+
266
+ # Init uv project β€” creates pyproject.toml
267
+ uv init -p 3.12 --no-workspace
268
+
269
+ # Create venv inside task folder
270
+ uv venv -p 3.12 "$VENV_DIR"
271
+
272
+ # Parse requirements.txt: strip comments and blank lines
273
+ DEPS=$(grep -v '^\s*#' "$REQ" | grep -v '^\s*$' | tr '\n' ' ')
274
+
275
+ if [[ -z "$DEPS" ]]; then
276
+ _warn " requirements.txt is empty β€” skipping uv add."
277
+ else
278
+ # uv add writes deps into pyproject.toml and generates uv.lock
279
+ VIRTUAL_ENV="$VENV_DIR" uv add $DEPS && \
280
+ _ok " Done: pyproject.toml + uv.lock + .venv ready." || \
281
+ _error " Failed to install requirements for $dataset_name."
282
+ fi
283
+
284
+ cd "$TEAM_DIR"
285
+ done
286
+
287
+ # Clean up bootstrap venv β€” no trace left
288
+ if [[ -d "$BOOTSTRAP_VENV" ]]; then
289
+ rm -rf "$BOOTSTRAP_VENV"
290
+ _ok "Bootstrap venv removed."
291
+ fi
292
+
293
+ # =============================================================
294
+ echo ""
295
+ echo "============================================="
296
+ echo -e "${GREEN} Setup complete!${NC}"
297
+ echo "============================================="
298
+ echo " Team access : $OWNER + ${TEAMMATES[*]}"
299
+ echo " uv : $(uv --version 2>&1)"
300
+ echo ""
301
+ echo " Activate a task env:"
302
+ echo " source $TEAM_DIR/<dataset-name>/.venv/bin/activate"
303
+ echo ""
304
+ echo " Submit a job: sbatch job.sh"
305
+ echo "============================================="
306
+ echo ""