tuieval 0.2.0.dev156__tar.gz → 0.2.0.dev160__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.dev156 → tuieval-0.2.0.dev160}/CHANGELOG.md +2 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/PKG-INFO +1 -1
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/models.md +2 -2
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/_version.py +2 -2
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/ctxbench.py +52 -14
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/run_evals.py +3 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/tests/test_tuieval.py +46 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/.gitignore +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/LICENSE +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/README.md +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/RELEASING.md +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/agent-packs.md +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/brand/README.md +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/brand/favicon.ico +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/brand/readme-header.png +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/brand/social-preview.png +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/brand/tuieval-icon-1024.png +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/brand/tuieval-icon-128.png +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/brand/tuieval-icon-16.png +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/brand/tuieval-icon-16.svg +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/brand/tuieval-icon-256.png +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/brand/tuieval-icon-32.png +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/brand/tuieval-icon-48.png +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/brand/tuieval-icon-512.png +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/brand/tuieval-icon-64.png +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/brand/tuieval-icon-animated.svg +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/brand/tuieval-icon.svg +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/tui-answer-reasoning.png +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/tui-run-reasoning.png +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/images/tui-setup.png +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/docs/writing-packs.md +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/pyproject.toml +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/__init__.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/__main__.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/agents.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/builtin.toml +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/cli.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/client.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/compare.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/dates.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/doctor.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/engine.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/export.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/graders/__init__.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/graders/answer.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/graders/code.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/graders/rag.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/graders/reply.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/graders/tool_call.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/insights.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/logs.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/machines.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/onboard.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/packs.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/profiles.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/pta.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/remove.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/scaffold.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/selftest.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/models.toml +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/answer/pack.toml +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/answer/system.txt +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/answer/tests.yaml +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/code/pack.toml +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/code/system.txt +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/code/tests.yaml +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/rag/pack.toml +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/rag/system.txt +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/rag/tests.yaml +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/reply/pack.toml +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/reply/system.txt +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/reply/tests.yaml +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/tool_call/pack.toml +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/tool_call/system.txt +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/tool_call/tests.yaml +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/tool_call/tools.yaml +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/tui.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/tune.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/verdict.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/watch_proxy.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/workspace.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/yamlout.py +0 -0
- {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/tests/mock_server.py +0 -0
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- 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.
|
|
6
|
+
- 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.
|
|
5
7
|
- Fix: `tuieval tune --ctx` refused models larger than the machine's memory ("another model or app is holding memory"), which servers that read the model from disk as needed run fine. Their size on disk is no longer checked against free memory.
|
|
6
8
|
- Fix: `tuieval tune --ctx` waits for the machine to recover after each try (memory pressure back to normal, memory given back). A try stopped for memory pressure could fail the next one within seconds, at a context that works.
|
|
7
9
|
- `tuieval tune --ctx`: the measured context governs the caps in `models.toml` (`max_ctx`, a model's `ctx`, a context flag), not the other way around: the search runs up to the model's own limit, and runs use what was measured even above a cap. It starts at half the model's current context, and a try is also stopped while the server loads. Memory is measured as what the machine loses while the server runs (on a Mac from `vm_stat` page counts, not the rounded free percentage), so memory-mapped files a server reads on demand no longer count against it.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: tuieval
|
|
3
|
-
Version: 0.2.0.
|
|
3
|
+
Version: 0.2.0.dev160
|
|
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
|
|
@@ -153,8 +153,8 @@ The knobs are `[servers.<name>.tune]` in `models.toml`: each knob is a list of o
|
|
|
153
153
|
The fit check estimates the context from the model file, and only for servers that use memory the way llama.cpp does. `tuieval tune <model> --ctx` measures it instead, the same way for any server tuieval starts:
|
|
154
154
|
|
|
155
155
|
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.
|
|
156
|
-
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.
|
|
157
|
-
3. 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.
|
|
156
|
+
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.
|
|
157
|
+
3. 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.
|
|
158
158
|
|
|
159
159
|
Expect 3 to 5 server starts; the largest ones 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).
|
|
160
160
|
|
|
@@ -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.dev160'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 2, 0, 'dev160')
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -20,9 +20,13 @@ 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
|
|
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
|
-
or memory runs out.
|
|
27
|
+
or memory runs out. (A server that reaches the warning level at the smallest context, with nothing
|
|
28
|
+
swapped, fills memory to a budget of its own: for it only critical pressure counts, besides
|
|
29
|
+
swapping and memory running out.) The next probe waits until the machine has recovered (pressure back to normal,
|
|
26
30
|
the memory given back), so one probe's pressure can't fail the next. Typically 3 to 5 server starts.
|
|
27
31
|
|
|
28
32
|
Memory is read off the machine, not the server's processes: available memory before the server
|
|
@@ -52,6 +56,7 @@ APART = 0.8 # memory per token is read off two probes at least th
|
|
|
52
56
|
MAX_STARTS = 8
|
|
53
57
|
REQUEST_LIMIT_S = 3600 # reading a few hundred thousand tokens takes a while ([tune] ctx_request_timeout_s)
|
|
54
58
|
PRESSURE_WARNING = 2 # macOS memory pressure level that stops a probe (1 is normal)
|
|
59
|
+
PRESSURE_CRITICAL = 4 # the level that stops one for a server whose normal state is the warning level
|
|
55
60
|
SWAP_STOP_MB = 512 # swapped out while a probe ran: stop it
|
|
56
61
|
AVAILABLE_STOP_GB = 1.0 # memory available under this stops a probe
|
|
57
62
|
SETTLE_S = 120 # how long the machine may take to recover after a probe before the next one
|
|
@@ -79,6 +84,8 @@ class Probe:
|
|
|
79
84
|
total_s: float | None = None
|
|
80
85
|
load_s: float | None = None
|
|
81
86
|
filled: bool = False # the server's token count confirms the context was full
|
|
87
|
+
pressure: int | None = None # highest macOS memory pressure level while it ran
|
|
88
|
+
stopped_for: str = "" # "pressure" when memory pressure alone stopped it (nothing was swapped)
|
|
82
89
|
|
|
83
90
|
def summary(self):
|
|
84
91
|
if not self.ok:
|
|
@@ -139,8 +146,9 @@ class Guard:
|
|
|
139
146
|
"""Watches the machine while a probe's server loads and works. When it gets unhealthy, the
|
|
140
147
|
server is stopped: a load is abandoned and a request is cut off."""
|
|
141
148
|
|
|
142
|
-
def __init__(self, eng, every_s=2.0):
|
|
143
|
-
self.eng, self.every_s, self.reason = eng, every_s, ""
|
|
149
|
+
def __init__(self, eng, every_s=2.0, stop_level=PRESSURE_WARNING):
|
|
150
|
+
self.eng, self.every_s, self.reason, self.stop_level = eng, every_s, "", stop_level
|
|
151
|
+
self.pressure_only = False # stopped for memory pressure, with nothing swapped out
|
|
144
152
|
self.pressure, self._stop = machines.memory_pressure_level(), threading.Event()
|
|
145
153
|
self._swap0 = machines.swapped_out_bytes()
|
|
146
154
|
self._own_memory = eng.machine().discrete # VRAM: the machine's memory isn't what runs out
|
|
@@ -155,7 +163,9 @@ class Guard:
|
|
|
155
163
|
lvl = machines.memory_pressure_level()
|
|
156
164
|
if lvl is not None:
|
|
157
165
|
self.pressure = max(self.pressure or 0, lvl)
|
|
158
|
-
if lvl >=
|
|
166
|
+
if lvl >= self.stop_level:
|
|
167
|
+
swap = machines.swapped_out_bytes()
|
|
168
|
+
self.pressure_only = None in (swap, self._swap0) or swap - self._swap0 < 2**20
|
|
159
169
|
return f"macOS memory pressure rose to level {lvl}"
|
|
160
170
|
swap = machines.swapped_out_bytes()
|
|
161
171
|
if None not in (swap, self._swap0) and (swap - self._swap0) / 2**20 > SWAP_STOP_MB:
|
|
@@ -191,8 +201,9 @@ class Guard:
|
|
|
191
201
|
self.eng._stall = None
|
|
192
202
|
|
|
193
203
|
|
|
194
|
-
def probe(eng, m, ctx, emit=lambda *a, **k: None, limit=REQUEST_LIMIT_S):
|
|
195
|
-
"""Serve the model with this context, fill it and ask for the fact. Returns a Probe.
|
|
204
|
+
def probe(eng, m, ctx, emit=lambda *a, **k: None, limit=REQUEST_LIMIT_S, stop_level=PRESSURE_WARNING):
|
|
205
|
+
"""Serve the model with this context, fill it and ask for the fact. Returns a Probe.
|
|
206
|
+
stop_level: the macOS memory pressure level that stops it."""
|
|
196
207
|
from . import client
|
|
197
208
|
out = Probe(ctx)
|
|
198
209
|
reserve = ANSWER_TOKENS + max(256, ctx // 50)
|
|
@@ -200,7 +211,7 @@ def probe(eng, m, ctx, emit=lambda *a, **k: None, limit=REQUEST_LIMIT_S):
|
|
|
200
211
|
if target < 1024:
|
|
201
212
|
out.error = f"a context of {ctx:,} is too small to test"
|
|
202
213
|
return out
|
|
203
|
-
guard = Guard(eng)
|
|
214
|
+
guard = Guard(eng, stop_level=stop_level)
|
|
204
215
|
try:
|
|
205
216
|
with guard, eng.serve(m, log_name=f"{m['label']}.ctx", ctx=ctx) as (url, info):
|
|
206
217
|
out.load_s = round(info["load_s"], 1) if info.get("load_s") else None
|
|
@@ -215,8 +226,8 @@ def probe(eng, m, ctx, emit=lambda *a, **k: None, limit=REQUEST_LIMIT_S):
|
|
|
215
226
|
met = client.metrics(res) if not res.get("error") else {}
|
|
216
227
|
out.prompt_tokens, out.pp_tps, out.tg_tps = met.get("prompt_tokens"), met.get("prompt_tps"), met.get("gen_tps")
|
|
217
228
|
out.total_s = round(res["total_s"], 1) if res.get("total_s") else None
|
|
218
|
-
guard.check()
|
|
219
|
-
out.mem_gb = memory_gb(eng, m, info, guard)
|
|
229
|
+
guard.reason = guard.reason or guard.check() # with the server still up: a short probe may end
|
|
230
|
+
out.mem_gb = memory_gb(eng, m, info, guard) # between the guard's own readings
|
|
220
231
|
text = (res.get("answer") or "") + (res.get("reasoning") or "")
|
|
221
232
|
if res.get("error"):
|
|
222
233
|
out.error = res["error"]
|
|
@@ -234,8 +245,10 @@ def probe(eng, m, ctx, emit=lambda *a, **k: None, limit=REQUEST_LIMIT_S):
|
|
|
234
245
|
out.error = str(e).splitlines()[0]
|
|
235
246
|
if not guard.reason and any(w in out.error for w in NOT_ABOUT_CONTEXT):
|
|
236
247
|
raise # a smaller context wouldn't help
|
|
248
|
+
out.pressure = guard.pressure
|
|
237
249
|
if guard.reason: # the machine got unhealthy: that is why, whatever the server said as it was stopped
|
|
238
250
|
out.ok, out.error = False, guard.reason
|
|
251
|
+
out.stopped_for = "pressure" if guard.pressure_only else ""
|
|
239
252
|
return out
|
|
240
253
|
|
|
241
254
|
|
|
@@ -310,6 +323,7 @@ def search(try_ctx, start, upper, limit_gb=None, step=STEP, floor=FLOOR, max_sta
|
|
|
310
323
|
Returns (probes in the order tried, why it stopped)."""
|
|
311
324
|
tried, lo, hi, c = [], None, None, min(start, upper)
|
|
312
325
|
why = f"{max_starts} server starts used"
|
|
326
|
+
budget = limit_gb # None once the tries show it doesn't describe this server
|
|
313
327
|
while len(tried) < max_starts:
|
|
314
328
|
emit("tune_step", message=f"[{len(tried) + 1}] context {c:,}", start=len(tried) + 1, max_starts=max_starts)
|
|
315
329
|
try:
|
|
@@ -336,12 +350,20 @@ def search(try_ctx, start, upper, limit_gb=None, step=STEP, floor=FLOOR, max_sta
|
|
|
336
350
|
if hi is not None and hi - lo <= step:
|
|
337
351
|
why = f"{hi:,} failed: {next(p.error for p in tried if p.ctx == hi)}"
|
|
338
352
|
break
|
|
339
|
-
|
|
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)
|
|
340
362
|
nxt = min(upper, lo * 2) if hi is None else lo + _grid((hi - lo) / 2)
|
|
341
363
|
if fit is not None and fit < nxt:
|
|
342
364
|
if _grid(fit) - lo < min(step, upper - lo):
|
|
343
365
|
at = min(upper, lo + step)
|
|
344
|
-
why = (f"memory: {at:,} is predicted to need more than the {
|
|
366
|
+
why = (f"memory: {at:,} is predicted to need more than the {budget:.1f} GB this machine has "
|
|
345
367
|
f"for it ({per * 1000:.3f} GB per 1,000 tokens)")
|
|
346
368
|
break
|
|
347
369
|
nxt = _grid(fit)
|
|
@@ -443,10 +465,24 @@ def bench(eng, label, emit=lambda *a, **k: None, max_ctx=None, start=None, step=
|
|
|
443
465
|
|
|
444
466
|
baseline = None if sv.machine.discrete else machines.available_memory_gb()
|
|
445
467
|
|
|
468
|
+
rule = {"level": PRESSURE_WARNING, "passed": False}
|
|
469
|
+
|
|
446
470
|
def try_ctx(ctx):
|
|
447
471
|
eng._check()
|
|
448
472
|
settle(eng, baseline, emit)
|
|
449
|
-
|
|
473
|
+
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:
|
|
475
|
+
# Before anything has passed, at the smallest contexts: this isn't the context being too
|
|
476
|
+
# large. The server fills memory to a budget of its own and runs at the warning level.
|
|
477
|
+
rule["level"] = PRESSURE_CRITICAL
|
|
478
|
+
emit("tune_result", message=" " + r.summary())
|
|
479
|
+
emit("tune_step", message=f" memory pressure reaches the warning level at {ctx:,} already, with nothing "
|
|
480
|
+
"swapped: that is how this server runs. From here a try is stopped for swapping, "
|
|
481
|
+
"memory running out or critical pressure only; trying this context again")
|
|
482
|
+
settle(eng, baseline, emit)
|
|
483
|
+
r = probe(eng, m, ctx, emit, limit_s, rule["level"])
|
|
484
|
+
rule["passed"] = rule["passed"] or r.ok
|
|
485
|
+
return r
|
|
450
486
|
|
|
451
487
|
tried, why = search(try_ctx, first, upper, room, step, min(FLOOR, first), max_starts, emit)
|
|
452
488
|
passed = [p for p in tried if p.ok]
|
|
@@ -465,7 +501,9 @@ def bench(eng, label, emit=lambda *a, **k: None, max_ctx=None, start=None, step=
|
|
|
465
501
|
"meta": {"date": profiles.now(), "machine": sv.machine.summary, "server_version": eng.server_version(m),
|
|
466
502
|
"model_file": os.path.basename(str(m.get("model", ""))), "model_bytes": sv.identity.get("model_bytes"),
|
|
467
503
|
"kv_type": sv.kv_type, "upper_bound": upper, "upper_bound_from": source,
|
|
468
|
-
"fill_confirmed": best.filled, "server_starts": len(tried)
|
|
504
|
+
"fill_confirmed": best.filled, "server_starts": len(tried),
|
|
505
|
+
"stops_at_pressure": "critical" if rule["level"] >= PRESSURE_CRITICAL else "warning",
|
|
506
|
+
"pressure_seen": max((p.pressure or 0 for p in passed), default=0) or None},
|
|
469
507
|
}
|
|
470
508
|
path = profiles.save_context(sv.machine.id, label, measured, eng.tuning_dir)
|
|
471
509
|
eng._serving.clear()
|
|
@@ -650,6 +650,9 @@ def context_report(e, label, got):
|
|
|
650
650
|
per = f", {at['gb_per_1k_tokens']} GB per 1,000 tokens" if at.get("gb_per_1k_tokens") else ""
|
|
651
651
|
say(f"{label}: largest context {got['max_ctx']:,}{mem}{per}", GREEN)
|
|
652
652
|
say(f"{label}: stopped there because: {at['stopped']}")
|
|
653
|
+
if got["meta"].get("stops_at_pressure") == "critical":
|
|
654
|
+
say(f"{label}: this server runs with memory pressure at the warning level, so tries were judged by swapping, "
|
|
655
|
+
"memory running out and critical pressure", YELLOW)
|
|
653
656
|
if not got["meta"].get("fill_confirmed"):
|
|
654
657
|
say(f"{label}: the server reports no token counts, so how full the context was isn't confirmed", YELLOW)
|
|
655
658
|
if sv.ctx_source == "measured":
|
|
@@ -4044,6 +4044,21 @@ class ContextBench(unittest.TestCase):
|
|
|
4044
4044
|
ctxbench.settle(eng, 85.0, lambda kind, **d: said.append(d["message"]), limit_s=0.01)
|
|
4045
4045
|
self.assertIn("25.0 GB less memory is available", said[-1])
|
|
4046
4046
|
|
|
4047
|
+
def test_search_isnt_capped_by_memory_a_server_sizes_itself(self):
|
|
4048
|
+
said = []
|
|
4049
|
+
# about 84 GB whatever the context, against 82.9 GB set aside: over it from the smallest try on
|
|
4050
|
+
best, tried, why = self._search(300000, gb=lambda c: 84.0 + c * 4e-6, start=32768, upper=1048576,
|
|
4051
|
+
limit_gb=82.9, max_starts=12,
|
|
4052
|
+
emit=lambda kind, **d: said.append(d.get("message", "")))
|
|
4053
|
+
self.assertEqual(tried[:5], [32768, 65536, 131072, 262144, 524288])
|
|
4054
|
+
self.assertGreaterEqual(best, 262144)
|
|
4055
|
+
self.assertIn("failed", why)
|
|
4056
|
+
self.assertEqual(sum("sizes its own memory" in s for s in said), 1)
|
|
4057
|
+
# one whose memory grows with the context past the budget is still capped
|
|
4058
|
+
best, tried, why = self._search(10**9, gb=lambda c: 70 + 0.0001 * c, start=32768, upper=1048576, limit_gb=82.9)
|
|
4059
|
+
self.assertTrue(why.startswith("memory:"), why)
|
|
4060
|
+
self.assertLess(max(tried), 131072)
|
|
4061
|
+
|
|
4047
4062
|
def test_search_halves_when_the_first_try_fails(self):
|
|
4048
4063
|
best, tried, why = self._search(20000, start=65536, upper=131072)
|
|
4049
4064
|
self.assertEqual(tried[:3], [65536, 32768, 16384])
|
|
@@ -4267,6 +4282,37 @@ max_context = 8192
|
|
|
4267
4282
|
self.assertEqual(got["max_ctx"], 18432)
|
|
4268
4283
|
self.assertTrue(any("more than this machine's memory" in s for s in said))
|
|
4269
4284
|
|
|
4285
|
+
def test_a_server_that_runs_at_the_warning_level_is_judged_by_swapping(self):
|
|
4286
|
+
from tuieval import ctxbench, machines
|
|
4287
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
4288
|
+
e = self._engine(self._workspace(tmp))
|
|
4289
|
+
machines.memory_pressure_level = lambda: 2 if e._procs else 1 # warning whenever its server is up
|
|
4290
|
+
r = ctxbench.probe(e, e.model("sized"), 8192)
|
|
4291
|
+
self.assertEqual((r.ok, r.stopped_for), (False, "pressure"))
|
|
4292
|
+
said = []
|
|
4293
|
+
got = ctxbench.bench(e, "sized", lambda kind, **d: said.append(d.get("message", "")), max_ctx=65536, step=2048)
|
|
4294
|
+
self.assertEqual(got["max_ctx"], 18432)
|
|
4295
|
+
self.assertEqual((got["meta"]["stops_at_pressure"], got["meta"]["pressure_seen"]), ("critical", 2))
|
|
4296
|
+
self.assertEqual(sum("that is how this server runs" in s for s in said), 1) # decided once, on the first try
|
|
4297
|
+
# swapping still stops a try under that rule
|
|
4298
|
+
swapped = iter([0] + [2**30] * 1000)
|
|
4299
|
+
machines.swapped_out_bytes = lambda: next(swapped)
|
|
4300
|
+
r = ctxbench.probe(e, e.model("sized"), 8192, stop_level=ctxbench.PRESSURE_CRITICAL)
|
|
4301
|
+
self.assertEqual((r.ok, r.stopped_for), (False, ""))
|
|
4302
|
+
self.assertIn("swapped out 1024 MB", r.error)
|
|
4303
|
+
|
|
4304
|
+
def test_pressure_after_a_try_has_passed_is_the_edge(self):
|
|
4305
|
+
from tuieval import ctxbench, machines
|
|
4306
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
4307
|
+
e = self._engine(self._workspace(tmp))
|
|
4308
|
+
|
|
4309
|
+
def level(): # normal up to a context of 16384, warning above: the context is what does it
|
|
4310
|
+
cmd = [a for p in e._procs for a in p.args]
|
|
4311
|
+
return 2 if "--context" in cmd and int(cmd[cmd.index("--context") + 1]) > 16384 else 1
|
|
4312
|
+
machines.memory_pressure_level = level
|
|
4313
|
+
got = ctxbench.bench(e, "sized", max_ctx=65536, step=2048)
|
|
4314
|
+
self.assertEqual((got["max_ctx"], got["meta"]["stops_at_pressure"]), (16384, "warning"))
|
|
4315
|
+
|
|
4270
4316
|
def test_a_probe_stops_when_the_machine_starts_swapping(self):
|
|
4271
4317
|
from tuieval import ctxbench, machines
|
|
4272
4318
|
with tempfile.TemporaryDirectory() as 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
|
|
File without changes
|
{tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/tool_call/pack.toml
RENAMED
|
File without changes
|
{tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/tool_call/system.txt
RENAMED
|
File without changes
|
{tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/src/tuieval/templates/packs/tool_call/tests.yaml
RENAMED
|
File without changes
|
{tuieval-0.2.0.dev156 → tuieval-0.2.0.dev160}/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
|