Leon4gr45 commited on
Commit
4e26fec
·
verified ·
1 Parent(s): 222125a

Delete benchmarks/scripts/run_beam_10m_1_ingest_eval.sh

Browse files
benchmarks/scripts/run_beam_10m_1_ingest_eval.sh DELETED
@@ -1,253 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Resilient BEAM 10M/1 ingest + product evaluate.
3
- # Resume-safe. LISTEN-based ensure_api (never pkill healthy uvicorn).
4
- # Uses flock so watchdog/ensure never double-bind :8000.
5
- # NEVER touches beam1m1clean — uses beam10m1clean / beam-10m-1-clean only.
6
- #
7
- # TARGET comes from data/beam/10M/1/meta.json (ingest_target or n_turns-5).
8
- # Do not invent TARGET without a normalized sample.
9
- set +e
10
- ROOT="$(cd "$(dirname "$0")/.." && pwd)"
11
- cd "$ROOT"
12
- unset BRAINPAT_TOKEN BRAINAPI_TOKEN
13
- set -a; source ./.env; set +a
14
- export TERM=dumb PYTHONUNBUFFERED=1
15
-
16
- SRC="${BRAINAPI_SRC:-$HOME/.brainapi/source}"
17
- UV_LOG=/tmp/uvicorn-beam10m.log
18
- CEL_LOG=/tmp/brainapi-beam-worker.log
19
- LOCK_DIR=/tmp/beam10m-locks
20
- mkdir -p "$LOCK_DIR"
21
-
22
- BEAM_INGEST_CONCURRENCY="${BEAM_INGEST_CONCURRENCY:-2}"
23
- BEAM_INGEST_TIMEOUT="${BEAM_INGEST_TIMEOUT:-2400}"
24
- CELERY_WORKER_CONCURRENCY="${CELERY_WORKER_CONCURRENCY:-4}"
25
- RUN_ID="${BEAM_10M_RUN:-beam-10m-1-clean}"
26
- BRAIN_ID="${BEAM_10M_BRAIN:-beam10m1clean}"
27
- EVAL_RUN_ID="${BEAM_10M_EVAL_RUN:-beam-10m-1-clean-product}"
28
- SAMPLE_ID="${BEAM_10M_SAMPLE:-1}"
29
-
30
- api_ok() {
31
- lsof -iTCP:8000 -sTCP:LISTEN >/dev/null 2>&1 || return 1
32
- code=$(curl -s -o /dev/null --max-time 5 -w '%{http_code}' http://127.0.0.1:8000/docs || echo 000)
33
- [[ "$code" == "200" || "$code" == "401" ]]
34
- }
35
-
36
- start_uvicorn() {
37
- (
38
- flock -n 9 || return 0
39
- if lsof -iTCP:8000 -sTCP:LISTEN >/dev/null 2>&1; then
40
- return 0
41
- fi
42
- nohup bash -c "cd '$SRC' && exec ./.venv/bin/uvicorn src.services.api.app:app --host 127.0.0.1 --port 8000" \
43
- >> "$UV_LOG" 2>&1 &
44
- echo $! > /tmp/beam10m-uvicorn.pid
45
- sleep 5
46
- ) 9>"$LOCK_DIR/uvicorn.lock"
47
- }
48
-
49
- start_celery() {
50
- (
51
- flock -n 9 || return 0
52
- if pgrep -f '/.venv/bin/celery -A src.workers.app worker' >/dev/null 2>&1; then
53
- return 0
54
- fi
55
- nohup bash -c "cd '$SRC' && exec ./.venv/bin/celery -A src.workers.app worker --loglevel=info --pool=threads \
56
- --concurrency=${CELERY_WORKER_CONCURRENCY} \
57
- -Q ingest_data,finalize_ingestion,process_architect_relationships,consolidate_graph,chatbot_memory,ingest_file,ingest_structured_data" \
58
- >> "$CEL_LOG" 2>&1 &
59
- echo $! > /tmp/beam10m-celery.pid
60
- sleep 5
61
- ) 9>"$LOCK_DIR/celery.lock"
62
- }
63
-
64
- ensure_api() {
65
- for _ in 1 2 3 4 5 6 7 8 9 10 11 12; do
66
- if api_ok; then
67
- start_celery
68
- return 0
69
- fi
70
- start_uvicorn
71
- start_celery
72
- sleep 3
73
- done
74
- return 1
75
- }
76
-
77
- resolve_target() {
78
- .venv/bin/python - <<PY
79
- import json
80
- from pathlib import Path
81
- meta = Path("data/beam/10M/${SAMPLE_ID}/meta.json")
82
- if not meta.exists():
83
- print(0)
84
- raise SystemExit(0)
85
- row = json.loads(meta.read_text(encoding="utf-8"))
86
- target = row.get("ingest_target")
87
- if target is None:
88
- n = int(row.get("n_turns") or 0)
89
- target = max(1, n - 5) if n else 0
90
- print(int(target))
91
- PY
92
- }
93
-
94
- terminal_count() {
95
- .venv/bin/python - <<PY
96
- import json
97
- import re
98
- from pathlib import Path
99
- p = Path("runs/${RUN_ID}/ingest.jsonl")
100
- rows = [json.loads(l) for l in p.read_text().splitlines() if l.strip()] if p.exists() else []
101
- last = {}
102
- for r in rows:
103
- last[r.get("unit_id")] = r
104
- pat = re.compile(r"maximum context length is 8192", re.I)
105
- n = 0
106
- for r in last.values():
107
- st = r.get("status")
108
- err = r.get("error") or ""
109
- if st in {"completed", "partial_failed", "permanent_failed"}:
110
- n += 1
111
- elif st == "failed" and pat.search(err):
112
- n += 1
113
- print(n)
114
- PY
115
- }
116
-
117
- completed_count() {
118
- terminal_count
119
- }
120
-
121
- watchdog() {
122
- while [[ ! -f /tmp/beam-10m-1.STOP ]]; do
123
- if ! lsof -iTCP:8000 -sTCP:LISTEN >/dev/null 2>&1; then
124
- echo "WATCHDOG_API_RESTART $(date -u +%H:%M:%S)"
125
- start_uvicorn
126
- fi
127
- if ! pgrep -f '/.venv/bin/celery -A src.workers.app worker' >/dev/null 2>&1; then
128
- echo "WATCHDOG_CELERY_RESTART $(date -u +%H:%M:%S)"
129
- start_celery
130
- fi
131
- sleep 30
132
- done
133
- }
134
-
135
- TARGET=$(resolve_target)
136
- if [[ "$TARGET" -le 0 ]]; then
137
- echo "FATAL_NO_TARGET: normalize 10M sample first: ./beam.sh download --size 10M"
138
- echo "Then re-run; TARGET is read from data/beam/10M/${SAMPLE_ID}/meta.json"
139
- exit 1
140
- fi
141
-
142
- N_TURNS=$(.venv/bin/python - <<PY
143
- import json
144
- from pathlib import Path
145
- meta = Path("data/beam/10M/${SAMPLE_ID}/meta.json")
146
- print(json.loads(meta.read_text(encoding="utf-8")).get("n_turns", 0))
147
- PY
148
- )
149
-
150
- STALL_LIMIT=3
151
- prev_n=-1
152
- stalls=0
153
- MIN_EVAL_TURNS=$(( TARGET * 70 / 100 ))
154
- if [[ "$MIN_EVAL_TURNS" -lt 1 ]]; then
155
- MIN_EVAL_TURNS=1
156
- fi
157
-
158
- rm -f /tmp/beam-10m-1.STOP /tmp/beam-10m-1.DONE
159
- echo "START_10M_INGEST $(date -u +%Y-%m-%dT%H:%M:%SZ) concurrency=$BEAM_INGEST_CONCURRENCY celery_c=$CELERY_WORKER_CONCURRENCY target=$TARGET n_turns=$N_TURNS brain=$BRAIN_ID run=$RUN_ID"
160
- ensure_api || { echo FATAL_API_DOWN; exit 1; }
161
- watchdog &
162
- WD_PID=$!
163
- echo "watchdog_pid=$WD_PID"
164
-
165
- for try in $(seq 1 300); do
166
- ensure_api || { echo API_DOWN; sleep 20; continue; }
167
- done_n=$(completed_count)
168
- echo "try=$try terminal=$done_n target=$TARGET $(date -u +%H:%M:%S)"
169
- if [[ "$done_n" -ge "$TARGET" ]]; then
170
- break
171
- fi
172
- if [[ "$done_n" -eq "$prev_n" ]]; then
173
- stalls=$((stalls + 1))
174
- if [[ "$stalls" -ge "$STALL_LIMIT" ]]; then
175
- echo "INGEST_STALLED terminal=$done_n (no progress ${stalls} tries) — proceed to eval"
176
- break
177
- fi
178
- else
179
- stalls=0
180
- fi
181
- prev_n=$done_n
182
- ./beam.sh ingest \
183
- --size 10M --sample "$SAMPLE_ID" \
184
- --run "$RUN_ID" \
185
- --brain "$BRAIN_ID" \
186
- --concurrency "$BEAM_INGEST_CONCURRENCY" \
187
- --timeout "$BEAM_INGEST_TIMEOUT"
188
- sleep 2
189
- done
190
-
191
- done_n=$(completed_count)
192
- echo "INGEST_DONE=$done_n"
193
- kill "$WD_PID" 2>/dev/null
194
- wait "$WD_PID" 2>/dev/null
195
-
196
- if [[ "$done_n" -lt "$MIN_EVAL_TURNS" ]]; then
197
- echo "INGEST_INCOMPLETE abort eval ($done_n/$N_TURNS target=$TARGET)"
198
- date -u +%Y-%m-%dT%H:%M:%SZ > /tmp/beam-10m-1.DONE
199
- exit 2
200
- fi
201
-
202
- for ab in \
203
- abstention \
204
- contradiction_resolution \
205
- event_ordering \
206
- information_extraction \
207
- instruction_following \
208
- knowledge_update \
209
- multi_session_reasoning \
210
- preference_following \
211
- summarization \
212
- temporal_reasoning
213
- do
214
- echo "==== EVAL $ab $(date -u +%H:%M:%S) ===="
215
- ensure_api
216
- ./beam.sh evaluate \
217
- --size 10M --sample "$SAMPLE_ID" \
218
- --run "$EVAL_RUN_ID" \
219
- --brain "$BRAIN_ID" \
220
- --profile product \
221
- --abilities "$ab" \
222
- --concurrency 1 \
223
- --historical-limit 12 --max-passages 12 --max-facts 40 \
224
- --no-ppr
225
- done
226
- ./beam.sh report --run "$EVAL_RUN_ID"
227
- .venv/bin/python - <<PY
228
- import json, statistics, re
229
- from pathlib import Path
230
- rows=[json.loads(l) for l in Path('runs/${RUN_ID}/ingest.jsonl').read_text().splitlines() if l.strip()]
231
- last={}
232
- for r in rows: last[r.get('unit_id')]=r
233
- pat=re.compile(r'maximum context length is 8192', re.I)
234
- comp=[r for r in last.values() if r.get('status')=='completed' and (r.get('cost') or {}).get('llm_source_multiplier') is not None]
235
- mult=[r['cost']['llm_source_multiplier'] for r in comp]
236
- perm=sorted(
237
- uid for uid,r in last.items()
238
- if r.get('status')=='permanent_failed'
239
- or (r.get('status')=='failed' and pat.search(r.get('error') or ''))
240
- )
241
- print('MULTIPLIER n', len(mult),
242
- 'median', round(statistics.median(mult),1) if mult else None,
243
- 'mean', round(statistics.mean(mult),1) if mult else None)
244
- print('PERMANENT_FAILS', perm)
245
- rep_path=Path('runs/${EVAL_RUN_ID}/report.json')
246
- if rep_path.exists():
247
- rep=json.loads(rep_path.read_text())
248
- m=rep.get('metrics') or {}
249
- print('HEADLINE', m.get('headline_score'))
250
- print('PER', m.get('per_ability'))
251
- PY
252
- date -u +%Y-%m-%dT%H:%M:%SZ > /tmp/beam-10m-1.DONE
253
- echo MULTI_DONE