#!/bin/bash # Empirical test that each correctness gate actually DISCRIMINATES. # # The grader compares by relative Frobenius error against TOL, so a submission that returns the # reference plus noise of a known relative magnitude lands at a known relerr. Two runs per task: # # noise = 0.5 x TOL -> MUST pass (a gate that fails here rejects correct kernels) # noise = 2.0 x TOL -> MUST fail (a gate that passes here accepts wrong kernels) # # Integer/bool outputs are compared exactly and are deliberately left unperturbed; a task whose # outputs are ALL integer is reported as NOISE-IMMUNE rather than silently "passing". # # KNOWN LIMITATIONS -- a flag from this probe is not automatically a task defect. Verified cases where # the probe, not the task, is wrong: # * SCALAR outputs (a loss). Multiplicative noise gives relerr = |randn|*S, which exceeds 2S about # 5% of the time, so across several graded shapes it reads as a false TOO TIGHT. Handled: tensors # of <= 4 elements are perturbed by exactly S. # * fp8 outputs. e4m3 eps is 0.125, so a 1% injected perturbation is 8x BELOW one ULP: most elements # round straight back and the ones near a boundary flip a whole 12.5% code. Measured relerr is set # by the flip FRACTION, not the injected magnitude, so fp8-output tasks report TOO TIGHT spuriously. # * tol far below the output dtype's epsilon (e.g. 1e-4 on a bf16 output, eps 7.8e-3). The injected # noise rounds away entirely at 2x tol, giving a false NO DISCRIMINATION; the 100x probe separates # this from a genuinely dead gate. # * ROWWISE comparators, if the noise is scaled by the global norm rather than multiplicatively. 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 </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 # Either the outputs are all integer (compared exactly, so float noise is a no-op) or the gate # genuinely does not bite. A 100x probe separates the two. 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"