Skip to content

Qwen3.8-27B + DFlash2 on 64 GB: the default context fits prompts it cannot retain, so conversations past ~100K re-prefill every turn #71

Closed

Description

@benwilson

Summary. On a 64 GB M5 Pro at stock settings (0.3.5.1, tensorfold serve Vontra/Qwen3.8-27B-MLX-4bit --name bench, DFlash2 pulled), the fitted window is 140,288 tokens. But nothing above roughly 100–125K tokens can be kept for the next turn. The request is served, but storing its checkpoint fails: the store evicts every older checkpoint trying to make room, then refuses the new one anyway (see suggestion 3), so the store ends up empty. The next turn re-prefills everything: 7–11 minutes on this machine. The README says omitted --context targets the window "allowing room to retain a prompt for the next turn". That holds without the drafter and fails with it.

Machine, runtime and fixture are as in #70 (the M5 Pro 64 GB report).

A growing conversation

One conversation, +6,144 fixture tokens per turn, real replies kept, greedy, thinking off. Checkpoint state is from each request's serve.log done line.

Turn Prompt tokens Cached TTFT Checkpoint store after the turn
14 89,613 83,261 33.6 s 2 ckpts, 6.06 GiB
15 95,875 89,405 36.0 s 1 ckpt, 6.10 GiB, evictions 13→15
16 102,152 95,868 36.6 s 0 ckpts, 0.00 GiB, evictions 16
17 108,431 2,048 (system block only) 434 s 0, 0.00 GiB
18–22 114,682 → 139,783 2,048 466 → 644 s 0, 0.00 GiB
23 146,035 HTTP 400, "maximum context length is 140,288…"

With DFlash2 resident, the largest conversation checkpoint this configuration keeps is about 6.1–6.3 GiB, roughly 96–100K tokens.

Single requests (cold, then the same prompt plus one turn)

98,337 tokens 131,106 tokens 139,922 tokens 152,210 tokens
+ DFlash2 (default) kept 6.24 GiB; resumed 0.69 s not kept (0.00 GiB, evictions 5→6); resumed 574 s not kept; resumed 644 s over the window
--drafter none kept 9.44 GiB; resumed 0.59 s

Controls

So the window seems to be sized so one request fits, while keeping that request's checkpoint needs roughly 65 KB per token on top. Measured: 6.24 GiB for 98K tokens, 9.44 GiB for 152K. That extra doesn't fit alongside the drafter.

Suggestions (any one would do)

  1. When DFlash2 is resident, size the default context so a request and its checkpoint fit. Here that's about 100K rather than 140K.
  2. Or report a second number at startup, "prompts resume up to N tokens", next to the window. Clients such as Claude Code or Pi could compact before N instead of before the window.
  3. Or check before evicting. In PromptMemory.allow_checkpoint (server/prompt_memory.py), the loop while self.projected(..., extra_bytes=size) > self.budget: if not self._reclaim(): return False evicts retained checkpoints one at a time. Only after the store is empty does it find the new checkpoint still doesn't fit. Checking first whether the checkpoint would fit with the store empty (and returning False without evicting if not) would keep the other conversations' prefixes. That's the "evictions 5→6, then 0 checkpoints" pattern above.

Per-turn serve.log, request bodies and results are in the report's archive.

Activity

  1. benwilson commented on Sep 29, 2026

    @benwilson
    Author

    Re-tested on 0.3.6.2: still reproduces at stock settings. --spill-gib is a real mitigation.

    Same Mac and fixture as the report above. This time: TensorFold 0.3.6.2 (71377a5), mlx 0.32.3, tensorfold serve Vontra/Qwen3.8-27B-MLX-4bit --name bench with DFlash2. Fitted context is 140,288, unchanged from 0.3.5.1.

    Stock 0.3.6.2 behaves exactly like 0.3.5.1. The store goes 6.06 → 6.07 GiB → 0 checkpoints, 0.00 GiB after the 101,937-token turn, and the next turns re-prefill everything. Single requests do the same: a 131,134-token resumed request had 0 cached tokens and took 572 s, and a 139,950-token one had 0 and took 627 s. A 98,365-token resumed request still hits (98,304 cached, 0.60 s).

    The same growing conversation with --spill-gib 16. Each run first sends one separate conversation of about 8.2K tokens (8,225 stock, 8,226 spill), then the session, then that separate conversation again. The prompt-token column is the spill run's; the stock run is within 60 tokens of it on every turn.

    Turn Prompt tokens Stock: cached / TTFT --spill-gib 16: cached / TTFT
    15 95.7K 89,330 / 34.8 s 89,353 / 36.0 s
    16 102.0K 95,474 / 36.9 s 95,497 / 38.1 s
    17 108.2K 2,048 / 433 s 95,497 / 75.5 s
    18 114.5K 2,048 / 471 s 95,497 / 112.7 s
    19 120.7K (stopped after two misses) 95,497 / 152.0 s
    20 127.0K 95,497 / 193.1 s
    21 133.3K 95,497 / 235.8 s
    22 139.5K 95,497 / 279.3 s
    23 145.8K HTTP 400, over the window (as expected)
    The separate 8K conversation afterwards 8,225 / 8,226 0 / 19.7 s (lost) 8,192 / 0.44 s, same token_sha as before the session

    What spill fixes, and what it doesn't:

    • It saves what gets evicted. The separate conversation and the session's 95,497-token checkpoint were written to disk ("spilled conversation tokens=95497 (6.1 GiB) in 0.64s") and read back ("read conversation snapshot": six times for 95,497, once for the 8K conversation). An 89,353-token checkpoint was spilled too but never needed again.
    • It can't save the checkpoints that are refused. From the 102K turn up, the session's own checkpoints are never stored (checkpoints=0 (0.00 GiB) after each of those turns; in the source that's allow_checkpoint returning False), so there's nothing to spill. That's why turn 17 resumes from 95,497, not from about 102K. Every later turn resumes from the same 95,497-token spill and re-prefills a tail that grows by about 6K tokens a turn, adding roughly 40 s per turn.
    • The cost of turning it on is disk, not RAM. Swap stayed flat at 776 MB, and the peak footprint was 43.50 GiB against 43.44 GiB stock. The spill writes in the log add up to 12.5 GiB (0.7 + 5.7 + 6.1).

    A suggested fix building on spill. When --spill-gib is set and allow_checkpoint refuses a checkpoint for memory, write that checkpoint straight to the spill directory instead of dropping it. Its arrays exist at that moment, and 6 GiB wrote in under a second here. Each turn would then resume from the previous one, not from the last checkpoint that happened to fit, and the curve above would stay flat past 100K. Separately, the two earlier suggestions still apply to users without --spill-gib, which is off by default: size the default window so a request and its checkpoint fit with the drafter resident, or check whether a checkpoint can fit before evicting others to make room.

  2. cdepuy commented on Sep 29, 2026

    @cdepuy

    Adding a 96 GB M3 Ultra datapoint (same 0.3.5.1, same failure shape, different machine) — from a live Hermes session on the box:

    • RAM 96 GB; stock fraction 0.70 capped the MLX share at 67.2 GiB; raised it via a local env patch to 0.85 (so the limit is now bounded by Metal's ~77.8 GiB recommended working set) and --prompt-cache-gib 80.
    • The session grew 118k → 193,781 tokens. With the bigger budget, warm turns are fine (100% cached, TTFT 2.6–4.7 s, decode 18–29 tok/s, evictions flat) — the 80 GiB store does hold a ~30 GiB / 193k prefix, because on a 96 GB box there is headroom the 64 GB machine never had.
    • But the retention cliff is the same failure mode, just delayed: two requests in the window below (191,101 and 192,225 tokens) arrived after the store rotated their checkpoints to disk — cached=135,641 against a 191–192k prompt — and cost 480–503 s TTFT (a 58k-token cold re-prefill) instead of resuming. The store was 16–28 GiB before those turns, i.e. it had evicted + refilled and the newest prefix didn't round-trip.
    • The pre-reboot state (25 GB swap in use) made the cold path worse than the original prefill would have been: one 187,130-token resume took 447 s TTFT with the KV partly paged out.

    So: on a machine with headroom the trap widens (bigger prefix can be kept longer, then cliff-rotates when two or more conversations interleave or the session grows another ~60–70k); on a 64 GB box it's the documented 7–11 minute every-turn version. Both are "the fitted window admits prompts whose checkpoint doesn't fit, and allow_checkpoint only discovers that after evicting everything."

    I'd land on suggestion 3 (check fit before evicting in PromptMemory.allow_checkpoint) as the minimal fix, with 1 or 2 as the honest UX layer on top: a "prompts resume up to N tokens" second number at startup is what a client (Hermes compression, Claude Code, Pi) actually needs to compact before N rather than before the window — otherwise the client optimizes for the wrong boundary and the user pays minutes on the next turn.

    Happy to share the full live-log table (14 warm + 2 cold turns at 188–194k with per-request checkpoint GiB / evictions) if useful.

  3. ashhart commented on Sep 29, 2026

    @ashhart
    Owner

    Thanks @benwilson. Your two tables pointed at two separate faults, and both are fixed in 0.3.6.3.

    • Single requests above ~100K weren't kept because the DFlash2 head held every prompt chunk's taps until the first
      draft. Each prompt token kept 50 KB of the target's hidden states (five layers of 5,120 halves) alive in a lazy MLX
      graph, beside the 27B's 64 KB of KV. That peaked exactly when the prompt's checkpoint was copied. The head now
      evaluates the drafter's 2,047-row window after each chunk. Our startup probe went from 114.0 to 64.0 KB a token,
      and the fitted window didn't move (144,384 on our emulated 64 GB budget; your M5 Pro reported 140,288).
    • In the growing conversation, a resumed turn held the prefix it resumed from until its prefill ended. Making room
      for its own checkpoint then evicted every conversation and still failed: your turns 15, 16 and 17. The scheduler
      now lets go of it. @sanjaibalajee's PR fix: preserve prefixes when checkpoint cannot fit #74 also landed, so a copy that can't fit evicts nothing.

    I measured it on an M3 Ultra with the 64 GB class emulated (TENSORFOLD_MEMORY_LIMIT_GB=44.8,
    --prompt-cache-gib 8) and your checkpoint revisions. One conversation grew by about 6,900 tokens a turn. After a
    101,950-token cold start (360 s), every turn resumed from the one before, 108,871 through 143,481 tokens, in 38 to
    46 s each, and kept its own prompt (6.9 to 9.0 GiB). The next turn, 150,403 tokens, got the HTTP 400 for the
    144,384 window. MLX's peak stayed at 40.1 GiB of its 41.8 GiB share. With the taps fix alone, the same run lost its
    prefix on every resumed turn and prefilled from zero on the turn after.

    That's an emulated budget, not your hardware, so I'd value a rerun of your ladder on the M5 Pro once 0.3.6.3 is
    out. If you start with an explicit --context past what can be kept, startup now says so ("requests up to N tokens
    keep their prompt for the next turn").

  4. benwilson commented on Sep 29, 2026

    @benwilson
    Author

    Verified on the M5 Pro 64 GB with 0.3.6.3: fixed. Fresh venv, TensorFold 0.3.6.3 (1911880), mlx 0.32.2 as pinned, tensorfold serve Vontra/Qwen3.8-27B-MLX-4bit --name bench with DFlash2, same checkpoint revisions and fixture as before. Stock settings; no --spill-gib, no memory override.

    Startup. "then 64.0 KB a token" (0.3.6.2: 114.0). "context window 139,264 tokens: the most one request can use in the 44.8 GiB memory budget and still keep its prompt for the next turn." That's 1,024 below 0.3.6.2's 140,288, and the promise now holds.

    With an explicit --context 200000 startup says: "requests up to 140,032 tokens keep their prompt for the next turn in the 44.8 GiB memory budget; a longer one is served, and its next turn prefills again". That's exactly the second number a client needs. It's 768 above the default window's 139,264; I didn't test whether a 140K request resumes under that setting.

    The ladder (cold, then the same prompt plus one turn; 64 reply tokens, greedy):

    Rendered prompt tokens Cold TTFT 0.3.6.3 resumed: cached / TTFT 0.3.6.2 resumed: cached / TTFT
    98,337 368.8 s 98,304 / 0.53 s 98,304 / 0.60 s
    131,106 565.9 s 131,072 / 0.66 s 0 / 572 s
    138,897 618.5 s 138,890 / 0.60 s 0 / 627 s (at 139,922)

    The store kept each top-of-window prompt: checkpoints=1 (8.24 GiB) after the 131K request and (8.73 GiB) after 139K.

    The growing conversation (+6,144 fixture tokens a turn, real replies kept):

    Turn Prompt tokens Cached TTFT 0.3.6.2 same turn
    16 101,932 95,444 36.7 s 95,474 / 36.9 s
    17 108,204 101,925 37.0 s 2,048 / 433 s
    18 114,452 108,069 38.9 s 2,048 / 471 s
    19 120,703 114,213 41.2 s
    20 126,979 120,696 41.2 s
    21 133,271 126,840 43.5 s
    22 139,508 HTTP 400: "maximum context length is 139,264 tokens" (correct)

    Every turn resumed from the one before, and the checkpoint store grew from 6.84 GiB at turn 16 to 8.39 GiB at turn 21. That matches your emulated run: 36.7–43.5 s here against your 38–46 s.

    Unchanged costs, all fine: the exact lifetime peak was 43.67 GiB for the ladder (0.3.6.2: 43.67) and 43.57 GiB for the session, and swap stayed flat at 768 MB. Exactness on this build: 8/8 release checks, 4/4 with a real 8,192-token resume, and bench_concurrent --alone --serial 180/180 equal with every solo run equal to "draft": false.

    One expected limit, for the record. A separate 8K conversation sent before the session was pushed out by the end of it (cached 0 on replay, 19.0 s). That's what finite memory does at stock settings. On 0.3.6.2, --spill-gib 16 brought such a conversation back in 0.44 s, so the two combine well.

  5. added a commit that references this issue on Oct 20, 2026
    dbf7134
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions