tuieval 0.2.0.dev158__py3-none-any.whl → 0.2.0.dev162__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tuieval/_version.py CHANGED
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '0.2.0.dev158'
22
- __version_tuple__ = version_tuple = (0, 2, 0, 'dev158')
21
+ __version__ = version = '0.2.0.dev162'
22
+ __version_tuple__ = version_tuple = (0, 2, 0, 'dev162')
23
23
 
24
24
  __commit_id__ = commit_id = None
tuieval/ctxbench.py CHANGED
@@ -20,7 +20,9 @@ The search starts at half the context the model runs with now and doubles, up to
20
20
  limit: what models.toml caps the context at (max_ctx, ctx, a context flag) doesn't bound it, since
21
21
  the measurement replaces those. Memory grows about linearly with the context, so two probes that
22
22
  passed predict the largest context that fits under the machine's limit; no probe goes above that
23
- prediction, and a failed probe is bisected against the largest that passed. A probe is stopped at
23
+ prediction, and a failed probe is bisected against the largest that passed. (A server that already
24
+ takes more than that limit at the smallest context, and passes, sizes its own memory: the
25
+ prediction doesn't cap it, and the probes and their guard decide.) A probe is stopped at
24
26
  once, while the server loads or works, when memory pressure rises, the machine starts swapping,
25
27
  or memory runs out. (A server that reaches the warning level at the smallest context, with nothing
26
28
  swapped, fills memory to a budget of its own: for it only critical pressure counts, besides
@@ -321,6 +323,7 @@ def search(try_ctx, start, upper, limit_gb=None, step=STEP, floor=FLOOR, max_sta
321
323
  Returns (probes in the order tried, why it stopped)."""
322
324
  tried, lo, hi, c = [], None, None, min(start, upper)
323
325
  why = f"{max_starts} server starts used"
326
+ budget = limit_gb # None once the tries show it doesn't describe this server
324
327
  while len(tried) < max_starts:
325
328
  emit("tune_step", message=f"[{len(tried) + 1}] context {c:,}", start=len(tried) + 1, max_starts=max_starts)
326
329
  try:
@@ -347,12 +350,20 @@ def search(try_ctx, start, upper, limit_gb=None, step=STEP, floor=FLOOR, max_sta
347
350
  if hi is not None and hi - lo <= step:
348
351
  why = f"{hi:,} failed: {next(p.error for p in tried if p.ctx == hi)}"
349
352
  break
350
- _, per, fit = predict([p for p in tried if p.ok], limit_gb)
353
+ smallest = min((p for p in tried if p.ok and p.mem_gb), key=lambda p: p.ctx, default=None)
354
+ if budget is not None and smallest and smallest.mem_gb >= budget:
355
+ # Over the budget at the smallest context that passed: the context isn't what takes the
356
+ # memory. The server fills memory to a budget of its own, so the prediction can't cap it.
357
+ emit("tune_step", message=f" it took {smallest.mem_gb:.1f} GB at {smallest.ctx:,} already, more than the "
358
+ f"{budget:.1f} GB set aside, and passed: this server sizes its own memory, so "
359
+ "the search goes by the tries, not by predicted memory")
360
+ budget = None
361
+ _, per, fit = predict([p for p in tried if p.ok], budget)
351
362
  nxt = min(upper, lo * 2) if hi is None else lo + _grid((hi - lo) / 2)
352
363
  if fit is not None and fit < nxt:
353
364
  if _grid(fit) - lo < min(step, upper - lo):
354
365
  at = min(upper, lo + step)
355
- why = (f"memory: {at:,} is predicted to need more than the {limit_gb:.1f} GB this machine has "
366
+ why = (f"memory: {at:,} is predicted to need more than the {budget:.1f} GB this machine has "
356
367
  f"for it ({per * 1000:.3f} GB per 1,000 tokens)")
357
368
  break
358
369
  nxt = _grid(fit)
tuieval/engine.py CHANGED
@@ -43,6 +43,7 @@ import shutil
43
43
  import signal
44
44
  import socket
45
45
  import statistics
46
+ import string
46
47
  import subprocess
47
48
  import tempfile
48
49
  import threading
@@ -133,9 +134,53 @@ def load_config(path):
133
134
  m.setdefault("served_name", m["label"] if server.get("model_is_path") else m["model"])
134
135
  m["vision"] = bool(m.get("vision") or m.get("mmproj"))
135
136
  m.setdefault("tags", [])
137
+ for name, server in cfg["servers"].items():
138
+ check_drafts(path, name, server)
136
139
  return cfg
137
140
 
138
141
 
142
+ DRAFT_KIND_RE = re.compile(r"^[a-z0-9_]+$")
143
+
144
+
145
+ def draft_names(server):
146
+ """The drafter placeholders a server's flags can use: {draft} (the model's `draft` file,
147
+ whatever it is) and {draft_<kind>} for each kind in the server's `drafts` table."""
148
+ return ["draft"] + [f"draft_{k}" for k in server.get("drafts", {})]
149
+
150
+
151
+ def draft_fields(args):
152
+ """The drafter placeholders a list of arguments uses."""
153
+ return {name for a in args for _, name, _, _ in string.Formatter().parse(str(a))
154
+ if name and (name == "draft" or name.startswith("draft_"))}
155
+
156
+
157
+ def draft_literals(server):
158
+ """Format values that leave the drafter placeholders in place: tune options and profiles keep
159
+ them, and the path is filled in when the server starts."""
160
+ return {n: "{" + n + "}" for n in draft_names(server)}
161
+
162
+
163
+ def check_drafts(path, name, server):
164
+ """A server's `drafts` table and the drafter placeholders in its tune options."""
165
+ kinds = server.get("drafts", {})
166
+ if not isinstance(kinds, dict) or not all(isinstance(v, dict) for v in kinds.values()):
167
+ raise ConfigError(f"{path}: [servers.{name}.drafts] must map each kind to the GGUF metadata "
168
+ f"that identifies it, e.g. kind = {{\"general.architecture\" = \"...\"}}")
169
+ for kind in kinds:
170
+ if not DRAFT_KIND_RE.match(kind):
171
+ raise ConfigError(f"{path}: [servers.{name}.drafts] kind {kind!r} must be lowercase letters, digits or '_'")
172
+ known = set(draft_names(server))
173
+ for knob, options in server.get("tune", {}).items():
174
+ for i, o in enumerate(options):
175
+ used = draft_fields(o)
176
+ if used - known:
177
+ raise ConfigError(f"{path}: [servers.{name}.tune] {knob} uses {{{sorted(used - known)[0]}}}, "
178
+ f"but [servers.{name}.drafts] has no such kind")
179
+ if used and i == 0:
180
+ raise ConfigError(f"{path}: [servers.{name}.tune] {knob}: the first option is the default for "
181
+ f"every model, so it can't need a drafter file")
182
+
183
+
139
184
  def fit_check(server):
140
185
  """Whether tuieval sizes the context for this server's models from GGUF headers (machines.fit,
141
186
  which assumes llama.cpp's memory use). By default only servers whose command takes {ctx}, i.e.
@@ -290,6 +335,7 @@ class Serving:
290
335
  identity: dict # output-affecting settings, part of the results fingerprint
291
336
  profile: dict | None = None
292
337
  mtp_layers: int = 0
338
+ drafts: tuple = () # drafter placeholders this model's `draft` file fills ({draft}, {draft_<kind>})
293
339
  need_gb: float | None = None # estimated GPU memory at ctx (from the fit check); None when unknown
294
340
  ctx_source: str = "" # "measured" when ctx comes from tuieval tune --ctx on this machine
295
341
  ctx_measured: dict | None = None # that measurement (profiles.load_context), also when it's out of date
@@ -1435,6 +1481,21 @@ class Engine:
1435
1481
  vals = self.knob_values(machine)
1436
1482
  return [a.format(**vals) for opts in server.get("tune", {}).values() if opts for a in opts[0]]
1437
1483
 
1484
+ def drafts(self, m):
1485
+ """The drafter placeholders a model's `draft` file fills: {draft} when the file exists, and
1486
+ {draft_<kind>} for each kind of its server whose GGUF metadata the file has."""
1487
+ path = expand(m.get("draft", ""))
1488
+ if not path or not os.path.isfile(path):
1489
+ return ()
1490
+ names = ["draft"]
1491
+ for kind, want in self.cfg["servers"][m["server"]].get("drafts", {}).items():
1492
+ try:
1493
+ if machines.gguf_matches(path, want):
1494
+ names.append(f"draft_{kind}")
1495
+ except (OSError, ValueError):
1496
+ break # not a readable GGUF: no kind
1497
+ return tuple(names)
1498
+
1438
1499
  def serving(self, m, machine=None):
1439
1500
  """Serving for a model on this machine: context from the fit check, speed flags from its
1440
1501
  tuned profile (or the defaults), and the output-affecting identity."""
@@ -1455,16 +1516,23 @@ class Engine:
1455
1516
  if fit_check(server):
1456
1517
  mmproj = expand(m.get("mmproj", ""))
1457
1518
  extra = os.path.getsize(mmproj) if mmproj and os.path.isfile(mmproj) else 0
1519
+ draft = expand(m.get("draft", "")) # counted whether or not the tuned flags use it
1520
+ extra += os.path.getsize(draft) if draft and os.path.isfile(draft) else 0
1458
1521
  f = machines.fit(path, mc, kv_type=kv or "f16", headroom_gb=self.headroom_gb(mc), extra_bytes=extra,
1459
1522
  want_ctx=want)
1460
1523
  ctx, fits, note, need = f.max_ctx, f.fits, f.note, f.need_gb
1461
1524
  except (OSError, ValueError) as e:
1462
1525
  note = f"couldn't read the GGUF header ({e}); context not checked"
1463
1526
  profile, perf, perf_source = None, [], "n/a"
1527
+ drafts = self.drafts(m)
1464
1528
  if server.get("cmd") and (server.get("perf") or server.get("tune")):
1465
1529
  perf = list(server.get("perf", []))
1466
1530
  profile = profiles.load(mc.id, m["label"], self.tuning_dir)
1467
- if profile:
1531
+ if profile and draft_fields(profile["args"]) - set(drafts):
1532
+ # tuned with a drafter file that is gone or is another kind now: its flags can't run
1533
+ perf += self.default_knob_args(server, mc)
1534
+ perf_source = "outdated: the drafter file it was tuned with is missing or changed"
1535
+ elif profile:
1468
1536
  perf += list(profile["args"])
1469
1537
  why = profiles.stale(profile, self.server_version(m), size)
1470
1538
  perf_source = f"outdated: {why}" if why else \
@@ -1498,7 +1566,7 @@ class Engine:
1498
1566
  # resident), so both are part of what a result is valid for.
1499
1567
  identity["machine"] = mc.id
1500
1568
  identity["perf"] = perf
1501
- sv = Serving(mc, ctx, kv, fits, note, perf, perf_source, identity, profile, mtp, need,
1569
+ sv = Serving(mc, ctx, kv, fits, note, perf, perf_source, identity, profile, mtp, drafts, need,
1502
1570
  ctx_source=source, ctx_measured=measured, ctx_note=ctx_note)
1503
1571
  self._serving[key] = sv
1504
1572
  return sv
@@ -1515,7 +1583,8 @@ class Engine:
1515
1583
  ident["endpoint"], ident["quantization"] = ep.get("tag"), ep.get("quantization")
1516
1584
  return ident
1517
1585
  values = {"model": os.path.basename(m["model"]), "served_name": "<name>", "port": "<port>", "ctx": "<ctx>",
1518
- "kv_type": kv or "", "mmproj": os.path.basename(m.get("mmproj", ""))}
1586
+ "kv_type": kv or "", "mmproj": os.path.basename(m.get("mmproj", "")),
1587
+ **{n: os.path.basename(m.get("draft", "")) for n in draft_names(server)}}
1519
1588
  cmd = [a.format(**values) for a in server["cmd"]]
1520
1589
  if m.get("mmproj"):
1521
1590
  cmd += [a.format(**values) for a in server.get("vision_args", [])]
@@ -1541,7 +1610,8 @@ class Engine:
1541
1610
  port = port or server["port"]
1542
1611
  values = {"model": expand(m["model"]), "served_name": m["served_name"], "port": port,
1543
1612
  "mmproj": expand(m.get("mmproj", "")), "ctx": ctx or sv.ctx or "", "kv_type": sv.kv_type or "",
1544
- "root": self.root, **self.knob_values(sv.machine)}
1613
+ "root": self.root, **self.knob_values(sv.machine),
1614
+ **{n: expand(m.get("draft", "")) for n in draft_names(server)}}
1545
1615
  cmd = [expand(a, **values) for a in server["cmd"]]
1546
1616
  cmd += [expand(a, **values) for a in (sv.perf_args if perf_args is None else perf_args)]
1547
1617
  if m.get("mmproj"):
@@ -2046,6 +2116,8 @@ class Engine:
2046
2116
  raise ModelFailed(f"model not found: {model_path}")
2047
2117
  if m.get("mmproj") and not os.path.isfile(expand(m["mmproj"])):
2048
2118
  raise ModelFailed(f"mmproj file not found: {expand(m['mmproj'])}")
2119
+ if m.get("draft") and not os.path.isfile(expand(m["draft"])):
2120
+ raise ModelFailed(f"draft file not found: {expand(m['draft'])}")
2049
2121
  if cwd and not os.path.isdir(cwd):
2050
2122
  raise ModelFailed(f"server directory not found: {cwd}")
2051
2123
  missing = missing_program(cmd, cwd)
tuieval/machines.py CHANGED
@@ -252,9 +252,9 @@ def _value(f, vtype, keep_arrays):
252
252
 
253
253
 
254
254
  @functools.lru_cache(maxsize=64)
255
- def read_gguf(path):
256
- """Metadata from a GGUF file's header (no tensors are read). Arrays are kept only for the
257
- per-layer attention keys; tokenizer arrays are skipped."""
255
+ def gguf_metadata(path):
256
+ """The key-value pairs of a GGUF file's header (no tensors are read). Arrays are kept only for
257
+ the per-layer attention keys; other arrays (the tokenizer's) are skipped."""
258
258
  path = os.path.expanduser(path)
259
259
  with open(path, "rb") as f:
260
260
  if f.read(4) != b"GGUF":
@@ -272,6 +272,20 @@ def read_gguf(path):
272
272
  val = _value(f, vtype, keep)
273
273
  if val is not None:
274
274
  kv[key] = val
275
+ return kv
276
+
277
+
278
+ def gguf_matches(path, want):
279
+ """Whether a GGUF file's header has these values: {"key": value, …}. A key the file doesn't
280
+ have counts as false."""
281
+ kv = gguf_metadata(path)
282
+ return all(kv.get(k, False) == v for k, v in want.items())
283
+
284
+
285
+ def read_gguf(path):
286
+ """What tuieval needs to know about a model, from its GGUF header."""
287
+ path = os.path.expanduser(path)
288
+ kv = gguf_metadata(path)
275
289
  arch = kv.get("general.architecture", "")
276
290
  get = lambda k, d=None: kv.get(f"{arch}.{k}", d) # noqa: E731
277
291
  layers = int(get("block_count", 0) or 0)
tuieval/tune.py CHANGED
@@ -354,14 +354,18 @@ def similarity(texts, reference, chars=600):
354
354
  # ------------------------------------------------------------------ knobs
355
355
  def knobs(eng, m, sv=None):
356
356
  """{knob: [resolved option args, …]} for this model on this machine, with options that can't
357
- apply removed (draft-mtp on a model without MTP layers) and duplicates merged."""
357
+ apply removed (draft-mtp on a model without MTP layers, an option that takes a drafter file the
358
+ model doesn't have) and duplicates merged. Drafter placeholders stay as written: the profile
359
+ keeps them and the path is filled in when the server starts."""
358
360
  server = eng.cfg["servers"][m["server"]]
359
361
  sv = sv or eng.serving(m)
360
- vals = eng.knob_values(sv.machine)
362
+ vals = {**eng.knob_values(sv.machine), **engine_mod.draft_literals(server)}
361
363
  out = {}
362
364
  for name, options in server.get("tune", {}).items():
363
365
  seen, opts = set(), []
364
366
  for o in options:
367
+ if engine_mod.draft_fields(o) - set(sv.drafts):
368
+ continue # needs a drafter file (of a kind) this model doesn't have
365
369
  args = [a.format(**vals) for a in o]
366
370
  if sv.mtp_layers == 0 and any("draft-mtp" in a for a in args) and sv.identity.get("model_bytes"):
367
371
  continue # the GGUF was read and has no MTP layers
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: tuieval
3
- Version: 0.2.0.dev158
3
+ Version: 0.2.0.dev162
4
4
  Summary: Evaluate local and frontier LLMs on your own questions: accuracy, speed, tokens and PASS/FAIL verdicts, in the terminal.
5
5
  Project-URL: Homepage, https://github.com/ashe-wb/tuieval
6
6
  Project-URL: Issues, https://github.com/ashe-wb/tuieval/issues
@@ -1,19 +1,19 @@
1
1
  tuieval/__init__.py,sha256=myVXVX7htbwezW6k3x_FuKgn1RSZ2WcTaDEMByGn6Wg,312
2
2
  tuieval/__main__.py,sha256=E6Gls0DNz8GQK2K-kOUIx8cYhgANW_CH54VKrfCfs14,52
3
- tuieval/_version.py,sha256=fDKT-fqtUr9K6z3Mb0pFLVcYHLCx_zjwXd_-sC7Qd0Q,537
3
+ tuieval/_version.py,sha256=pxmDFVRvLYhGnEkyqrkqleADe-92ALGEewQiuRrBhxY,537
4
4
  tuieval/agents.py,sha256=XmY4d4PAnC7BQcs_6KO9WTuIdpnwYVAdyhqItybWdAM,15408
5
5
  tuieval/builtin.toml,sha256=QLQP1nh577RW6x0Z38JKNES-MPTSmlZAcxD5Javbk4Q,4768
6
6
  tuieval/cli.py,sha256=Q9-b9sg6LSAfNq6o-c3J3hiOIoINgvH_Fe_U1x-0W4U,4915
7
7
  tuieval/client.py,sha256=O77uftaxqgQ8b8rMnpR5822kmYFfr574w1pZlaSOFEE,14304
8
8
  tuieval/compare.py,sha256=T5MDIkNzPGTFUvYr1EzxVGGlCdvTlO1v5De3gN0Eocw,39654
9
- tuieval/ctxbench.py,sha256=li2l_eAS-63Sj4Qq6htLgdGnRSqeyxAg1LU1Za-Z5ms,26903
9
+ tuieval/ctxbench.py,sha256=Xahl_o-r25Aq9LFaZXlZMzLhARIayT8gpsAQxYwuUYA,27898
10
10
  tuieval/dates.py,sha256=CVazlwNjCRhD__D12zXLdeqF2ySt15X3xLUQeE-o6PY,6293
11
11
  tuieval/doctor.py,sha256=j2MdDORstsAGPnRmpsnxau1_fR6sTc_oEFGM5zugTJU,7246
12
- tuieval/engine.py,sha256=OfAQx4s9A7PfaPJDr5U_MBp69kS3-tI99aPnrCYZ8mU,141469
12
+ tuieval/engine.py,sha256=novRrmz7AeEs-sQqEImdN5qFW5m_QpD-GJgGZ_ZA8oM,145365
13
13
  tuieval/export.py,sha256=dbHQgL_ubWtIPM1sLzAew_gETnrDJyd0zgqVA5vkpXM,9657
14
14
  tuieval/insights.py,sha256=hIJp1n0eZeoo9QCyS5-OChv70ItSqV8jSsInoh4Stm0,29591
15
15
  tuieval/logs.py,sha256=01gZK6tf53dIThaIrs1bEsz9eqKYVlcxpyaLnSPTVxo,8127
16
- tuieval/machines.py,sha256=KEZ7tJWdGdlIjNDfd8sgXMyV-GclcdQLoubNimz5tbs,21956
16
+ tuieval/machines.py,sha256=a4bmR-EuNQ1l_w4g44Yjdn-xPQ6tLP-t0ZH-QoPAhOg,22410
17
17
  tuieval/onboard.py,sha256=IYETVDWCCo9vF0Dtj4_rr9VanYeCky8PwP3-2g5A_l0,6215
18
18
  tuieval/packs.py,sha256=KOj0BkwsB2124aslGyauZonyyGqtSrCJ-WAozEntmqE,17466
19
19
  tuieval/profiles.py,sha256=3GribubCOCRTi_rClLxVynBeX2SBYTig0XObAlS8lzg,5300
@@ -23,7 +23,7 @@ tuieval/run_evals.py,sha256=OwS4HGkCOlU0cGcToqJKxFpL8GQdMFW5PB6SitSAfrE,56337
23
23
  tuieval/scaffold.py,sha256=YBOqniJpf_GtKKAFF3_OHxxMGbmTWdFjcClGcOnrrKE,12130
24
24
  tuieval/selftest.py,sha256=cIGSDCrCK-QISAXjKSJDB4sD-WwS32bn3Gn4Y0oGoF8,11502
25
25
  tuieval/tui.py,sha256=5BtqHoEtqBHRCrh0qPn2Vmg-4hSjjtlfPQ5qoysHlb0,211349
26
- tuieval/tune.py,sha256=izz1Qs-d9PrWAqEZpyrLxfrlhlaouif9uFQSeJveL0k,41294
26
+ tuieval/tune.py,sha256=V43Lo3x-flTuUFYXRt2_aqmpo4RML0adP-XUHWTgfRQ,41659
27
27
  tuieval/verdict.py,sha256=l51SiZt50LdPdcHuyAB1us6cZrARlJdgjrKgl2AluME,21229
28
28
  tuieval/watch_proxy.py,sha256=bnDO1i6n6yUs1hODoUWcMppJMGPavoQqs6aNYrIxpT8,11416
29
29
  tuieval/workspace.py,sha256=V_HhkaN1odr0OpjNsPYradRWLpzDldM7SwpvxohBL4U,895
@@ -51,8 +51,8 @@ tuieval/templates/packs/tool_call/pack.toml,sha256=n4bx0lGJHSmW41uVqhfIXJ2BWZpmT
51
51
  tuieval/templates/packs/tool_call/system.txt,sha256=mKxu-lB-0YjLHXdgeFJa8x2C180OvcNz5cHv2N5Bg3U,254
52
52
  tuieval/templates/packs/tool_call/tests.yaml,sha256=Nv7c4syrzJ9cU8EBKSK_1ZSFx9V02aCjW4-2TBCPT7s,1859
53
53
  tuieval/templates/packs/tool_call/tools.yaml,sha256=HgxCkh0On2VwbHSsjAGM8tNCK7ZtKLGrs7lMCn3Fprs,1048
54
- tuieval-0.2.0.dev158.dist-info/METADATA,sha256=2W7y-2ulqEgP62OuDUuVeXE9ffTDHn2mBbHAYeTXL_M,15306
55
- tuieval-0.2.0.dev158.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
56
- tuieval-0.2.0.dev158.dist-info/entry_points.txt,sha256=7eIhi1GpFxBP2OLJV02Nn8LwsNuO512eKOGt1IBbj04,45
57
- tuieval-0.2.0.dev158.dist-info/licenses/LICENSE,sha256=7wfRgGtBGH1aXhZkIn47oUznqKC18kEPMvUVgol7Ffc,1077
58
- tuieval-0.2.0.dev158.dist-info/RECORD,,
54
+ tuieval-0.2.0.dev162.dist-info/METADATA,sha256=QuoFHbrGop9LK3iWs23AV5To3AhtkXJqcQbepEEHW8w,15306
55
+ tuieval-0.2.0.dev162.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
56
+ tuieval-0.2.0.dev162.dist-info/entry_points.txt,sha256=7eIhi1GpFxBP2OLJV02Nn8LwsNuO512eKOGt1IBbj04,45
57
+ tuieval-0.2.0.dev162.dist-info/licenses/LICENSE,sha256=7wfRgGtBGH1aXhZkIn47oUznqKC18kEPMvUVgol7Ffc,1077
58
+ tuieval-0.2.0.dev162.dist-info/RECORD,,