interplane.Get Omega
Read in your language

omega-rosetta

aien-dev/omega-rosetta

Brought by drakestapleton

branch main Branches Tags History

omega-rosetta / bench / check.sh

100 lines · 4442 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3# bench/check.sh: gates for the MultiPL-E Omega adapter (bench/README.md).
4#
5# sh bench/check.sh --omc PATH [--multipl-e DIR]
6#
7# PATH must hash to omc_sha256 in omega.ref. With --multipl-e (a MultiPL-E clone at
8# MULTIPLE_E_PIN in bench/multipl-e/build_prompts.py) the prompts are rebuilt and must equal the
9# committed ones; without it that gate prints NOT_RUN. Writes bench/results/<mode>/ (committed)
10# and bench/build/.
11# stdout: "PASS <gate>", "FAIL <gate> ..." or "NOT_RUN <gate> ..." lines, then "BENCH PASS|FAIL".
12# Exit 0 when no gate fails, 1 when one fails, 2 when setup fails. Linux AArch64 only.
13set -u
14bench=$(cd "$(dirname "$0")" && pwd)
15root=$(dirname "$bench")
16omc="${OMEGA_OMC:-}"
17mpe=""
18while [ $# -gt 0 ]; do
19 case "$1" in
20 --omc) omc="$2"; shift ;;
21 --multipl-e) mpe="$2"; shift ;;
22 *) echo "check.sh: unknown argument $1" >&2; exit 2 ;;
23 esac
24 shift
25done
26die() { echo "check.sh: $*" >&2; exit 2; }
27pin=$(awk '$1=="omc_sha256"{print $2}' "$root/omega.ref")
28[ -n "$pin" ] || die "omega.ref has no omc_sha256 line"
29[ -n "$omc" ] && [ -f "$omc" ] || die "give --omc PATH (or OMEGA_OMC)"
30got=$(sha256sum "$omc" | awk '{print $1}')
31[ "$got" = "$pin" ] || die "omc sha256 $got does not match the pin $pin"
32OMEGA_OMC=$omc; OMEGA_OMC_SHA256=$pin; export OMEGA_OMC OMEGA_OMC_SHA256
33work="$bench/build/check"; rm -rf "$work"; mkdir -p "$work" || die "cannot create $work"
34fails=0
35pass() { echo "PASS $1"; }
36fail() { echo "FAIL $*"; fails=$((fails + 1)); }
37
38# 1. The pin and the pass line are written in two files; they must agree.
39if python3 - "$bench" "$pin" <<'EOF'
40import sys
41sys.path.insert(0, sys.argv[1] + "/multipl-e")
42import eval_om, humaneval_to_om
43ok = eval_om.PINNED_OMC_SHA256 == sys.argv[2] and eval_om.MPE_OK_LINE == humaneval_to_om.MPE_OK_LINE
44sys.exit(0 if ok else 1)
45EOF
46then pass constants; else fail constants "eval_om pin or pass line differs"; fi
47
48# 2. The committed prompts are what the translator writes.
49if [ -n "$mpe" ]; then
50 if python3 -W ignore "$bench/multipl-e/build_prompts.py" --multipl-e "$mpe" > "$work/build.log" 2>&1 \
51 && git -C "$root" diff --quiet -- bench/prompts; then
52 pass prompts-rebuild
53 else
54 fail prompts-rebuild "see $work/build.log and git diff bench/prompts"
55 fi
56else
57 echo "NOT_RUN prompts-rebuild (no --multipl-e)"
58fi
59
60# 3. Every translated prompt and its tests compile: the stub body traps 14 in the first case.
61for set in humaneval mbpp; do
62 python3 "$bench/stub_model.py" stub "$work/stub-$set" --prompts "$bench/prompts/$set-om.jsonl" >&2 \
63 && python3 "$bench/score.py" --expect trap:14 "$work/stub-$set" > "$work/stub-$set.log" \
64 && pass "stub-sweep-$set $(head -n 1 "$work/stub-$set.log")" \
65 || fail "stub-sweep-$set" "$(grep FAIL "$work/stub-$set.log" | head -n 3)"
66done
67
68# 4. Hand solutions pass; each negative control is classified as what it is.
69for spec in hand:pass wrong:wrong_answer invalid:compile_error trap:trap:5 timeout:timeout; do
70 mode=${spec%%:*}; want=${spec#*:}
71 out="$bench/results/$mode"; rm -rf "$out"
72 python3 "$bench/stub_model.py" "$mode" "$out" >&2 || { fail "mode-$mode" "stub_model failed"; continue; }
73 t=15; [ "$mode" = timeout ] && t=2
74 if OMEGA_EVAL_TIMEOUT=$t python3 "$bench/score.py" --expect "$want" "$out" > "$work/$mode.log"; then
75 pass "mode-$mode $want $(cat "$work/$mode.log" | head -n 1)"
76 else
77 fail "mode-$mode" "$(cat "$work/$mode.log")"
78 fi
79done
80
81# 5. eval_om refuses an omc that is not the pin (negative control: a wrong pin).
82printf 'om2\nfn main to int\nret 0\nend\n' > "$work/bare.om"
83if OMEGA_OMC_SHA256=0000000000000000000000000000000000000000000000000000000000000000 \
84 python3 "$bench/multipl-e/eval_om.py" "$work/bare.om" > "$work/pin.log" 2>&1; then
85 fail pin-refusal "eval_om ran with a wrong pin"
86elif grep -q "refusing to evaluate" "$work/pin.log"; then
87 pass pin-refusal
88else
89 fail pin-refusal "$(tail -n 1 "$work/pin.log")"
90fi
91
92# 6. Exit 0 alone is not a pass: a program that never writes the pass line.
93if python3 "$bench/multipl-e/eval_om.py" "$work/bare.om" | grep -q '"om_status": "no_pass_line"'; then
94 pass no-pass-line
95else
96 fail no-pass-line "exit 0 without the pass line was not no_pass_line"
97fi
98
99if [ "$fails" -eq 0 ]; then echo "BENCH PASS"; exit 0; fi
100echo "BENCH FAIL ($fails)"; exit 1