| #!/usr/bin/env bash |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| set -euo pipefail |
|
|
| HERE="$(cd "$(dirname "$0")" && pwd)" |
| cd "$HERE" |
|
|
| |
| |
| if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then |
| export PATH="$HOME/.local/bin:$PATH" |
| fi |
|
|
| MODE="${1:-once}" |
| HOST="$(hostname)" |
| LEM_BENCHMARKS_DIR="$HERE/lem-benchmarks" |
| WORKSPACES="$HERE/workspaces" |
|
|
| log() { printf "\033[1;32m[lem-eval %s]\033[0m %s\n" "$(date -u +%H:%M:%S)" "$*"; } |
|
|
| |
|
|
| maintain() { |
| log "git pull LEM-Eval" |
| git pull --ff-only || log "LEM-Eval pull failed (non-fatal)" |
| if [[ -d "$LEM_BENCHMARKS_DIR/.git" ]]; then |
| log "git pull lem-benchmarks" |
| (cd "$LEM_BENCHMARKS_DIR" && git pull --ff-only) || log "lem-benchmarks pull failed (non-fatal)" |
| fi |
| } |
|
|
| |
|
|
| run_target() { |
| local name="$1" ttype="$2" quant="$3" repo="$4" |
| local workspace="$WORKSPACES/$repo" |
| local label="$name/$ttype/$quant" |
|
|
| if [[ ! -d "$workspace/.git" ]]; then |
| log "[$label] workspace $repo not cloned, skipping (run install.sh first)" |
| return 0 |
| fi |
|
|
| log "[$label] git pull $repo" |
| (cd "$workspace" && git pull --ff-only) || { |
| log "[$label] pull failed, skipping" |
| return 0 |
| } |
|
|
| log "[$label] running eval.py..." |
| |
| |
| |
| |
| local task_args=() |
| if [[ -n "${LEM_TASK:-}" ]]; then |
| task_args=(--task "$LEM_TASK") |
| fi |
|
|
| if ! uv run --script eval.py \ |
| --target "$name" \ |
| --type "$ttype" \ |
| --quant "$quant" \ |
| --eval-results-dir "$workspace/.eval_results" \ |
| --lem-benchmarks-dir "$LEM_BENCHMARKS_DIR" \ |
| --n-questions 1 \ |
| --rounds 8 \ |
| "${task_args[@]}"; then |
| log "[$label] eval.py failed — continuing with next target" |
| return 0 |
| fi |
|
|
| |
| if (cd "$workspace" && git status --short | grep -q .); then |
| log "[$label] committing canon update to $repo" |
| (cd "$workspace" \ |
| && git add .eval_results/ \ |
| && git commit -m "eval: ${name}/${ttype}/${quant} advance ($(date -u +%Y-%m-%dT%H:%M:%SZ))" \ |
| && git push) || log "[$label] model repo push failed (non-fatal)" |
| fi |
|
|
| |
| if (cd "$LEM_BENCHMARKS_DIR" && git status --short | grep -q .); then |
| log "[$label] committing canon update to lem-benchmarks" |
| (cd "$LEM_BENCHMARKS_DIR" \ |
| && git add "results/$name/" \ |
| && git commit -m "eval: ${name}/${ttype}/${quant} advance ($(date -u +%Y-%m-%dT%H:%M:%SZ))" \ |
| && git push) || log "[$label] lem-benchmarks push failed (non-fatal)" |
| fi |
| } |
|
|
| |
| |
| |
| |
| |
| |
|
|
| once() { |
| log "host=$HOST types=${LEM_TYPES:-auto} names=${LEM_NAMES:-all} mode=once" |
|
|
| if [[ ! -d "$LEM_BENCHMARKS_DIR/.git" ]]; then |
| log "lem-benchmarks not cloned — run ./install.sh first" |
| exit 1 |
| fi |
|
|
| |
| local triples |
| triples=$(LEM_TYPES="${LEM_TYPES:-}" LEM_NAMES="${LEM_NAMES:-}" python3 - <<'PY' |
| import os, platform, yaml |
|
|
| types_env = os.environ.get("LEM_TYPES", "").strip() |
| if types_env: |
| allowed_types = set(t.strip() for t in types_env.split(",")) |
| else: |
| allowed_types = set() |
| if platform.system() == "Darwin": |
| try: |
| import mlx_lm |
| allowed_types.add("mlx") |
| except ImportError: |
| pass |
| if any(os.path.exists(os.path.join(p, "ollama")) |
| for p in os.environ.get("PATH", "").split(":")): |
| allowed_types.add("gguf") |
|
|
| names_env = os.environ.get("LEM_NAMES", "").strip() |
| allowed_names = set(n.strip() for n in names_env.split(",")) if names_env else None |
|
|
| def derive_repo_id(this_ref): |
| if this_ref.startswith("hf.co/"): |
| base = this_ref[len("hf.co/"):] |
| if ":" in base: |
| base = base.split(":", 1)[0] |
| return base |
| return this_ref |
|
|
| with open("targets.yaml") as f: |
| cfg = yaml.safe_load(f) |
| for t in cfg.get("targets", []): |
| if t.get("type") not in allowed_types: |
| continue |
| if allowed_names and t["name"] not in allowed_names: |
| continue |
| name = t["name"] |
| ttype = t["type"] |
| quant = t.get("quant", "") |
| repo = derive_repo_id(t["this"]) |
| print(f"{name}|{ttype}|{quant}|{repo}") |
| PY |
| ) |
|
|
| if [[ -z "$triples" ]]; then |
| log "no targets match this worker's types (set LEM_TYPES to override)" |
| exit 0 |
| fi |
|
|
| while IFS='|' read -r name ttype quant repo; do |
| [[ -z "$name" ]] && continue |
| run_target "$name" "$ttype" "$quant" "$repo" |
| done <<< "$triples" |
|
|
| log "pass complete" |
| } |
|
|
| |
|
|
| case "$MODE" in |
| once) |
| once |
| ;; |
| maintain) |
| maintain |
| ;; |
| loop) |
| |
| |
| |
| |
| |
| |
| while true; do |
| once |
| sleep 10 |
| done |
| ;; |
| *) |
| echo "usage: $0 {once|maintain|loop}" >&2 |
| exit 1 |
| ;; |
| esac |
|
|