Snider Virgil commited on
Commit
86b06f4
·
1 Parent(s): 45b798c

refactor: partition by type (mlx|gguf), drop owner hostname field

Browse files

Routing by 'owner: <hostname>' coupled the fleet to specific machine
names and broke whenever a machine was renamed or replaced. Routing by
'type: <backend>' instead describes the actual constraint: what
inference path the target needs. Workers detect their own capabilities
at runtime (import mlx_lm + platform check → mlx; explicit opt-in for
gguf until that wrapper lands) or take an explicit LEM_TYPES env
override. Partition falls out of what the hardware can do.

Changes:

targets.yaml
lemer, lemma type: mlx (Apple Silicon workers)
lemmy, lemrd type: gguf (GGUF workers — via Ollama endpoint on charon)

eval.py
- SUPPORTED_TYPES = {'mlx', 'gguf'}
- detect_default_types() probes mlx_lm import + Darwin platform
- --type flag overrides capability detection
- LEM_TYPES env var takes precedence over both
- --my-targets filters by allowed_types (was: by hostname owner)
- gguf targets fail fast with explicit TODO: wrapper not yet implemented

lem-eval.sh
- once() target-list resolution uses type filter via inline python
- log line shows LEM_TYPES for visibility

install.sh
- pre-clone loop filters by type, same logic as eval.py/lem-eval.sh

README.md
- describes capability-based partitioning
- notes gguf wrapper status (not yet implemented, will be
OpenAI-SDK against local Ollama/llama.cpp)

Follow-up needed before gguf targets run: wire gguf_wrapper.py as an
OpenAI-SDK client pointing at a local llama-cpp-server or Ollama
endpoint. The charon cron that's been running since the old pipeline
already has the environment + credentials + Ollama stack, so that
wrapper should drop in cleanly.

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

Files changed (5) hide show
  1. README.md +15 -6
  2. eval.py +57 -13
  3. install.sh +29 -14
  4. lem-eval.sh +28 -11
  5. targets.yaml +11 -10
README.md CHANGED
@@ -14,8 +14,10 @@ The 8-PAC benchmark runner for the Lemma model family.
14
  A HuggingFace dataset repo used as a tool-shaped "github" — the entire
15
  scorer lives here, anyone clones it, installs once, and the worker
16
  machines chug along advancing per-model canons in lockstep. Multiple
17
- workers farm different targets in parallel (each worker owns its
18
- targets via the `owner` field in `targets.yaml`).
 
 
19
 
20
  ## What it does
21
 
@@ -48,7 +50,7 @@ different machines contribute additive rows to the aggregator.
48
  LEM-Eval/
49
  ├── eval.py # target-driven runner (PEP 723 — uv run it)
50
  ├── mlx_lm_wrapper.py # lighteval custom model backend
51
- ├── targets.yaml # declarative fleet spec (base, this, owner)
52
  ├── install.sh # bootstrap: clone model repos + lem-benchmarks
53
  ├── lem-eval.sh # service script (once | maintain | loop)
54
  ├── cron/
@@ -73,9 +75,16 @@ cd LEM-Eval
73
  crontab -l | cat - cron/submit.cron cron/maintain.cron | crontab -
74
  ```
75
 
76
- Add a new machine: edit `targets.yaml` to set `owner: <hostname>` on the
77
- targets that machine should run, commit, push. Workers on that machine
78
- pick up the change via the `maintain` cron's hourly `git pull`.
 
 
 
 
 
 
 
79
 
80
  ## Quick start (manual / dev)
81
 
 
14
  A HuggingFace dataset repo used as a tool-shaped "github" — the entire
15
  scorer lives here, anyone clones it, installs once, and the worker
16
  machines chug along advancing per-model canons in lockstep. Multiple
17
+ workers farm different targets in parallel each target declares a
18
+ `type` (`mlx` or `gguf`) in `targets.yaml`, and workers filter by the
19
+ backends they can actually run (capability probe or `LEM_TYPES` env).
20
+ Partition falls out of what the hardware can do, not hostnames.
21
 
22
  ## What it does
23
 
 
50
  LEM-Eval/
51
  ├── eval.py # target-driven runner (PEP 723 — uv run it)
52
  ├── mlx_lm_wrapper.py # lighteval custom model backend
53
+ ├── targets.yaml # declarative fleet spec (base, this, type)
54
  ├── install.sh # bootstrap: clone model repos + lem-benchmarks
55
  ├── lem-eval.sh # service script (once | maintain | loop)
56
  ├── cron/
 
75
  crontab -l | cat - cron/submit.cron cron/maintain.cron | crontab -
76
  ```
77
 
78
+ Add a new machine: install LEM-Eval on it, the worker's backend probe
79
+ decides which targets it can run (mlx on Apple Silicon, gguf where an
80
+ Ollama endpoint is reachable). Override with `LEM_TYPES=mlx,gguf` in
81
+ the cron env if you want explicit control. Workers pick up `targets.yaml`
82
+ edits via the `maintain` cron's hourly `git pull`.
83
+
84
+ **gguf wrapper status:** not yet implemented. gguf targets (`lemmy`,
85
+ `lemrd`) sit in `targets.yaml` waiting for `gguf_wrapper.py` — will be
86
+ an OpenAI-SDK wrapper pointing at a local Ollama/llama.cpp server.
87
+ Until then, gguf targets list but don't run.
88
 
89
  ## Quick start (manual / dev)
90
 
eval.py CHANGED
@@ -774,25 +774,50 @@ def _run_once(
774
  return summary
775
 
776
 
777
- def _print_target_table(targets, my_host=None):
778
- print(f"{'name':<18} {'owner':<12} {'base':<42} {'this':<24}")
779
- print("-" * 100)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
780
  for t in targets:
781
- mark = " *" if (my_host and t.get("owner") == my_host) else ""
782
- print(f"{t['name']:<18} {t.get('owner', '?'):<12} {t['base']:<42} {t['this']:<24}{mark}")
783
 
784
 
785
  def main():
786
- import socket
787
- host = socket.gethostname()
788
-
789
  parser = argparse.ArgumentParser(
790
  description="LEM-Eval 8-PAC benchmark runner — target-driven, multi-writer",
791
  )
792
  parser.add_argument("--target", help="Target name from targets.yaml")
793
  parser.add_argument("--list-targets", action="store_true", help="List all targets and exit")
794
  parser.add_argument("--my-targets", action="store_true",
795
- help="List targets owned by this hostname and exit")
 
 
 
796
  parser.add_argument("--n-questions", type=int, default=DEFAULT_N_QUESTIONS)
797
  parser.add_argument("--rounds", type=int, default=DEFAULT_ROUNDS)
798
  parser.add_argument("--task", default=None,
@@ -817,21 +842,40 @@ def main():
817
  cfg = load_targets()
818
  all_targets = cfg.get("targets", [])
819
 
 
 
 
 
 
 
 
 
 
 
820
  if args.list_targets:
821
- _print_target_table(all_targets, my_host=host)
822
  return 0
823
  if args.my_targets:
824
- mine = [t for t in all_targets if t.get("owner") == host]
825
  if not mine:
826
- print(f"No targets owned by '{host}' in targets.yaml")
827
  return 0
828
- _print_target_table(mine)
829
  return 0
830
 
831
  if not args.target:
832
  parser.error("--target is required (or use --list-targets / --my-targets)")
833
 
834
  target = resolve_target(args.target, cfg)
 
 
 
 
 
 
 
 
 
835
 
836
  # Populate module globals so the lighteval custom-model loader picks
837
  # up the right identity when it instantiates MLXLMModel.
 
774
  return summary
775
 
776
 
777
+ SUPPORTED_TYPES = {"mlx", "gguf"}
778
+
779
+
780
+ def detect_default_types():
781
+ """Figure out which target types this machine can run by capability probe.
782
+
783
+ Apple Silicon + mlx_lm installed → mlx. Anything else (or explicit opt-in)
784
+ → gguf via an OpenAI-compatible endpoint (Ollama / llama.cpp server).
785
+ Returns a set. Workers override with --type or the LEM_TYPES env var.
786
+ """
787
+ import platform
788
+ types = set()
789
+ try:
790
+ import mlx_lm # noqa: F401
791
+ if platform.system() == "Darwin":
792
+ types.add("mlx")
793
+ except ImportError:
794
+ pass
795
+ # gguf path will be available once gguf_wrapper lands — for now it's
796
+ # opt-in via explicit --type gguf so workers don't silently skip
797
+ # mlx-only targets when the wrapper is absent.
798
+ return types or {"mlx"}
799
+
800
+
801
+ def _print_target_table(targets, highlight_types=None):
802
+ highlight_types = set(highlight_types or [])
803
+ print(f"{'name':<18} {'type':<6} {'base':<42} {'this':<24}")
804
+ print("-" * 94)
805
  for t in targets:
806
+ mark = " *" if (t.get("type") in highlight_types) else ""
807
+ print(f"{t['name']:<18} {t.get('type', '?'):<6} {t['base']:<42} {t['this']:<24}{mark}")
808
 
809
 
810
  def main():
 
 
 
811
  parser = argparse.ArgumentParser(
812
  description="LEM-Eval 8-PAC benchmark runner — target-driven, multi-writer",
813
  )
814
  parser.add_argument("--target", help="Target name from targets.yaml")
815
  parser.add_argument("--list-targets", action="store_true", help="List all targets and exit")
816
  parser.add_argument("--my-targets", action="store_true",
817
+ help="List targets whose type matches this machine's capabilities and exit")
818
+ parser.add_argument("--type", default=None,
819
+ help="Restrict to targets of this type (mlx|gguf). "
820
+ "Defaults to capability detection (mlx on Apple Silicon).")
821
  parser.add_argument("--n-questions", type=int, default=DEFAULT_N_QUESTIONS)
822
  parser.add_argument("--rounds", type=int, default=DEFAULT_ROUNDS)
823
  parser.add_argument("--task", default=None,
 
842
  cfg = load_targets()
843
  all_targets = cfg.get("targets", [])
844
 
845
+ # Resolve the set of types this invocation accepts.
846
+ if args.type:
847
+ if args.type not in SUPPORTED_TYPES:
848
+ parser.error(f"--type must be one of {sorted(SUPPORTED_TYPES)}, got {args.type!r}")
849
+ allowed_types = {args.type}
850
+ elif os.environ.get("LEM_TYPES"):
851
+ allowed_types = set(os.environ["LEM_TYPES"].split(","))
852
+ else:
853
+ allowed_types = detect_default_types()
854
+
855
  if args.list_targets:
856
+ _print_target_table(all_targets, highlight_types=allowed_types)
857
  return 0
858
  if args.my_targets:
859
+ mine = [t for t in all_targets if t.get("type") in allowed_types]
860
  if not mine:
861
+ print(f"No targets match this machine's types: {sorted(allowed_types)}")
862
  return 0
863
+ _print_target_table(mine, highlight_types=allowed_types)
864
  return 0
865
 
866
  if not args.target:
867
  parser.error("--target is required (or use --list-targets / --my-targets)")
868
 
869
  target = resolve_target(args.target, cfg)
870
+ target_type = target.get("type")
871
+ if target_type not in SUPPORTED_TYPES:
872
+ parser.error(f"target {args.target!r} has unknown type {target_type!r}")
873
+ if target_type == "gguf":
874
+ parser.error(
875
+ f"target {args.target!r} is type=gguf, but the gguf wrapper is not yet "
876
+ f"implemented. TODO: wire an OpenAI-SDK-against-Ollama wrapper at "
877
+ f"gguf_wrapper.py. For now, gguf targets sit in targets.yaml waiting."
878
+ )
879
 
880
  # Populate module globals so the lighteval custom-model loader picks
881
  # up the right identity when it instantiates MLXLMModel.
install.sh CHANGED
@@ -51,27 +51,42 @@ fi
51
 
52
  # --- clone each owned target's model repo ---------------------------------
53
 
54
- log "resolving targets owned by $(hostname)..."
55
  uv run --script eval.py --my-targets || true
56
 
57
- # Pre-clone each owned target's model repo into workspaces/<target>
58
- python3 - <<PY
59
- import os, subprocess, yaml, socket, sys
60
- host = socket.gethostname()
61
- with open('targets.yaml') as f:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  cfg = yaml.safe_load(f)
63
- for t in cfg.get('targets', []):
64
- if t.get('owner') != host:
65
  continue
66
- name = t['name']
67
- repo = t['this']
68
- dest = os.path.join('workspaces', name)
69
- if os.path.isdir(os.path.join(dest, '.git')):
70
  print(f" [{name}] already cloned, pulling")
71
- subprocess.run(['git', '-C', dest, 'pull', '--ff-only'], check=False)
72
  else:
73
  print(f" [{name}] cloning https://huggingface.co/{repo} → {dest}")
74
- subprocess.run(['git', 'clone', f'https://huggingface.co/{repo}', dest], check=True)
75
  PY
76
 
77
  # --- warm the uv cache so first eval.py run is fast -----------------------
 
51
 
52
  # --- clone each owned target's model repo ---------------------------------
53
 
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
+
63
+ types_env = os.environ.get("LEM_TYPES", "").strip()
64
+ if types_env:
65
+ allowed = set(t.strip() for t in types_env.split(","))
66
+ else:
67
+ allowed = set()
68
+ try:
69
+ import mlx_lm # noqa: F401
70
+ if platform.system() == "Darwin":
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
 
92
  # --- warm the uv cache so first eval.py run is fast -----------------------
lem-eval.sh CHANGED
@@ -81,31 +81,48 @@ run_target() {
81
  fi
82
  }
83
 
84
- # --- one pass over all targets owned by this host ------------------------
 
 
 
85
 
86
  once() {
87
- log "host=$HOST mode=once"
88
 
89
  if [[ ! -d "$LEM_BENCHMARKS_DIR/.git" ]]; then
90
  log "lem-benchmarks not cloned — run ./install.sh first"
91
  exit 1
92
  fi
93
 
94
- # Get list of targets owned by this host via python (avoids yaml-in-shell)
95
  local targets
96
- targets=$(python3 - <<PY
97
- import yaml, socket
98
- host = socket.gethostname()
99
- with open('targets.yaml') as f:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  cfg = yaml.safe_load(f)
101
- for t in cfg.get('targets', []):
102
- if t.get('owner') == host:
103
- print(t['name'])
104
  PY
105
  )
106
 
107
  if [[ -z "$targets" ]]; then
108
- log "no targets owned by $HOST in targets.yaml"
109
  exit 0
110
  fi
111
 
 
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"
91
 
92
  if [[ ! -d "$LEM_BENCHMARKS_DIR/.git" ]]; then
93
  log "lem-benchmarks not cloned — run ./install.sh first"
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()
103
+ if types_env:
104
+ allowed = set(t.strip() for t in types_env.split(","))
105
+ else:
106
+ allowed = set()
107
+ try:
108
+ import mlx_lm # noqa: F401
109
+ if platform.system() == "Darwin":
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
 
targets.yaml CHANGED
@@ -1,13 +1,14 @@
1
  # targets.yaml — declarative fleet spec for LEM-Eval workers.
2
  #
3
  # Each target is a (base, this) model pair that gets benchmarked together in
4
- # a paired A/B run. The `owner` field is the hostname of the worker that
5
- # should run this target workers filter by `hostname(3)` so adding or
6
- # retiring a machine is just editing this file and `git pull`.
 
7
  #
8
  # Each target is an independent canon. Workers writing to different targets
9
  # don't race because each target's .eval_results/ lives in a different model
10
- # repo (and its results/<model>/ path in LEM-benchmarks is also disjoint).
11
  #
12
  # Editing this file is the way to change the fleet. After an edit, commit
13
  # and push — workers pick up the new config on their next `git pull` cycle
@@ -23,25 +24,25 @@ defaults:
23
  targets:
24
 
25
  - name: lemer
26
- owner: studio
27
  base: mlx-community/gemma-4-e2b-it-4bit
28
  this: lthn/lemer
29
  notes: Gemma 4 E2B
30
 
31
  - name: lemma
32
- owner: studio
33
  base: mlx-community/gemma-4-e4b-it-4bit
34
  this: lthn/lemma
35
  notes: Gemma 4 E4B
36
 
37
  - name: lemmy
38
- owner: charon
39
  base: mlx-community/gemma-4-26b-a4b-it-4bit
40
  this: lthn/lemmy
41
- notes: Gemma 4 26B A4B MoE
42
 
43
  - name: lemrd
44
- owner: charon
45
  base: mlx-community/gemma-4-31b-it-4bit
46
  this: lthn/lemrd
47
- notes: Gemma 4 31B
 
1
  # targets.yaml — declarative fleet spec for LEM-Eval workers.
2
  #
3
  # Each target is a (base, this) model pair that gets benchmarked together in
4
+ # a paired A/B run. The `type` field says which inference backend the target
5
+ # needs 'mlx' runs on Apple Silicon via mlx_lm, 'gguf' runs on any machine
6
+ # that can serve GGUF (via Ollama or llama.cpp). Workers filter by type so
7
+ # partitioning across machines falls out of capability, not hostnames.
8
  #
9
  # Each target is an independent canon. Workers writing to different targets
10
  # don't race because each target's .eval_results/ lives in a different model
11
+ # repo (and its results/<target>/ path in LEM-benchmarks is also disjoint).
12
  #
13
  # Editing this file is the way to change the fleet. After an edit, commit
14
  # and push — workers pick up the new config on their next `git pull` cycle
 
24
  targets:
25
 
26
  - name: lemer
27
+ type: mlx
28
  base: mlx-community/gemma-4-e2b-it-4bit
29
  this: lthn/lemer
30
  notes: Gemma 4 E2B
31
 
32
  - name: lemma
33
+ type: mlx
34
  base: mlx-community/gemma-4-e4b-it-4bit
35
  this: lthn/lemma
36
  notes: Gemma 4 E4B
37
 
38
  - name: lemmy
39
+ type: gguf
40
  base: mlx-community/gemma-4-26b-a4b-it-4bit
41
  this: lthn/lemmy
42
+ notes: Gemma 4 26B A4B MoE — runs via GGUF on charon (Ollama endpoint)
43
 
44
  - name: lemrd
45
+ type: gguf
46
  base: mlx-community/gemma-4-31b-it-4bit
47
  this: lthn/lemrd
48
+ notes: Gemma 4 31B — runs via GGUF on charon (Ollama endpoint)