tuieval 0.2.0.dev162__tar.gz → 0.2.0.dev164__tar.gz
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-0.2.0.dev162 → tuieval-0.2.0.dev164}/CHANGELOG.md +2 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/PKG-INFO +1 -1
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/models.md +3 -2
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/_version.py +2 -2
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/ctxbench.py +116 -23
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/machines.py +35 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/run_evals.py +2 -1
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/tests/test_tuieval.py +106 -2
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/.gitignore +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/LICENSE +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/README.md +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/RELEASING.md +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/agent-packs.md +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/brand/README.md +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/brand/favicon.ico +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/brand/readme-header.png +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/brand/social-preview.png +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/brand/tuieval-icon-1024.png +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/brand/tuieval-icon-128.png +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/brand/tuieval-icon-16.png +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/brand/tuieval-icon-16.svg +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/brand/tuieval-icon-256.png +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/brand/tuieval-icon-32.png +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/brand/tuieval-icon-48.png +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/brand/tuieval-icon-512.png +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/brand/tuieval-icon-64.png +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/brand/tuieval-icon-animated.svg +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/brand/tuieval-icon.svg +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/tui-answer-reasoning.png +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/tui-run-reasoning.png +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/images/tui-setup.png +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/docs/writing-packs.md +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/pyproject.toml +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/__init__.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/__main__.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/agents.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/builtin.toml +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/cli.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/client.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/compare.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/dates.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/doctor.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/engine.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/export.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/graders/__init__.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/graders/answer.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/graders/code.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/graders/rag.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/graders/reply.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/graders/tool_call.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/insights.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/logs.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/onboard.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/packs.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/profiles.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/pta.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/remove.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/scaffold.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/selftest.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/models.toml +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/answer/pack.toml +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/answer/system.txt +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/answer/tests.yaml +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/code/pack.toml +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/code/system.txt +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/code/tests.yaml +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/rag/pack.toml +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/rag/system.txt +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/rag/tests.yaml +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/reply/pack.toml +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/reply/system.txt +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/reply/tests.yaml +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/tool_call/pack.toml +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/tool_call/system.txt +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/tool_call/tests.yaml +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/tool_call/tools.yaml +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/tui.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/tune.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/verdict.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/watch_proxy.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/workspace.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/yamlout.py +0 -0
- {tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/tests/mock_server.py +0 -0
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- `tuieval tune --ctx` starts where the model file says the limit is, instead of climbing from a small context: for a GGUF on a llama.cpp-style server it estimates the largest context that fits (weights, buffers, and the KV cache per token with sliding-window layers counted as llama.cpp keeps them), tries that first, and lets the first reading predict whether more fits. Typically 1 or 2 server starts, down from 3 to 6 (Gemma 4 31B: one, at its 262,144 limit, where it took five). The estimate is dropped when a try's memory is more than 25% off it; MLA models, models larger than memory and servers that size their own memory keep the doubling search. The saved measurement records where it started (`started_from`, `estimated_ctx`).
|
|
6
|
+
|
|
5
7
|
- Drafter files: a model can name a separate drafter file (`draft = "…gguf"`), and tune options that use `{draft}` are offered only to models that have one. A server's `[servers.<name>.drafts]` table names kinds of drafter by GGUF metadata, for options that use `{draft_<kind>}`. See docs/models.md.
|
|
6
8
|
- Fix: `tuieval tune --ctx` stopped early ("predicted to need more memory") on servers that fill memory to their own budget whatever the context. When the smallest context that passed already took more than the memory set aside, the prediction no longer caps the search.
|
|
7
9
|
- Fix: `tuieval tune --ctx` found no working context for servers that fill memory to their own budget and run with macOS memory pressure at the warning level. When the first try reaches that level with nothing swapped, tries are judged by swapping, memory running out and critical pressure instead.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: tuieval
|
|
3
|
-
Version: 0.2.0.
|
|
3
|
+
Version: 0.2.0.dev164
|
|
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
|
|
@@ -167,9 +167,10 @@ The fit check estimates the context from the model file, and only for servers th
|
|
|
167
167
|
|
|
168
168
|
1. It starts the server with a context, sends a built-in document that fills it (sized from the token counts the server reports, so any tokenizer works) with one fact near the start, and asks for that fact.
|
|
169
169
|
2. The try passes when the answer is right, the server read the whole document (a server that cuts long prompts short fails here), and the machine stayed healthy: no macOS memory pressure, no swapping, memory left on Linux. A try is stopped the moment one of those turns bad, also while the server is still loading. The next try waits until the machine has recovered, so the pressure one try leaves behind can't fail the next. Some servers fill memory to a budget of their own and run with macOS memory pressure at the warning level: when the very first try reaches it with nothing swapped out, it is tried again, and from then on a try is stopped only for swapping, memory running out or critical pressure.
|
|
170
|
-
3.
|
|
170
|
+
3. For a GGUF on a server tuieval sizes from the model file (one whose `cmd` takes `{ctx}`, like llama.cpp), it first works out from the file where the limit is: the weights (with an `mmproj` and `draft`), an allowance for buffers, and the KV cache per token of context, counting sliding-window layers as llama.cpp keeps them (their window only, whatever the context). The first try is at that estimate (or at the model's own limit when that fits by the estimate), so there are no small tries on the way up. A try that passes predicts from its memory reading whether a larger context fits, and the next try goes straight there; a first try that fails is followed by one 15% lower, then halving. When a try's memory is more than 25% off the estimate, the estimate is dropped and the search goes by the tries alone. There is no estimate for MLA models (a compressed cache of its own shape), sliding windows without a per-layer pattern in the file, models larger than the machine's memory, or servers that size their own memory; the output says which.
|
|
171
|
+
4. Without an estimate (or with `--start N`), it starts at half the context the model runs with now (32768 when that isn't known) and doubles. Memory grows about linearly with the context, so two tries that passed predict the largest context that fits in the machine's memory (less `memory_headroom_gb`, and less whatever other apps hold now); no try goes above the prediction, and a failed try is bisected against the largest that passed. A server that takes more than that at the smallest context and still passes sizes its own memory (it fills a budget of its own, whatever the context): the prediction doesn't cap it, and it keeps doubling until a try fails or is stopped.
|
|
171
172
|
|
|
172
|
-
Expect 3 to 5
|
|
173
|
+
Expect 1 or 2 server starts from an estimate (one when the model's own limit fits), 3 to 5 without one; the largest take as long as the server needs to read that many tokens. It won't start when memory pressure is already elevated or the model is larger than the memory free now (unless the model is larger than the machine's memory altogether: a server that reads its model from disk as needed is judged by the tries alone).
|
|
173
174
|
|
|
174
175
|
Memory is read off the machine, not the server's processes: the memory available before the server starts, less the lowest it falls to while the context is full (VRAM on discrete GPUs). On a Mac, available memory is RAM less what is held and can't be given back (anonymous and wired pages and the compressor, from `vm_stat`), so files a server maps and reads on demand don't count against it, and the reading is in the same terms as the memory it is compared with.
|
|
175
176
|
|
|
@@ -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.
|
|
22
|
-
__version_tuple__ = version_tuple = (0, 2, 0, '
|
|
21
|
+
__version__ = version = '0.2.0.dev164'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 2, 0, 'dev164')
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -16,18 +16,24 @@ for that fact. The probe passes when the answer is right, the server read the wh
|
|
|
16
16
|
server that cuts long prompts short reports fewer tokens, or loses the fact), and the machine
|
|
17
17
|
stayed healthy. Filling matters: some servers only take memory as the context fills.
|
|
18
18
|
|
|
19
|
-
The search
|
|
20
|
-
|
|
21
|
-
the
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
The search runs up to the model's own limit: what models.toml caps the context at (max_ctx, ctx,
|
|
20
|
+
a context flag) doesn't bound it, since the measurement replaces those. It starts where the model
|
|
21
|
+
file says the limit is (estimate: the weights, buffers and the KV cache per token, on llama.cpp's
|
|
22
|
+
terms, against the memory free now), so the first try usually settles it: a try that passes
|
|
23
|
+
predicts from its memory reading whether a larger one fits, and one that fails is halved. Without
|
|
24
|
+
an estimate (a server that sizes its own memory, MLA, a model larger than memory, --start) it
|
|
25
|
+
starts at half the context the model runs with now and doubles. Memory grows about linearly with
|
|
26
|
+
the context, so two probes that passed predict the largest context that fits under the machine's
|
|
27
|
+
limit; no probe goes above that prediction, and a failed probe is bisected against the largest that
|
|
28
|
+
passed. (A server that already
|
|
24
29
|
takes more than that limit at the smallest context, and passes, sizes its own memory: the
|
|
25
30
|
prediction doesn't cap it, and the probes and their guard decide.) A probe is stopped at
|
|
26
31
|
once, while the server loads or works, when memory pressure rises, the machine starts swapping,
|
|
27
32
|
or memory runs out. (A server that reaches the warning level at the smallest context, with nothing
|
|
28
33
|
swapped, fills memory to a budget of its own: for it only critical pressure counts, besides
|
|
29
34
|
swapping and memory running out.) The next probe waits until the machine has recovered (pressure back to normal,
|
|
30
|
-
the memory given back), so one probe's pressure can't fail the next. Typically
|
|
35
|
+
the memory given back), so one probe's pressure can't fail the next. Typically 1 or 2 server starts
|
|
36
|
+
from an estimate, 3 to 5 without one.
|
|
31
37
|
|
|
32
38
|
Memory is read off the machine, not the server's processes: available memory before the server
|
|
33
39
|
starts less the lowest it falls to. Resident memory would count files a server maps and reads on
|
|
@@ -38,7 +44,9 @@ A server tuieval doesn't start, or can't set the context of, is only verified at
|
|
|
38
44
|
model declares (max_context): one probe, nothing saved.
|
|
39
45
|
"""
|
|
40
46
|
import dataclasses
|
|
47
|
+
import glob
|
|
41
48
|
import os
|
|
49
|
+
import re
|
|
42
50
|
import threading
|
|
43
51
|
import time
|
|
44
52
|
|
|
@@ -50,7 +58,13 @@ from . import tune
|
|
|
50
58
|
ANSWER_TOKENS = 1024 # room for the answer (and any thinking) in a probe
|
|
51
59
|
STEP = 8192 # how close to the true maximum the search gets
|
|
52
60
|
FLOOR = machines.MIN_CTX # the smallest context tried
|
|
53
|
-
FIRST = 32768 # the first context tried for a model whose usual context isn't known
|
|
61
|
+
FIRST = 32768 # the first context tried for a model whose usual context isn't known (and no
|
|
62
|
+
# estimate); also the largest at which pressure before a pass says how a server runs
|
|
63
|
+
ESTIMATE_BUFFERS_GB = 1.0 # the estimate's buffers: this, plus this share of the weights. Gemma 4 31B Q8_0 with
|
|
64
|
+
ESTIMATE_BUFFERS_SHARE = 0.15 # its mmproj (31.5 GB) took 38.2 GB on llama.cpp before its context: 6.7 GB more,
|
|
65
|
+
# 1.2 of them sliding windows; this allows 5.7 GB besides those
|
|
66
|
+
ESTIMATE_OFF = 0.25 # a reading further than this share from the estimate means it doesn't apply
|
|
67
|
+
ESTIMATE_BACKOFF = 0.85 # a first try at the estimate that fails: the next is this share of it
|
|
54
68
|
APART = 0.8 # memory per token is read off two probes at least this far apart (the lower one
|
|
55
69
|
# at most this share of the higher): closer ones differ by less than the noise
|
|
56
70
|
MAX_STARTS = 8
|
|
@@ -297,16 +311,25 @@ def memory_gb(eng, m, info, guard):
|
|
|
297
311
|
return round(taken, 2) if taken else None
|
|
298
312
|
|
|
299
313
|
|
|
300
|
-
def predict(passed, limit_gb):
|
|
314
|
+
def predict(passed, limit_gb, per_gb=None):
|
|
301
315
|
"""(base_gb, gb_per_token, largest context predicted to fit) from the largest context that
|
|
302
316
|
passed with a memory reading and the nearest one well below it (APART). The third is None when
|
|
303
|
-
memory doesn't grow with the context (nothing to predict) or there aren't two such readings.
|
|
317
|
+
memory doesn't grow with the context (nothing to predict) or there aren't two such readings.
|
|
318
|
+
per_gb: the memory per token estimated from the model file. With it, one reading is enough
|
|
319
|
+
(and it stands in for two readings too close together to tell growth from noise), unless that
|
|
320
|
+
reading is less than the cache alone would take: then the estimate doesn't describe this server."""
|
|
304
321
|
pts = sorted((p.ctx, p.mem_gb) for p in passed if p.mem_gb)
|
|
305
|
-
if
|
|
322
|
+
if not pts:
|
|
306
323
|
return None, None, None
|
|
307
324
|
c2, g2 = pts[-1]
|
|
308
|
-
|
|
309
|
-
|
|
325
|
+
lower = [(c, g) for c, g in pts[:-1] if c <= APART * c2]
|
|
326
|
+
if lower or (len(pts) >= 2 and not per_gb):
|
|
327
|
+
c1, g1 = lower[-1] if lower else pts[0]
|
|
328
|
+
per = (g2 - g1) / (c2 - c1)
|
|
329
|
+
elif per_gb and g2 > per_gb * c2:
|
|
330
|
+
per = per_gb
|
|
331
|
+
else:
|
|
332
|
+
return None, None, None
|
|
310
333
|
base = g2 - per * c2
|
|
311
334
|
if per <= 0 or limit_gb is None:
|
|
312
335
|
return base, max(per, 0.0), None
|
|
@@ -318,10 +341,14 @@ def _grid(n):
|
|
|
318
341
|
|
|
319
342
|
|
|
320
343
|
def search(try_ctx, start, upper, limit_gb=None, step=STEP, floor=FLOOR, max_starts=MAX_STARTS,
|
|
321
|
-
emit=lambda *a, **k: None):
|
|
344
|
+
emit=lambda *a, **k: None, estimated=None):
|
|
322
345
|
"""Probe contexts until the largest that works is known to within `step`. try_ctx(ctx) -> Probe.
|
|
323
|
-
|
|
346
|
+
estimated: (fixed GB, GB per token) from the model file (see estimate), so that the first try that
|
|
347
|
+
passes already predicts the largest context that fits. A try whose memory reading is off the
|
|
348
|
+
estimate by more than ESTIMATE_OFF drops it: the search goes by the tries from there. Returns
|
|
349
|
+
(probes in the order tried, why it stopped)."""
|
|
324
350
|
tried, lo, hi, c = [], None, None, min(start, upper)
|
|
351
|
+
per_gb = estimated[1] if estimated else None
|
|
325
352
|
why = f"{max_starts} server starts used"
|
|
326
353
|
budget = limit_gb # None once the tries show it doesn't describe this server
|
|
327
354
|
while len(tried) < max_starts:
|
|
@@ -334,12 +361,19 @@ def search(try_ctx, start, upper, limit_gb=None, step=STEP, floor=FLOOR, max_sta
|
|
|
334
361
|
break
|
|
335
362
|
tried.append(r)
|
|
336
363
|
emit("tune_result", message=" " + r.summary(), result=r)
|
|
364
|
+
if per_gb and r.ok and r.mem_gb:
|
|
365
|
+
expected = estimated[0] + estimated[1] * c
|
|
366
|
+
if abs(r.mem_gb - expected) > ESTIMATE_OFF * expected:
|
|
367
|
+
per_gb = None
|
|
368
|
+
emit("tune_step", message=f" it took {r.mem_gb:.1f} GB where the estimate said {expected:.1f} GB: the "
|
|
369
|
+
"model file doesn't describe this server's memory, so the search goes by the "
|
|
370
|
+
"tries from here")
|
|
337
371
|
if r.ok:
|
|
338
372
|
lo = max(lo or 0, c)
|
|
339
373
|
else:
|
|
340
374
|
hi = min(hi or c, c)
|
|
341
|
-
if lo is None: # nothing has worked yet: halve
|
|
342
|
-
c = _grid(hi // 2)
|
|
375
|
+
if lo is None: # nothing has worked yet: halve (a first try at the estimate: a little below it)
|
|
376
|
+
c = _grid(hi * ESTIMATE_BACKOFF) if estimated and len(tried) == 1 else _grid(hi // 2)
|
|
343
377
|
if c < floor:
|
|
344
378
|
why = f"nothing from {floor:,} up worked"
|
|
345
379
|
break
|
|
@@ -358,7 +392,7 @@ def search(try_ctx, start, upper, limit_gb=None, step=STEP, floor=FLOOR, max_sta
|
|
|
358
392
|
f"{budget:.1f} GB set aside, and passed: this server sizes its own memory, so "
|
|
359
393
|
"the search goes by the tries, not by predicted memory")
|
|
360
394
|
budget = None
|
|
361
|
-
_, per, fit = predict([p for p in tried if p.ok], budget)
|
|
395
|
+
_, per, fit = predict([p for p in tried if p.ok], budget, per_gb)
|
|
362
396
|
nxt = min(upper, lo * 2) if hi is None else lo + _grid((hi - lo) / 2)
|
|
363
397
|
if fit is not None and fit < nxt:
|
|
364
398
|
if _grid(fit) - lo < min(step, upper - lo):
|
|
@@ -367,6 +401,8 @@ def search(try_ctx, start, upper, limit_gb=None, step=STEP, floor=FLOOR, max_sta
|
|
|
367
401
|
f"for it ({per * 1000:.3f} GB per 1,000 tokens)")
|
|
368
402
|
break
|
|
369
403
|
nxt = _grid(fit)
|
|
404
|
+
elif per_gb and fit is not None and hi is not None and lo < _grid(fit) < hi:
|
|
405
|
+
nxt = _grid(fit) # the estimate's memory per token, from a reading it matched: no need to bisect
|
|
370
406
|
if nxt <= lo:
|
|
371
407
|
why = f"{hi:,} failed: {next(p.error for p in tried if p.ctx == hi)}" if hi else why
|
|
372
408
|
break
|
|
@@ -403,6 +439,48 @@ def room_gb(eng):
|
|
|
403
439
|
return (limit if free is None else min(limit, free - headroom)), ""
|
|
404
440
|
|
|
405
441
|
|
|
442
|
+
def _file_gb(path):
|
|
443
|
+
"""A file's size with the other shards of a split GGUF (-00001-of-00003), or 0 if it is missing."""
|
|
444
|
+
match = re.search(r"-(\d{5})-of-(\d{5})\.gguf$", path)
|
|
445
|
+
paths = glob.glob(path[:match.start()] + f"-*-of-{match.group(2)}.gguf") if match else [path]
|
|
446
|
+
return sum(os.path.getsize(p) for p in paths if os.path.isfile(p)) / machines.GB
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
def estimate(eng, m, room, kv_type=None):
|
|
450
|
+
"""(the largest context the model file says fits in `room` GB, (fixed GB, GB per token), the
|
|
451
|
+
arithmetic as text), or (None, None, why not). For servers tuieval sizes from the model file (machines.fit, on
|
|
452
|
+
llama.cpp's terms): the weights with an mmproj and drafter, buffers (ESTIMATE_BUFFERS_GB and
|
|
453
|
+
ESTIMATE_BUFFERS_SHARE of the weights) and sliding windows' fixed cache, then the KV cache per token
|
|
454
|
+
(machines.kv_cache_split). Errs a little large on the buffers, so a first try at the estimate
|
|
455
|
+
usually passes and its memory reading corrects the rest."""
|
|
456
|
+
server = eng.cfg["servers"][m["server"]]
|
|
457
|
+
path = engine_mod.expand(str(m.get("model", "")))
|
|
458
|
+
if room is None:
|
|
459
|
+
return None, None, "the memory this machine has free can't be read"
|
|
460
|
+
if not (server.get("model_is_path") and os.path.isfile(path) and path.endswith(".gguf")):
|
|
461
|
+
return None, None, "the model isn't a GGUF file"
|
|
462
|
+
if not engine_mod.fit_check(server):
|
|
463
|
+
return None, None, "its server sizes its own memory"
|
|
464
|
+
try:
|
|
465
|
+
info = machines.read_gguf(path)
|
|
466
|
+
except (OSError, ValueError) as e:
|
|
467
|
+
return None, None, f"couldn't read the GGUF header ({e})"
|
|
468
|
+
split = machines.kv_cache_split(info, kv_type or m.get("kv_type") or server.get("kv_type") or "f16")
|
|
469
|
+
if not split or not split[0]:
|
|
470
|
+
return None, None, "the model file doesn't describe its KV cache well enough (MLA, or sliding windows without a layer pattern)"
|
|
471
|
+
weights = _file_gb(path) + sum(_file_gb(engine_mod.expand(m[k])) for k in ("mmproj", "draft") if m.get(k))
|
|
472
|
+
whole = eng.machine().gpu_limit_gb if eng.machine().discrete else eng.machine().ram_gb
|
|
473
|
+
if weights > whole:
|
|
474
|
+
return None, None, "the model is larger than this machine's memory: its server reads it from disk as needed"
|
|
475
|
+
fixed = weights * (1 + ESTIMATE_BUFFERS_SHARE) + ESTIMATE_BUFFERS_GB + split[1] / machines.GB
|
|
476
|
+
per = split[0] / machines.GB
|
|
477
|
+
ctx = int((room - fixed) / per)
|
|
478
|
+
how = (f"{weights:.1f} GB of weights, ~{fixed - weights:.1f} GB of buffers"
|
|
479
|
+
+ (" and sliding windows" if split[1] else "") + f", {per * 1000:.3f} GB per 1,000 tokens of context: "
|
|
480
|
+
f"about {max(ctx, 0):,} fit in {room:.1f} GB")
|
|
481
|
+
return ctx, (fixed, per), how
|
|
482
|
+
|
|
483
|
+
|
|
406
484
|
def upper_bound(m, asked=None):
|
|
407
485
|
"""(the largest context worth trying, where that number comes from): the model's own limit.
|
|
408
486
|
What models.toml caps the context at (max_ctx, ctx, a context flag) isn't one: the measurement
|
|
@@ -456,12 +534,24 @@ def bench(eng, label, emit=lambda *a, **k: None, max_ctx=None, start=None, step=
|
|
|
456
534
|
if size is not None and size > whole:
|
|
457
535
|
emit("tune_step", message=f"the model is {size:.0f} GB on disk, more than this machine's memory: its server "
|
|
458
536
|
"reads it from disk as needed, so its size isn't checked against free memory")
|
|
459
|
-
# Half of what it runs with now, so the second probe is a context expected to work and the two
|
|
460
|
-
# give the memory per token before anything larger is tried.
|
|
461
|
-
usual = sv.ctx if sv.fits and sv.ctx else None
|
|
462
|
-
first = min(upper, max(FLOOR, _grid(start or (usual // 2 if usual else FIRST))))
|
|
463
537
|
emit("tune_step", message=f"largest context up to {upper:,} ({source})"
|
|
464
538
|
+ (f"; {room:.1f} GB of memory to work with" if room is not None else ""))
|
|
539
|
+
# Start where the model file says the limit is, and check it there. Without an estimate: half of
|
|
540
|
+
# what it runs with now, so the second probe is a context expected to work and the two give the
|
|
541
|
+
# memory per token before anything larger is tried.
|
|
542
|
+
est, est_mem, how_est = estimate(eng, m, room, sv.kv_type)
|
|
543
|
+
if start:
|
|
544
|
+
first, began = _grid(start), "--start"
|
|
545
|
+
elif est is not None:
|
|
546
|
+
first, began = _grid(est), "estimate"
|
|
547
|
+
emit("tune_step", message=f"estimate: {how_est}; "
|
|
548
|
+
+ ("the model's own limit fits, so that is the first try" if first >= upper else
|
|
549
|
+
"the first try is there" if first >= FLOOR else f"the first try is {FLOOR:,}"))
|
|
550
|
+
else:
|
|
551
|
+
usual = sv.ctx if sv.fits and sv.ctx else None
|
|
552
|
+
first, began = _grid(usual // 2 if usual else FIRST), "half the usual context"
|
|
553
|
+
emit("tune_step", message=f"no estimate ({how_est}): starting at {min(upper, max(FLOOR, first)):,} and doubling")
|
|
554
|
+
first = min(upper, max(FLOOR, first))
|
|
465
555
|
|
|
466
556
|
baseline = None if sv.machine.discrete else machines.available_memory_gb()
|
|
467
557
|
|
|
@@ -471,9 +561,10 @@ def bench(eng, label, emit=lambda *a, **k: None, max_ctx=None, start=None, step=
|
|
|
471
561
|
eng._check()
|
|
472
562
|
settle(eng, baseline, emit)
|
|
473
563
|
r = probe(eng, m, ctx, emit, limit_s, rule["level"])
|
|
474
|
-
if r.stopped_for == "pressure" and not rule["passed"] and rule["level"] < PRESSURE_CRITICAL:
|
|
564
|
+
if r.stopped_for == "pressure" and not rule["passed"] and rule["level"] < PRESSURE_CRITICAL and ctx <= FIRST:
|
|
475
565
|
# Before anything has passed, at the smallest contexts: this isn't the context being too
|
|
476
566
|
# large. The server fills memory to a budget of its own and runs at the warning level.
|
|
567
|
+
# (A first try at a large estimate that reaches it is treated as too large, and halved.)
|
|
477
568
|
rule["level"] = PRESSURE_CRITICAL
|
|
478
569
|
emit("tune_result", message=" " + r.summary())
|
|
479
570
|
emit("tune_step", message=f" memory pressure reaches the warning level at {ctx:,} already, with nothing "
|
|
@@ -484,7 +575,8 @@ def bench(eng, label, emit=lambda *a, **k: None, max_ctx=None, start=None, step=
|
|
|
484
575
|
rule["passed"] = rule["passed"] or r.ok
|
|
485
576
|
return r
|
|
486
577
|
|
|
487
|
-
tried, why = search(try_ctx, first, upper, room, step, min(FLOOR, first), max_starts, emit
|
|
578
|
+
tried, why = search(try_ctx, first, upper, room, step, min(FLOOR, first), max_starts, emit,
|
|
579
|
+
est_mem if began == "estimate" else None)
|
|
488
580
|
passed = [p for p in tried if p.ok]
|
|
489
581
|
if not passed:
|
|
490
582
|
raise engine_mod.ModelFailed(f"no context worked ({why}); the last try: {tried[-1].error}")
|
|
@@ -501,6 +593,7 @@ def bench(eng, label, emit=lambda *a, **k: None, max_ctx=None, start=None, step=
|
|
|
501
593
|
"meta": {"date": profiles.now(), "machine": sv.machine.summary, "server_version": eng.server_version(m),
|
|
502
594
|
"model_file": os.path.basename(str(m.get("model", ""))), "model_bytes": sv.identity.get("model_bytes"),
|
|
503
595
|
"kv_type": sv.kv_type, "upper_bound": upper, "upper_bound_from": source,
|
|
596
|
+
"started_at": first, "started_from": began, "estimated_ctx": est,
|
|
504
597
|
"fill_confirmed": best.filled, "server_starts": len(tried),
|
|
505
598
|
"stops_at_pressure": "critical" if rule["level"] >= PRESSURE_CRITICAL else "warning",
|
|
506
599
|
"pressure_seen": max((p.pressure or 0 for p in passed), default=0) or None},
|
|
@@ -307,12 +307,25 @@ def read_gguf(path):
|
|
|
307
307
|
per_layer = [0 if r else h for h, r in zip(per_layer, recurrent)]
|
|
308
308
|
elif interval > 1:
|
|
309
309
|
per_layer = [h if (i + 1) % interval == 0 else 0 for i, h in enumerate(per_layer)]
|
|
310
|
+
# Which layers use the sliding window: a flag per layer, or (llama.cpp's other spelling) a
|
|
311
|
+
# number n, where the last layer of every n is full attention. None when the file doesn't say.
|
|
312
|
+
pattern = get("attention.sliding_window_pattern")
|
|
313
|
+
if isinstance(pattern, list) and len(pattern) == len(per_layer):
|
|
314
|
+
swa_layers = [bool(x) for x in pattern]
|
|
315
|
+
elif isinstance(pattern, int) and not isinstance(pattern, bool) and pattern > 1:
|
|
316
|
+
swa_layers = [i % pattern < pattern - 1 for i in range(len(per_layer))]
|
|
317
|
+
else:
|
|
318
|
+
swa_layers = None
|
|
310
319
|
return {
|
|
311
320
|
"path": path, "bytes": os.path.getsize(path), "architecture": arch, "name": kv.get("general.name", ""),
|
|
312
321
|
"layers": layers, "context_length": int(get("context_length", 0) or 0), "embedding": embd,
|
|
313
322
|
"kv_heads_per_layer": per_layer, "head_dim_k": head_dim_k, "head_dim_v": head_dim_v,
|
|
314
323
|
"experts": int(get("expert_count", 0) or 0), "experts_used": int(get("expert_used_count", 0) or 0),
|
|
315
324
|
"sliding_window": int(get("attention.sliding_window", 0) or 0),
|
|
325
|
+
"swa_layers": swa_layers,
|
|
326
|
+
"head_dim_k_swa": int(get("attention.key_length_swa", 0) or head_dim_k),
|
|
327
|
+
"head_dim_v_swa": int(get("attention.value_length_swa", 0) or head_dim_v),
|
|
328
|
+
"kv_lora_rank": int(get("attention.kv_lora_rank", 0) or 0), # MLA: a compressed cache of its own shape
|
|
316
329
|
"mtp_layers": int(get("nextn_predict_layers", 0) or 0), # built-in draft layers (draft-mtp)
|
|
317
330
|
}
|
|
318
331
|
|
|
@@ -325,6 +338,28 @@ def kv_bytes_per_token(info, kv_type="f16"):
|
|
|
325
338
|
return sum(h * (info["head_dim_k"] + info["head_dim_v"]) * per for h in info["kv_heads_per_layer"])
|
|
326
339
|
|
|
327
340
|
|
|
341
|
+
def kv_cache_split(info, kv_type="f16", ubatch=512):
|
|
342
|
+
"""(bytes per token of context, fixed bytes) of llama.cpp's KV cache, counting sliding windows as
|
|
343
|
+
llama.cpp keeps them: a sliding-window layer holds its window (plus a batch) whatever the context,
|
|
344
|
+
so only full-attention layers grow with it. Checked on Gemma 4 31B: 0.076 GB per 1,000 tokens
|
|
345
|
+
against 0.078 measured, where kv_bytes_per_token says 1.6. None when the layout isn't known well
|
|
346
|
+
enough to say: a sliding window with no per-layer pattern, or MLA's compressed cache."""
|
|
347
|
+
if info.get("kv_lora_rank"):
|
|
348
|
+
return None
|
|
349
|
+
per = KV_BYTES.get(kv_type, 2.0)
|
|
350
|
+
heads = info["kv_heads_per_layer"]
|
|
351
|
+
full = (info["head_dim_k"] + info["head_dim_v"]) * per
|
|
352
|
+
if not info.get("sliding_window"):
|
|
353
|
+
return sum(h * full for h in heads), 0.0
|
|
354
|
+
swa = info.get("swa_layers")
|
|
355
|
+
if not swa or len(swa) != len(heads):
|
|
356
|
+
return None
|
|
357
|
+
windowed = (info.get("head_dim_k_swa", info["head_dim_k"]) + info.get("head_dim_v_swa", info["head_dim_v"])) * per
|
|
358
|
+
grows = sum(h * full for h, s in zip(heads, swa) if not s)
|
|
359
|
+
fixed = sum(h * windowed for h, s in zip(heads, swa) if s) * (info["sliding_window"] + ubatch)
|
|
360
|
+
return grows, fixed
|
|
361
|
+
|
|
362
|
+
|
|
328
363
|
# ---------------------------------------------------------------- fit
|
|
329
364
|
@dataclasses.dataclass
|
|
330
365
|
class Fit:
|
|
@@ -707,7 +707,8 @@ def cmd_tune(argv):
|
|
|
707
707
|
p.add_argument("--max", type=int, default=None, metavar="N",
|
|
708
708
|
help="with --ctx: the largest context to try (default: the model's own limit)")
|
|
709
709
|
p.add_argument("--start", type=int, default=None, metavar="N",
|
|
710
|
-
help="with --ctx: the first context to try (default:
|
|
710
|
+
help="with --ctx: the first context to try (default: the largest the model file says fits, "
|
|
711
|
+
"where tuieval can work that out; else half of what the model runs with now)")
|
|
711
712
|
p.add_argument("--step", type=int, default=None, metavar="N",
|
|
712
713
|
help="with --ctx: how close to the true maximum to get (default 8192)")
|
|
713
714
|
p.add_argument("--models", default=None, help="default: the workspace's models.toml")
|
|
@@ -2873,16 +2873,21 @@ class PackMaxTokens(unittest.TestCase):
|
|
|
2873
2873
|
def fake_gguf(path, embedding=5120, size=0, kv_heads=4, extra=()):
|
|
2874
2874
|
"""A GGUF header with just the keys machines.read_gguf reads, padded to size bytes. kv_heads: a
|
|
2875
2875
|
number, or one per layer (a list, as some GGUFs store it). extra: more (key, type, value) pairs
|
|
2876
|
-
(type 8 a string, 7 a bool, 4 a uint32).
|
|
2876
|
+
(type 8 a string, 7 a bool, 4 a uint32, "bools" an array of bools). A key in extra replaces the
|
|
2877
|
+
default one of that name."""
|
|
2877
2878
|
import struct
|
|
2878
2879
|
s = lambda t: struct.pack("<Q", len(t)) + t.encode() # noqa: E731
|
|
2879
2880
|
kv = [("general.architecture", 8, "qwen35"), ("qwen35.block_count", 4, 64),
|
|
2880
2881
|
("qwen35.embedding_length", 4, embedding), ("qwen35.attention.head_count", 4, 24),
|
|
2881
2882
|
("qwen35.attention.head_count_kv", 9 if isinstance(kv_heads, list) else 4, kv_heads),
|
|
2882
2883
|
("qwen35.attention.key_length", 4, 256),
|
|
2883
|
-
("qwen35.full_attention_interval", 4, 4), ("qwen35.nextn_predict_layers", 4, 1)
|
|
2884
|
+
("qwen35.full_attention_interval", 4, 4), ("qwen35.nextn_predict_layers", 4, 1)]
|
|
2885
|
+
kv = [k for k in kv if k[0] not in {e[0] for e in extra}] + list(extra)
|
|
2884
2886
|
out = b"GGUF" + struct.pack("<IQQ", 3, 0, len(kv))
|
|
2885
2887
|
for key, t, v in kv:
|
|
2888
|
+
if t == "bools":
|
|
2889
|
+
out += s(key) + struct.pack("<IIQ", 9, 7, len(v)) + b"".join(struct.pack("<?", x) for x in v)
|
|
2890
|
+
continue
|
|
2886
2891
|
out += s(key) + struct.pack("<I", t)
|
|
2887
2892
|
if t == 8:
|
|
2888
2893
|
out += s(v)
|
|
@@ -4415,6 +4420,105 @@ max_context = 8192
|
|
|
4415
4420
|
self.assertFalse(r.ok)
|
|
4416
4421
|
self.assertIn("swapped out 1024 MB", r.error)
|
|
4417
4422
|
|
|
4423
|
+
def test_kv_cache_grows_only_in_full_attention_layers(self):
|
|
4424
|
+
from tuieval import machines
|
|
4425
|
+
# Gemma 4 31B's shape: 60 layers, every sixth full attention (4 KV heads of 512), the rest
|
|
4426
|
+
# sliding windows of 1024 (16 KV heads of 256)
|
|
4427
|
+
swa = [(i + 1) % 6 != 0 for i in range(60)]
|
|
4428
|
+
info = {"kv_heads_per_layer": [16 if s else 4 for s in swa], "head_dim_k": 512, "head_dim_v": 512,
|
|
4429
|
+
"head_dim_k_swa": 256, "head_dim_v_swa": 256, "sliding_window": 1024, "swa_layers": swa,
|
|
4430
|
+
"kv_lora_rank": 0}
|
|
4431
|
+
grows, fixed = machines.kv_cache_split(info)
|
|
4432
|
+
self.assertEqual(grows, 10 * 4 * 1024 * 2) # 0.076 GB per 1,000 tokens; 0.078 measured
|
|
4433
|
+
self.assertEqual(fixed, 50 * 16 * 512 * 2 * (1024 + 512))
|
|
4434
|
+
self.assertGreater(machines.kv_bytes_per_token(info), 15 * grows) # the fit check's safe overestimate
|
|
4435
|
+
self.assertIsNone(machines.kv_cache_split(dict(info, swa_layers=None))) # a window, no pattern
|
|
4436
|
+
self.assertIsNone(machines.kv_cache_split(dict(info, kv_lora_rank=512))) # MLA
|
|
4437
|
+
plain = dict(info, sliding_window=0, swa_layers=None)
|
|
4438
|
+
self.assertEqual(machines.kv_cache_split(plain), (machines.kv_bytes_per_token(plain), 0.0))
|
|
4439
|
+
|
|
4440
|
+
def test_the_sliding_window_pattern_is_read_in_both_spellings(self):
|
|
4441
|
+
from tuieval import machines
|
|
4442
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
4443
|
+
flags = [(i + 1) % 4 != 0 for i in range(64)]
|
|
4444
|
+
fake_gguf(f"{tmp}/listed.gguf", extra=[("qwen35.attention.sliding_window", 4, 1024),
|
|
4445
|
+
("qwen35.attention.sliding_window_pattern", "bools", flags),
|
|
4446
|
+
("qwen35.attention.key_length_swa", 4, 128)])
|
|
4447
|
+
info = machines.read_gguf(f"{tmp}/listed.gguf")
|
|
4448
|
+
self.assertEqual((info["swa_layers"], info["head_dim_k_swa"], info["head_dim_v_swa"]), (flags, 128, 256))
|
|
4449
|
+
fake_gguf(f"{tmp}/every.gguf", extra=[("qwen35.attention.sliding_window", 4, 1024),
|
|
4450
|
+
("qwen35.attention.sliding_window_pattern", 4, 4)])
|
|
4451
|
+
self.assertEqual(machines.read_gguf(f"{tmp}/every.gguf")["swa_layers"], flags)
|
|
4452
|
+
fake_gguf(f"{tmp}/none.gguf")
|
|
4453
|
+
self.assertIsNone(machines.read_gguf(f"{tmp}/none.gguf")["swa_layers"])
|
|
4454
|
+
|
|
4455
|
+
def test_search_from_an_estimate_settles_in_one_or_two_tries(self):
|
|
4456
|
+
# truth: 38.7 GB + 0.198 GB per 1,000 tokens against 85.3 GB, so 234,848 fit
|
|
4457
|
+
truth = lambda base: (lambda c: base + 0.000198 * c) # noqa: E731
|
|
4458
|
+
best, tried, why = self._search(234848, gb=truth(38.7), start=234496, upper=524288, limit_gb=85.3,
|
|
4459
|
+
estimated=(38.7, 0.000198))
|
|
4460
|
+
self.assertEqual((best, tried), (234496, [234496])) # the estimate was right: one try
|
|
4461
|
+
self.assertTrue(why.startswith("memory:"), why)
|
|
4462
|
+
# a cautious estimate: the first try's reading says more fits, and the second goes straight there
|
|
4463
|
+
best, tried, why = self._search(250880, gb=truth(35.5), start=234496, upper=524288, limit_gb=85.3,
|
|
4464
|
+
estimated=(38.7, 0.000198))
|
|
4465
|
+
self.assertEqual(tried, [234496, 250880])
|
|
4466
|
+
# an optimistic one: a little below it, then straight to what that reading predicts
|
|
4467
|
+
works = int((85.3 - 41.0) / 0.000198)
|
|
4468
|
+
best, tried, why = self._search(works, gb=truth(41.0), start=234496, upper=524288, limit_gb=85.3,
|
|
4469
|
+
estimated=(38.7, 0.000198))
|
|
4470
|
+
self.assertEqual(tried, [234496, 198656, 223232])
|
|
4471
|
+
self.assertEqual(best, 223232)
|
|
4472
|
+
# the model's own limit fits: one try
|
|
4473
|
+
best, tried, why = self._search(10**9, gb=truth(38.7), start=262144, upper=262144, limit_gb=85.3,
|
|
4474
|
+
estimated=(38.7, 0.000198))
|
|
4475
|
+
self.assertEqual((tried, why), ([262144], "reached the upper bound (262,144)"))
|
|
4476
|
+
|
|
4477
|
+
def test_an_estimate_the_readings_dont_match_is_dropped(self):
|
|
4478
|
+
said = []
|
|
4479
|
+
# the file says 0.015 GB per 1,000 tokens; this server takes 0.23 (a looped model)
|
|
4480
|
+
best, tried, why = self._search(276000, gb=lambda c: 21.8 + 0.00023 * c, start=1048576, upper=1048576,
|
|
4481
|
+
limit_gb=85.3, estimated=(26.2, 0.0000153), max_starts=12,
|
|
4482
|
+
emit=lambda kind, **d: said.append(d.get("message", "")))
|
|
4483
|
+
self.assertEqual(tried[:4], [1048576, 890880, 445440, 222208])
|
|
4484
|
+
self.assertEqual(sum("the model file doesn't describe this server's memory" in s for s in said), 1)
|
|
4485
|
+
self.assertGreaterEqual(best, 270336)
|
|
4486
|
+
|
|
4487
|
+
def test_bench_starts_at_the_estimate(self):
|
|
4488
|
+
from tuieval import ctxbench
|
|
4489
|
+
self.addCleanup(setattr, ctxbench, "room_gb", ctxbench.room_gb)
|
|
4490
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
4491
|
+
gguf = os.path.join(tmp, "m.gguf")
|
|
4492
|
+
fake_gguf(gguf, size=1000) # 16 full-attention layers of 4 KV heads of 256: 64 KiB per token
|
|
4493
|
+
mock = json.dumps([sys.executable, os.path.join(HERE, "mock_server.py"), "--port", "{port}", "--packs",
|
|
4494
|
+
os.path.join(tmp, "ws", "packs"), "--mode", "fixed", "--model", "{served_name}"])[1:-1]
|
|
4495
|
+
ws = self._workspace(tmp, f"""
|
|
4496
|
+
[servers.files]
|
|
4497
|
+
cmd = [{mock}, "--context", "{{ctx}}", "--breaks-above", "20000"]
|
|
4498
|
+
port = {free_port()}
|
|
4499
|
+
model_is_path = true
|
|
4500
|
+
|
|
4501
|
+
[[models]]
|
|
4502
|
+
label = "file"
|
|
4503
|
+
server = "files"
|
|
4504
|
+
model = "{gguf}"
|
|
4505
|
+
""")
|
|
4506
|
+
e = self._engine(ws)
|
|
4507
|
+
ctxbench.room_gb = lambda eng: (2.13, "") # 1 GB of buffers, then room for 18,432 tokens
|
|
4508
|
+
said = []
|
|
4509
|
+
got = ctxbench.bench(e, "file", lambda kind, **d: said.append(d.get("message", "")), max_ctx=65536, step=2048)
|
|
4510
|
+
self.assertEqual(list(got["probes"])[0], "18432")
|
|
4511
|
+
self.assertEqual((got["meta"]["started_from"], got["meta"]["estimated_ctx"]), ("estimate", 18513))
|
|
4512
|
+
self.assertTrue(any(s.startswith("estimate: ") and "about 18,513 fit in 2.1 GB" in s for s in said), said)
|
|
4513
|
+
self.assertEqual(got["max_ctx"], 18432)
|
|
4514
|
+
# --start still decides where it starts
|
|
4515
|
+
got = ctxbench.bench(e, "file", max_ctx=65536, start=16384, step=2048)
|
|
4516
|
+
self.assertEqual((list(got["probes"])[0], got["meta"]["started_from"]), ("16384", "--start"))
|
|
4517
|
+
# a server that isn't sized from the model file keeps the old start
|
|
4518
|
+
got = ctxbench.bench(e, "sized", lambda kind, **d: said.append(d.get("message", "")), max_ctx=65536, step=2048)
|
|
4519
|
+
self.assertEqual(got["meta"]["started_from"], "half the usual context")
|
|
4520
|
+
self.assertTrue(any(s.startswith("no estimate (the model isn't a GGUF file)") for s in said))
|
|
4521
|
+
|
|
4418
4522
|
def test_tune_ctx_command(self):
|
|
4419
4523
|
with tempfile.TemporaryDirectory() as tmp:
|
|
4420
4524
|
ws = self._workspace(tmp)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/tool_call/pack.toml
RENAMED
|
File without changes
|
{tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/tool_call/system.txt
RENAMED
|
File without changes
|
{tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/tool_call/tests.yaml
RENAMED
|
File without changes
|
{tuieval-0.2.0.dev162 → tuieval-0.2.0.dev164}/src/tuieval/templates/packs/tool_call/tools.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|