File size: 2,682 Bytes
0f775e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash
# Batch-validate generated tasks: stub must score 0, reference-as-submission must score > 0.
#   bash _factory/validate.sh <gpu> <task> [task...]
set -u
GPU=$1; shift
LANE=/home/zhuominc/MLE-Bench/mle_tasks/kernel-generation/kernels
for T in "$@"; do
  D=$LANE/$T
  SHIM=/tmp/_shim.$$.$T.py    # per-process+task: concurrent runs must not share this
  MOD=$(grep -oP '(?<=^COPY )\S+\.py(?= /app/)' $D/environment/Dockerfile | tail -1)
  # Graders expose the graded function in more than one shape. `fn = m.<name>` is the factory form;
  # legacy hand-written graders use `return m.<name>` inside a _load() helper (nsa-selected-attention),
  # and the megakernel family uses `m.<entry_build>` / `m.<entry_step>`. Without the fallbacks a task
  # is silently unvalidatable -- nsa-selected-attention was, and nobody noticed.
  FN=$(grep -oP '(?<=fn = m\.)\w+' $D/tests/verify_env.py | head -1)
  [ -z "$FN" ] && FN=$(grep -oP '(?<=return m\.)\w+' $D/tests/verify_env.py | head -1)
  [ -z "$FN" ] && FN=$(grep -oP '(?<=getattr\(m, ")\w+' $D/tests/verify_env.py | head -1)
  # build the pass-through shim on the HOST from the reference's real signature
  python3 - "$D" "$MOD" "$FN" "$SHIM" <<'PY'
import ast, re, sys, pathlib
d, mod, fn = sys.argv[1], sys.argv[2], sys.argv[3]
src = pathlib.Path(d, "environment", "reference.py").read_text()
tree = ast.parse(src)
f = next(n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name == fn)
names = [a.arg for a in f.args.args]
ndef = len(f.args.defaults)
defaults = [ast.unparse(d) for d in f.args.defaults]          # keep the REAL defaults (eps=1e-6, not None)
params = list(names)
for i, dv in enumerate(defaults):
    params[len(names) - ndef + i] = f"{names[len(names) - ndef + i]}={dv}"
pathlib.Path(sys.argv[4]).write_text(
    'import sys; sys.path.insert(0, "/app")\n'
    f'from reference import {fn} as _r\n'
    f'def {fn}({", ".join(params)}): return _r({", ".join(names)})\n')
PY
  [ -s "$SHIM" ] || { echo "$T: SHIM GENERATION FAILED"; continue; }
  IMG=mle-v-$T
  docker build -q -t $IMG $D/environment >/dev/null 2>&1 || { echo "$T: BUILD FAILED"; continue; }
  C=v-$T; docker rm -f $C >/dev/null 2>&1
  docker run -d --name $C --gpus "\"device=$GPU\"" --shm-size=8g --entrypoint sleep $IMG infinity >/dev/null
  docker cp $D/tests $C:/tests >/dev/null
  S=$(timeout 1700 docker exec $C bash /tests/test.sh 2>&1 | grep -E "^reward" | tail -1)
  docker cp $SHIM $C:/app/$MOD >/dev/null
  R=$(timeout 1700 docker exec $C bash /tests/test.sh 2>&1 | grep -E "^reward" | tail -1)
  docker rm -f $C >/dev/null 2>&1
  rm -f $SHIM
  printf "%-30s stub[%s] ref[%s]\n" "$T" "${S#reward: }" "${R#reward: }"
done