| #!/bin/bash |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| set -u |
| LANE=/home/zhuominc/MLE-Bench/mle_tasks/kernel-generation/kernels |
| GPU=${GPU:-1} |
| for T in $(cat "$1"); do |
| D=$LANE/$T |
| V=$D/tests/verify_env.py |
| [ -f "$V" ] || { echo "$T :: NO GRADER"; continue; } |
| TOL=$(grep -oP '(?<=^TOL = )[0-9.eE+-]+' $V | head -1) |
| FN=$(grep -oP '(?<=fn = m\.)\w+' $V | head -1) |
| MOD=$(grep -oP '(?<=^COPY )\S+\.py(?= /app/)' $D/environment/Dockerfile | tail -1) |
| if [ -z "${TOL:-}" ] || [ -z "${FN:-}" ] || [ -z "${MOD:-}" ]; then |
| echo "$T :: UNPARSEABLE (tol=${TOL:-?} fn=${FN:-?} mod=${MOD:-?})"; continue |
| fi |
| case "$TOL" in 0|0.0) echo "$T :: TOL=0 exact-only, skipped"; continue;; esac |
|
|
| SH=/tmp/gp.$$.$T.py |
| cat > $SH <<EOF |
| import os, sys, torch |
| sys.path.insert(0, "/app") |
| import reference as _R |
| _f = getattr(_R, "$FN") |
| S = float(os.environ.get("GP_NOISE", "0")) |
| |
| _SEEN = {"float": 0, "exact": 0} |
| |
| def _pert(t): |
| # MULTIPLICATIVE noise: relative error is ~S both globally AND per row. Scaling by the global |
| # norm instead would dump disproportionate error into low-norm rows and spuriously fail |
| # rowwise comparators (ROW_PASS), which is not what we are testing. |
| if not torch.is_tensor(t) or not t.is_floating_point(): |
| _SEEN["exact"] += 1 |
| return t |
| _SEEN["float"] += 1 |
| f = t.float() |
| if f.numel() <= 4: |
| # A SCALAR output (a loss) has relerr = |randn|*S under multiplicative noise, which exceeds |
| # 2*S about 5% of the time -- across several graded shapes that reads as a false "too tight". |
| # Perturb it by exactly S instead, so the injected relative error is deterministic. |
| return (f * (1.0 + S)).to(t.dtype) |
| return (f + f * torch.randn_like(f) * S).to(t.dtype) |
| |
| def $FN(*a, **k): |
| o = _f(*a, **k) |
| r = type(o)(_pert(x) for x in o) if isinstance(o, (tuple, list)) else _pert(o) |
| if _SEEN["float"] == 0 and _SEEN["exact"]: |
| sys.stderr.write("GP_ALL_EXACT\n") |
| return r |
| EOF |
| run() { |
| docker run --rm --gpus device=$GPU -e GP_NOISE=$1 \ |
| -v $D/tests:/tests:ro -v $D/environment/reference.py:/app/reference.py:ro \ |
| -v $SH:/app/$MOD:ro mle-gp-$T bash -c 'bash /tests/test.sh 2>/dev/null | tail -1' 2>/dev/null \ |
| | grep -oP '(?<=correct: )[01]\.[0-9]' | head -1 |
| } |
| docker build -q -t mle-gp-$T $D/environment >/dev/null 2>&1 || { echo "$T :: BUILD FAILED"; rm -f $SH; continue; } |
| LO=$(python3 -c "print($TOL*0.5)") |
| HI=$(python3 -c "print($TOL*2.0)") |
| A=$(run $LO); B=$(run $HI) |
| VERDICT="ok"; C="" |
| [ "${A:-x}" != "1.0" ] && VERDICT="TOO TIGHT (0.5xtol rejected)" |
| if [ "${B:-x}" != "0.0" ]; then |
| |
| |
| C=$(run $(python3 -c "print($TOL*100)")) |
| if [ "${C:-x}" = "1.0" ]; then VERDICT="NOISE-IMMUNE (exact/integer outputs; probe N/A)" |
| else VERDICT="NO DISCRIMINATION (2xtol accepted, 100x rejected)"; fi |
| fi |
| printf "%-38s tol=%-8s lo=%-4s hi=%-4s %s\n" "$T" "$TOL" "${A:-?}" "${B:-?}" "$VERDICT" |
| docker rmi -f mle-gp-$T >/dev/null 2>&1 |
| rm -f $SH |
| done |
| echo "GATEPROBE_DONE_$GPU" |
|
|