tuieval 0.2.0.dev156__tar.gz → 0.2.0.dev158__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.
Files changed (83) hide show
  1. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/CHANGELOG.md +1 -0
  2. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/PKG-INFO +1 -1
  3. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/models.md +1 -1
  4. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/_version.py +2 -2
  5. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/ctxbench.py +38 -11
  6. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/run_evals.py +3 -0
  7. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/tests/test_tuieval.py +31 -0
  8. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/.gitignore +0 -0
  9. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/LICENSE +0 -0
  10. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/README.md +0 -0
  11. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/RELEASING.md +0 -0
  12. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/agent-packs.md +0 -0
  13. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/brand/README.md +0 -0
  14. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/brand/favicon.ico +0 -0
  15. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/brand/readme-header.png +0 -0
  16. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/brand/social-preview.png +0 -0
  17. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/brand/tuieval-icon-1024.png +0 -0
  18. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/brand/tuieval-icon-128.png +0 -0
  19. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/brand/tuieval-icon-16.png +0 -0
  20. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/brand/tuieval-icon-16.svg +0 -0
  21. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/brand/tuieval-icon-256.png +0 -0
  22. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/brand/tuieval-icon-32.png +0 -0
  23. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/brand/tuieval-icon-48.png +0 -0
  24. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/brand/tuieval-icon-512.png +0 -0
  25. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/brand/tuieval-icon-64.png +0 -0
  26. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/brand/tuieval-icon-animated.svg +0 -0
  27. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/brand/tuieval-icon.svg +0 -0
  28. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/tui-answer-reasoning.png +0 -0
  29. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/tui-run-reasoning.png +0 -0
  30. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/images/tui-setup.png +0 -0
  31. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/docs/writing-packs.md +0 -0
  32. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/pyproject.toml +0 -0
  33. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/__init__.py +0 -0
  34. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/__main__.py +0 -0
  35. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/agents.py +0 -0
  36. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/builtin.toml +0 -0
  37. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/cli.py +0 -0
  38. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/client.py +0 -0
  39. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/compare.py +0 -0
  40. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/dates.py +0 -0
  41. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/doctor.py +0 -0
  42. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/engine.py +0 -0
  43. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/export.py +0 -0
  44. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/graders/__init__.py +0 -0
  45. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/graders/answer.py +0 -0
  46. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/graders/code.py +0 -0
  47. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/graders/rag.py +0 -0
  48. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/graders/reply.py +0 -0
  49. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/graders/tool_call.py +0 -0
  50. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/insights.py +0 -0
  51. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/logs.py +0 -0
  52. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/machines.py +0 -0
  53. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/onboard.py +0 -0
  54. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/packs.py +0 -0
  55. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/profiles.py +0 -0
  56. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/pta.py +0 -0
  57. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/remove.py +0 -0
  58. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/scaffold.py +0 -0
  59. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/selftest.py +0 -0
  60. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/templates/models.toml +0 -0
  61. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/templates/packs/answer/pack.toml +0 -0
  62. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/templates/packs/answer/system.txt +0 -0
  63. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/templates/packs/answer/tests.yaml +0 -0
  64. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/templates/packs/code/pack.toml +0 -0
  65. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/templates/packs/code/system.txt +0 -0
  66. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/templates/packs/code/tests.yaml +0 -0
  67. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/templates/packs/rag/pack.toml +0 -0
  68. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/templates/packs/rag/system.txt +0 -0
  69. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/templates/packs/rag/tests.yaml +0 -0
  70. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/templates/packs/reply/pack.toml +0 -0
  71. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/templates/packs/reply/system.txt +0 -0
  72. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/templates/packs/reply/tests.yaml +0 -0
  73. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/templates/packs/tool_call/pack.toml +0 -0
  74. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/templates/packs/tool_call/system.txt +0 -0
  75. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/templates/packs/tool_call/tests.yaml +0 -0
  76. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/templates/packs/tool_call/tools.yaml +0 -0
  77. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/tui.py +0 -0
  78. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/tune.py +0 -0
  79. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/verdict.py +0 -0
  80. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/watch_proxy.py +0 -0
  81. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/workspace.py +0 -0
  82. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/src/tuieval/yamlout.py +0 -0
  83. {tuieval-0.2.0.dev156 → tuieval-0.2.0.dev158}/tests/mock_server.py +0 -0
@@ -2,6 +2,7 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - 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
6
  - 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
7
  - 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
8
  - `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.dev156
3
+ Version: 0.2.0.dev158
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,7 +153,7 @@ 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.
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
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.
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).
@@ -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.dev156'
22
- __version_tuple__ = version_tuple = (0, 2, 0, 'dev156')
21
+ __version__ = version = '0.2.0.dev158'
22
+ __version_tuple__ = version_tuple = (0, 2, 0, 'dev158')
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -22,7 +22,9 @@ the measurement replaces those. Memory grows about linearly with the context, so
22
22
  passed predict the largest context that fits under the machine's limit; no probe goes above that
23
23
  prediction, and a failed probe is bisected against the largest that passed. A probe is stopped at
24
24
  once, while the server loads or works, when memory pressure rises, the machine starts swapping,
25
- or memory runs out. The next probe waits until the machine has recovered (pressure back to normal,
25
+ or memory runs out. (A server that reaches the warning level at the smallest context, with nothing
26
+ swapped, fills memory to a budget of its own: for it only critical pressure counts, besides
27
+ swapping and memory running out.) The next probe waits until the machine has recovered (pressure back to normal,
26
28
  the memory given back), so one probe's pressure can't fail the next. Typically 3 to 5 server starts.
27
29
 
28
30
  Memory is read off the machine, not the server's processes: available memory before the server
@@ -52,6 +54,7 @@ APART = 0.8 # memory per token is read off two probes at least th
52
54
  MAX_STARTS = 8
53
55
  REQUEST_LIMIT_S = 3600 # reading a few hundred thousand tokens takes a while ([tune] ctx_request_timeout_s)
54
56
  PRESSURE_WARNING = 2 # macOS memory pressure level that stops a probe (1 is normal)
57
+ PRESSURE_CRITICAL = 4 # the level that stops one for a server whose normal state is the warning level
55
58
  SWAP_STOP_MB = 512 # swapped out while a probe ran: stop it
56
59
  AVAILABLE_STOP_GB = 1.0 # memory available under this stops a probe
57
60
  SETTLE_S = 120 # how long the machine may take to recover after a probe before the next one
@@ -79,6 +82,8 @@ class Probe:
79
82
  total_s: float | None = None
80
83
  load_s: float | None = None
81
84
  filled: bool = False # the server's token count confirms the context was full
85
+ pressure: int | None = None # highest macOS memory pressure level while it ran
86
+ stopped_for: str = "" # "pressure" when memory pressure alone stopped it (nothing was swapped)
82
87
 
83
88
  def summary(self):
84
89
  if not self.ok:
@@ -139,8 +144,9 @@ class Guard:
139
144
  """Watches the machine while a probe's server loads and works. When it gets unhealthy, the
140
145
  server is stopped: a load is abandoned and a request is cut off."""
141
146
 
142
- def __init__(self, eng, every_s=2.0):
143
- self.eng, self.every_s, self.reason = eng, every_s, ""
147
+ def __init__(self, eng, every_s=2.0, stop_level=PRESSURE_WARNING):
148
+ self.eng, self.every_s, self.reason, self.stop_level = eng, every_s, "", stop_level
149
+ self.pressure_only = False # stopped for memory pressure, with nothing swapped out
144
150
  self.pressure, self._stop = machines.memory_pressure_level(), threading.Event()
145
151
  self._swap0 = machines.swapped_out_bytes()
146
152
  self._own_memory = eng.machine().discrete # VRAM: the machine's memory isn't what runs out
@@ -155,7 +161,9 @@ class Guard:
155
161
  lvl = machines.memory_pressure_level()
156
162
  if lvl is not None:
157
163
  self.pressure = max(self.pressure or 0, lvl)
158
- if lvl >= PRESSURE_WARNING:
164
+ if lvl >= self.stop_level:
165
+ swap = machines.swapped_out_bytes()
166
+ self.pressure_only = None in (swap, self._swap0) or swap - self._swap0 < 2**20
159
167
  return f"macOS memory pressure rose to level {lvl}"
160
168
  swap = machines.swapped_out_bytes()
161
169
  if None not in (swap, self._swap0) and (swap - self._swap0) / 2**20 > SWAP_STOP_MB:
@@ -191,8 +199,9 @@ class Guard:
191
199
  self.eng._stall = None
192
200
 
193
201
 
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."""
202
+ def probe(eng, m, ctx, emit=lambda *a, **k: None, limit=REQUEST_LIMIT_S, stop_level=PRESSURE_WARNING):
203
+ """Serve the model with this context, fill it and ask for the fact. Returns a Probe.
204
+ stop_level: the macOS memory pressure level that stops it."""
196
205
  from . import client
197
206
  out = Probe(ctx)
198
207
  reserve = ANSWER_TOKENS + max(256, ctx // 50)
@@ -200,7 +209,7 @@ def probe(eng, m, ctx, emit=lambda *a, **k: None, limit=REQUEST_LIMIT_S):
200
209
  if target < 1024:
201
210
  out.error = f"a context of {ctx:,} is too small to test"
202
211
  return out
203
- guard = Guard(eng)
212
+ guard = Guard(eng, stop_level=stop_level)
204
213
  try:
205
214
  with guard, eng.serve(m, log_name=f"{m['label']}.ctx", ctx=ctx) as (url, info):
206
215
  out.load_s = round(info["load_s"], 1) if info.get("load_s") else None
@@ -215,8 +224,8 @@ def probe(eng, m, ctx, emit=lambda *a, **k: None, limit=REQUEST_LIMIT_S):
215
224
  met = client.metrics(res) if not res.get("error") else {}
216
225
  out.prompt_tokens, out.pp_tps, out.tg_tps = met.get("prompt_tokens"), met.get("prompt_tps"), met.get("gen_tps")
217
226
  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)
227
+ guard.reason = guard.reason or guard.check() # with the server still up: a short probe may end
228
+ out.mem_gb = memory_gb(eng, m, info, guard) # between the guard's own readings
220
229
  text = (res.get("answer") or "") + (res.get("reasoning") or "")
221
230
  if res.get("error"):
222
231
  out.error = res["error"]
@@ -234,8 +243,10 @@ def probe(eng, m, ctx, emit=lambda *a, **k: None, limit=REQUEST_LIMIT_S):
234
243
  out.error = str(e).splitlines()[0]
235
244
  if not guard.reason and any(w in out.error for w in NOT_ABOUT_CONTEXT):
236
245
  raise # a smaller context wouldn't help
246
+ out.pressure = guard.pressure
237
247
  if guard.reason: # the machine got unhealthy: that is why, whatever the server said as it was stopped
238
248
  out.ok, out.error = False, guard.reason
249
+ out.stopped_for = "pressure" if guard.pressure_only else ""
239
250
  return out
240
251
 
241
252
 
@@ -443,10 +454,24 @@ def bench(eng, label, emit=lambda *a, **k: None, max_ctx=None, start=None, step=
443
454
 
444
455
  baseline = None if sv.machine.discrete else machines.available_memory_gb()
445
456
 
457
+ rule = {"level": PRESSURE_WARNING, "passed": False}
458
+
446
459
  def try_ctx(ctx):
447
460
  eng._check()
448
461
  settle(eng, baseline, emit)
449
- return probe(eng, m, ctx, emit, limit_s)
462
+ r = probe(eng, m, ctx, emit, limit_s, rule["level"])
463
+ if r.stopped_for == "pressure" and not rule["passed"] and rule["level"] < PRESSURE_CRITICAL:
464
+ # Before anything has passed, at the smallest contexts: this isn't the context being too
465
+ # large. The server fills memory to a budget of its own and runs at the warning level.
466
+ rule["level"] = PRESSURE_CRITICAL
467
+ emit("tune_result", message=" " + r.summary())
468
+ emit("tune_step", message=f" memory pressure reaches the warning level at {ctx:,} already, with nothing "
469
+ "swapped: that is how this server runs. From here a try is stopped for swapping, "
470
+ "memory running out or critical pressure only; trying this context again")
471
+ settle(eng, baseline, emit)
472
+ r = probe(eng, m, ctx, emit, limit_s, rule["level"])
473
+ rule["passed"] = rule["passed"] or r.ok
474
+ return r
450
475
 
451
476
  tried, why = search(try_ctx, first, upper, room, step, min(FLOOR, first), max_starts, emit)
452
477
  passed = [p for p in tried if p.ok]
@@ -465,7 +490,9 @@ def bench(eng, label, emit=lambda *a, **k: None, max_ctx=None, start=None, step=
465
490
  "meta": {"date": profiles.now(), "machine": sv.machine.summary, "server_version": eng.server_version(m),
466
491
  "model_file": os.path.basename(str(m.get("model", ""))), "model_bytes": sv.identity.get("model_bytes"),
467
492
  "kv_type": sv.kv_type, "upper_bound": upper, "upper_bound_from": source,
468
- "fill_confirmed": best.filled, "server_starts": len(tried)},
493
+ "fill_confirmed": best.filled, "server_starts": len(tried),
494
+ "stops_at_pressure": "critical" if rule["level"] >= PRESSURE_CRITICAL else "warning",
495
+ "pressure_seen": max((p.pressure or 0 for p in passed), default=0) or None},
469
496
  }
470
497
  path = profiles.save_context(sv.machine.id, label, measured, eng.tuning_dir)
471
498
  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":
@@ -4267,6 +4267,37 @@ max_context = 8192
4267
4267
  self.assertEqual(got["max_ctx"], 18432)
4268
4268
  self.assertTrue(any("more than this machine's memory" in s for s in said))
4269
4269
 
4270
+ def test_a_server_that_runs_at_the_warning_level_is_judged_by_swapping(self):
4271
+ from tuieval import ctxbench, machines
4272
+ with tempfile.TemporaryDirectory() as tmp:
4273
+ e = self._engine(self._workspace(tmp))
4274
+ machines.memory_pressure_level = lambda: 2 if e._procs else 1 # warning whenever its server is up
4275
+ r = ctxbench.probe(e, e.model("sized"), 8192)
4276
+ self.assertEqual((r.ok, r.stopped_for), (False, "pressure"))
4277
+ said = []
4278
+ got = ctxbench.bench(e, "sized", lambda kind, **d: said.append(d.get("message", "")), max_ctx=65536, step=2048)
4279
+ self.assertEqual(got["max_ctx"], 18432)
4280
+ self.assertEqual((got["meta"]["stops_at_pressure"], got["meta"]["pressure_seen"]), ("critical", 2))
4281
+ self.assertEqual(sum("that is how this server runs" in s for s in said), 1) # decided once, on the first try
4282
+ # swapping still stops a try under that rule
4283
+ swapped = iter([0] + [2**30] * 1000)
4284
+ machines.swapped_out_bytes = lambda: next(swapped)
4285
+ r = ctxbench.probe(e, e.model("sized"), 8192, stop_level=ctxbench.PRESSURE_CRITICAL)
4286
+ self.assertEqual((r.ok, r.stopped_for), (False, ""))
4287
+ self.assertIn("swapped out 1024 MB", r.error)
4288
+
4289
+ def test_pressure_after_a_try_has_passed_is_the_edge(self):
4290
+ from tuieval import ctxbench, machines
4291
+ with tempfile.TemporaryDirectory() as tmp:
4292
+ e = self._engine(self._workspace(tmp))
4293
+
4294
+ def level(): # normal up to a context of 16384, warning above: the context is what does it
4295
+ cmd = [a for p in e._procs for a in p.args]
4296
+ return 2 if "--context" in cmd and int(cmd[cmd.index("--context") + 1]) > 16384 else 1
4297
+ machines.memory_pressure_level = level
4298
+ got = ctxbench.bench(e, "sized", max_ctx=65536, step=2048)
4299
+ self.assertEqual((got["max_ctx"], got["meta"]["stops_at_pressure"]), (16384, "warning"))
4300
+
4270
4301
  def test_a_probe_stops_when_the_machine_starts_swapping(self):
4271
4302
  from tuieval import ctxbench, machines
4272
4303
  with tempfile.TemporaryDirectory() as tmp:
File without changes
File without changes