Snider Virgil commited on
Commit
70f85ef
·
1 Parent(s): 541e34f

fix(workers): capability probe + (name,type,quant) triple iteration

Browse files

Two bugs install.sh and lem-eval.sh both had:

1. Stale capability probe fallback — when mlx_lm import failed (linux),
the code fell back to {'mlx'} as the allowed type set. Charon then
tried to clone/run the mlx targets anyway, picking up lthn/lemer-mlx
into workspaces/lemer instead of the intended lthn/lemer gguf repo.
Now probes gguf independently via 'openai' import and errors out
with no fallback if neither backend is detected.

2. Runner keyed off target NAME only. With the composite (name, type,
quant) key we introduced earlier, multiple entries share 'lemer'
— the old code would race them into the same workspace dir and
eval.py would refuse to pick one (multiple matches). Python block
now emits pipe-separated 'name|type|quant|repo' tuples; run_target
takes all four and passes --type and --quant explicitly to eval.py.

install.sh pre-clone loop now:
- dedupes by repo id (multiple gguf quants share lthn/lemer — one clone)
- uses derive_repo_id() to strip the Ollama 'hf.co/<repo>:<tag>' form
into a bare clone-able repo id
- clones into workspaces/<repo-path> (e.g. workspaces/lthn/lemer,
workspaces/lthn/lemer-mlx) so siblings don't collide

lem-eval.sh run_target now:
- takes (name, type, quant, repo) explicitly
- workspace dir matches repo id, not target name
- commits carry 'name/type/quant' in the message for traceability
- passes --type and --quant to eval.py so resolve_target disambiguates

Co-Authored-By: Virgil <virgil@lethean.io>

Files changed (2) hide show
  1. install.sh +33 -8
  2. lem-eval.sh +51 -30
install.sh CHANGED
@@ -54,9 +54,11 @@ fi
54
  log "resolving targets this machine can run..."
55
  uv run --script eval.py --my-targets || true
56
 
57
- # Pre-clone each runnable target's model repo into workspaces/<target>.
58
- # Type filter mirrors eval.py / lem-eval.sh respect $LEM_TYPES if set,
59
- # otherwise capability probe (mlx on Apple Silicon).
 
 
60
  LEM_TYPES="${LEM_TYPES:-}" python3 - <<'PY'
61
  import os, platform, subprocess, yaml
62
 
@@ -71,21 +73,44 @@ else:
71
  allowed.add("mlx")
72
  except ImportError:
73
  pass
 
 
 
 
 
74
  if not allowed:
75
- allowed = {"mlx"}
 
 
 
 
 
 
 
 
 
76
 
77
  with open("targets.yaml") as f:
78
  cfg = yaml.safe_load(f)
 
 
 
79
  for t in cfg.get("targets", []):
80
  if t.get("type") not in allowed:
81
  continue
82
- name, repo = t["name"], t["this"]
83
- dest = os.path.join("workspaces", name)
 
 
 
 
 
 
84
  if os.path.isdir(os.path.join(dest, ".git")):
85
- print(f" [{name}] already cloned, pulling")
86
  subprocess.run(["git", "-C", dest, "pull", "--ff-only"], check=False)
87
  else:
88
- print(f" [{name}] cloning https://huggingface.co/{repo} → {dest}")
89
  subprocess.run(["git", "clone", f"https://huggingface.co/{repo}", dest], check=True)
90
  PY
91
 
 
54
  log "resolving targets this machine can run..."
55
  uv run --script eval.py --my-targets || true
56
 
57
+ # Pre-clone each runnable target's backing model repo into
58
+ # workspaces/<repo-id>. Capability probe matches eval.py: mlx on
59
+ # Apple Silicon with mlx_lm importable, gguf wherever openai is
60
+ # importable. Multiple targets sharing the same backing repo (e.g.
61
+ # the three gguf quants that all live in lthn/lemer) share one clone.
62
  LEM_TYPES="${LEM_TYPES:-}" python3 - <<'PY'
63
  import os, platform, subprocess, yaml
64
 
 
73
  allowed.add("mlx")
74
  except ImportError:
75
  pass
76
+ try:
77
+ import openai # noqa: F401
78
+ allowed.add("gguf")
79
+ except ImportError:
80
+ pass
81
  if not allowed:
82
+ print(" no target types detected (need mlx_lm or openai); set LEM_TYPES=gguf to override")
83
+
84
+ def derive_repo_id(this_ref):
85
+ """Strip Ollama hf.co/ prefix and :<tag> suffix to get a clone-able repo id."""
86
+ if this_ref.startswith("hf.co/"):
87
+ base = this_ref[len("hf.co/"):]
88
+ if ":" in base:
89
+ base = base.split(":", 1)[0]
90
+ return base
91
+ return this_ref
92
 
93
  with open("targets.yaml") as f:
94
  cfg = yaml.safe_load(f)
95
+
96
+ # Dedupe by repo id so multi-quant families clone once.
97
+ seen_repos = set()
98
  for t in cfg.get("targets", []):
99
  if t.get("type") not in allowed:
100
  continue
101
+ repo = derive_repo_id(t["this"])
102
+ if repo in seen_repos:
103
+ continue
104
+ seen_repos.add(repo)
105
+ # workspace dir matches the repo path so 'lthn/lemer' and
106
+ # 'lthn/lemer-mlx' end up in distinct folders.
107
+ dest = os.path.join("workspaces", repo)
108
+ os.makedirs(os.path.dirname(dest), exist_ok=True)
109
  if os.path.isdir(os.path.join(dest, ".git")):
110
+ print(f" [{repo}] already cloned, pulling")
111
  subprocess.run(["git", "-C", dest, "pull", "--ff-only"], check=False)
112
  else:
113
+ print(f" [{repo}] cloning https://huggingface.co/{repo} → {dest}")
114
  subprocess.run(["git", "clone", f"https://huggingface.co/{repo}", dest], check=True)
115
  PY
116
 
lem-eval.sh CHANGED
@@ -37,54 +37,59 @@ maintain() {
37
  fi
38
  }
39
 
40
- # --- run one slice for a single target ------------------------------------
41
 
42
  run_target() {
43
- local target="$1"
44
- local workspace="$WORKSPACES/$target"
 
45
 
46
  if [[ ! -d "$workspace/.git" ]]; then
47
- log "[$target] workspace not cloned, skipping (run install.sh first)"
48
  return 0
49
  fi
50
 
51
- log "[$target] git pull (model repo)"
52
  (cd "$workspace" && git pull --ff-only) || {
53
- log "[$target] pull failed, skipping"
54
  return 0
55
  }
56
 
57
- log "[$target] running eval.py..."
58
  uv run --script eval.py \
59
- --target "$target" \
 
 
60
  --eval-results-dir "$workspace/.eval_results" \
61
  --lem-benchmarks-dir "$LEM_BENCHMARKS_DIR" \
62
  --n-questions 1 \
63
  --rounds 8
64
 
65
- # Commit + push to target model repo
66
  if (cd "$workspace" && git status --short | grep -q .); then
67
- log "[$target] committing canon update to model repo"
68
  (cd "$workspace" \
69
  && git add .eval_results/ \
70
- && git commit -m "eval: advance canon ($(date -u +%Y-%m-%dT%H:%M:%SZ))" \
71
- && git push) || log "[$target] model repo push failed (non-fatal)"
72
  fi
73
 
74
  # Commit + push to lem-benchmarks for the aggregator row
75
  if (cd "$LEM_BENCHMARKS_DIR" && git status --short | grep -q .); then
76
- log "[$target] committing canon update to lem-benchmarks"
77
  (cd "$LEM_BENCHMARKS_DIR" \
78
- && git add "results/$target/" \
79
- && git commit -m "eval: $target canon advance ($(date -u +%Y-%m-%dT%H:%M:%SZ))" \
80
- && git push) || log "[$target] lem-benchmarks push failed (non-fatal)"
81
  fi
82
  }
83
 
84
  # --- one pass over all targets this worker can run -----------------------
85
  #
86
- # The set of runnable types comes from $LEM_TYPES (comma-separated) or
87
- # capability detection (mlx on Apple Silicon, otherwise explicit opt-in).
 
 
88
 
89
  once() {
90
  log "host=$HOST types=${LEM_TYPES:-auto} mode=once"
@@ -94,9 +99,9 @@ once() {
94
  exit 1
95
  fi
96
 
97
- # Get list of targets this worker can run, via python (avoids yaml-in-shell)
98
- local targets
99
- targets=$(LEM_TYPES="${LEM_TYPES:-}" python3 - <<'PY'
100
  import os, platform, yaml
101
 
102
  types_env = os.environ.get("LEM_TYPES", "").strip()
@@ -110,26 +115,42 @@ else:
110
  allowed.add("mlx")
111
  except ImportError:
112
  pass
113
- if not allowed:
114
- allowed = {"mlx"}
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  with open("targets.yaml") as f:
117
  cfg = yaml.safe_load(f)
118
  for t in cfg.get("targets", []):
119
- if t.get("type") in allowed:
120
- print(t["name"])
 
 
 
 
 
121
  PY
122
  )
123
 
124
- if [[ -z "$targets" ]]; then
125
  log "no targets match this worker's types (set LEM_TYPES to override)"
126
  exit 0
127
  fi
128
 
129
- while IFS= read -r target; do
130
- [[ -z "$target" ]] && continue
131
- run_target "$target"
132
- done <<< "$targets"
133
 
134
  log "pass complete"
135
  }
 
37
  fi
38
  }
39
 
40
+ # --- run one slice for a single (name, type, quant) triple --------------
41
 
42
  run_target() {
43
+ local name="$1" ttype="$2" quant="$3" repo="$4"
44
+ local workspace="$WORKSPACES/$repo"
45
+ local label="$name/$ttype/$quant"
46
 
47
  if [[ ! -d "$workspace/.git" ]]; then
48
+ log "[$label] workspace $repo not cloned, skipping (run install.sh first)"
49
  return 0
50
  fi
51
 
52
+ log "[$label] git pull $repo"
53
  (cd "$workspace" && git pull --ff-only) || {
54
+ log "[$label] pull failed, skipping"
55
  return 0
56
  }
57
 
58
+ log "[$label] running eval.py..."
59
  uv run --script eval.py \
60
+ --target "$name" \
61
+ --type "$ttype" \
62
+ --quant "$quant" \
63
  --eval-results-dir "$workspace/.eval_results" \
64
  --lem-benchmarks-dir "$LEM_BENCHMARKS_DIR" \
65
  --n-questions 1 \
66
  --rounds 8
67
 
68
+ # Commit + push to target model repo (canon advance for this quant)
69
  if (cd "$workspace" && git status --short | grep -q .); then
70
+ log "[$label] committing canon update to $repo"
71
  (cd "$workspace" \
72
  && git add .eval_results/ \
73
+ && git commit -m "eval: ${name}/${ttype}/${quant} advance ($(date -u +%Y-%m-%dT%H:%M:%SZ))" \
74
+ && git push) || log "[$label] model repo push failed (non-fatal)"
75
  fi
76
 
77
  # Commit + push to lem-benchmarks for the aggregator row
78
  if (cd "$LEM_BENCHMARKS_DIR" && git status --short | grep -q .); then
79
+ log "[$label] committing canon update to lem-benchmarks"
80
  (cd "$LEM_BENCHMARKS_DIR" \
81
+ && git add "results/$name/" \
82
+ && git commit -m "eval: ${name}/${ttype}/${quant} advance ($(date -u +%Y-%m-%dT%H:%M:%SZ))" \
83
+ && git push) || log "[$label] lem-benchmarks push failed (non-fatal)"
84
  fi
85
  }
86
 
87
  # --- one pass over all targets this worker can run -----------------------
88
  #
89
+ # Iterates every (name, type, quant) triple whose type matches this
90
+ # worker's capability set $LEM_TYPES env var overrides, otherwise
91
+ # capability probe (mlx on Apple Silicon with mlx_lm importable, gguf
92
+ # everywhere the openai client is importable).
93
 
94
  once() {
95
  log "host=$HOST types=${LEM_TYPES:-auto} mode=once"
 
99
  exit 1
100
  fi
101
 
102
+ # Emit one pipe-separated line per runnable target: name|type|quant|repo
103
+ local triples
104
+ triples=$(LEM_TYPES="${LEM_TYPES:-}" python3 - <<'PY'
105
  import os, platform, yaml
106
 
107
  types_env = os.environ.get("LEM_TYPES", "").strip()
 
115
  allowed.add("mlx")
116
  except ImportError:
117
  pass
118
+ try:
119
+ import openai # noqa: F401
120
+ allowed.add("gguf")
121
+ except ImportError:
122
+ pass
123
+
124
+ def derive_repo_id(this_ref):
125
+ if this_ref.startswith("hf.co/"):
126
+ base = this_ref[len("hf.co/"):]
127
+ if ":" in base:
128
+ base = base.split(":", 1)[0]
129
+ return base
130
+ return this_ref
131
 
132
  with open("targets.yaml") as f:
133
  cfg = yaml.safe_load(f)
134
  for t in cfg.get("targets", []):
135
+ if t.get("type") not in allowed:
136
+ continue
137
+ name = t["name"]
138
+ ttype = t["type"]
139
+ quant = t.get("quant", "")
140
+ repo = derive_repo_id(t["this"])
141
+ print(f"{name}|{ttype}|{quant}|{repo}")
142
  PY
143
  )
144
 
145
+ if [[ -z "$triples" ]]; then
146
  log "no targets match this worker's types (set LEM_TYPES to override)"
147
  exit 0
148
  fi
149
 
150
+ while IFS='|' read -r name ttype quant repo; do
151
+ [[ -z "$name" ]] && continue
152
+ run_target "$name" "$ttype" "$quant" "$repo"
153
+ done <<< "$triples"
154
 
155
  log "pass complete"
156
  }