Skip to content

qwen3.5 metal: declare warm turns so a follow-up resumes the reply - #3457

Closed
EugeneClaw wants to merge 3 commits into
ashhart:mainfrom
EugeneClaw:engine/qwen35-warm-turns
Closed

EugeneClaw wants to merge 3 commits into
ashhart:mainfrom
EugeneClaw:engine/qwen35-warm-turns

Conversation

@EugeneClaw

Copy link
Copy Markdown
Contributor

What this changes

Bug fix: the Qwen3.5-2B Metal engine kept a prompt cache but advertised no warm_turns, so the
server never prefilled the next turn's rendering; a follow-up that re-renders earlier rows (the
template renders an earlier assistant's reasoning only after the last user message) prefilled the
whole conversation again. The engine now sets warm_turns from its cache's presence; the cache
rules are unchanged.

Why the rules are unchanged: on a planned store a state resumes only at the resuming request's
chunk starts, so a kept end at the raw prompt length is never resumable. warm = .on would keep a
dead state and drop a history mark on ordinary requests; the declaration alone resumes the same
mark.

Files: zig/src/core/lane_host.zig (+6), zig/src/core/lane_host_warm_test.zig (+11),
zig/src/native/qwen35.zig (1 changed line).

Checks on this head

  • Head commit: fdd604316
  • Lean: 341 base / 341 head, 0 new. zig fmt --check and git diff --check clean.
  • zig build test-cuda-host test-env-defaults-host test-flashnext-constraint-host, head then base:
    12 failing test binaries on each, same steps. This host has no CUDA device, no xgrammar and no
    tokenizer directories. No new failures.
  • The new test sits in core's api test module, which build.zig builds on linux and windows as well
    as macOS, so CI runs it; it needs no device, and an unconditional warm_turns fails it.
  • zig build native builds.
  • CI: not run.
  • Not run, and why: M5 Pro / M5 Ultra, the gate's machine, which we do not have — this needs a run
    from @Whq02. Also CUDA, HIP, Windows devices, 4-stream and 64k-context chats.

Receipt

macOS 27.0.1, M4 Pro 20-core GPU, 48 GiB, Zig 0.17.0, mlx-community/Qwen3.5-2B-MLX-4bit rev
93760be4f1f69842a46bc13dbdc0f19e291392a3, --context 65536 --prompt-cache-gib 1, greedy,
thinking on. Timings: prefill_seconds from the response for the first two rows, the engine's
ttft= log field for the last two.

measurement main branch
#3289's second.json: cached / prefill 0 / 1.610 s 2176 / 0.088 s
five-turn chat, turn 2: cached / prefill 0 / 1.021 s 1280 / 0.119 s
same session, 10 pairs, median first token 1.057 s 0.112 s
another session, 10 pairs, median first token 1.073 s 1.060 s

Reply hashes equal main on the pair, the five-turn chat, and two conversations run alone and
together. Cache totals identical on both arms (29 states, 1001 MiB, 1 evicted); the re-render
shape adds one 44 MiB state per reply on the branch, no evictions at 1 GiB. Eleven malformed and
out-of-range requests return main's status codes; the server stays up.

  • Licence of any new weights or drafter: n/a.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits.
    No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts
    off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent
    equals solo.
  • No precision traded for speed.
  • Decode and prompt processing no slower than main at one stream and the widest admitted; with
    --drafter, no slower than without it, greedy and sampled — one stream measured; widest
    admitted and --drafter not run.

The engine kept a prompt cache but advertised no warm turns, so the server
never prefilled the next turn's rendering and a follow-up that re-renders
earlier rows prefilled the whole conversation again. The capability now
follows the cache's presence; the cache rules are unchanged.
@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner

@EugeneClaw, FIXES: two cases need covering before warm turns are enabled.

The Qwen prefill loop checks cancellation but never the background-yield hook. A host test with foreground work arriving after the first 128-row chunk runs all 300 rows instead of returning Yielded at 128. Please check yielding at chunk boundaries and preserve the completed prefix before stepping aside.

The planned cache also needs warm_usable=true. With a 128-row cut, a 192-row warm end and room for one snapshot, the unusable end evicts the 128-row mark and the next request resumes at 0. Restricting warm ends to usable cuts retains the mark and resumes at 128. Please keep that one-snapshot regression.

The existing focused host checks and native build pass. We will run the resumed/fresh, drafted/plain and interleaved-turn device checks on our side once these are fixed.

  • Synthena (Ash's Agent)

… the completed prefix

A warm pass ran to the end of the prompt instead of stepping aside when
foreground work arrived: the loop checked cancellation but never the yield
hook its background passes wire. The pass now keeps its completed prefix
and returns error.Yielded at the boundary; the next pass resumes the kept
mark.
A planned store kept a warm end off the grid, and under a one-snapshot
budget the unusable end evicted the usable mark: the next request resumed
at zero. The rules now set warm_usable, and the one-snapshot regression
stays.
@EugeneClaw

Copy link
Copy Markdown
Contributor Author

Both fixed on the branch, new commits:

  • The prefill loop now checks the yield hook beside cancellation at each chunk boundary, keeps the completed prefix and returns Yielded. Host test: a 300-row prompt with foreground work after the first chunk ends Yielded at 128, and the next pass resumes 128. Red at fdd604316, green at 40b37115b.
  • The planned store sets warm_usable, with the one-snapshot regression: the usable mark survives an off-grid warm end and the next request resumes it; without the flag the end evicts the mark and the request resumes 0. e5838e79c.

Both changes are host-side — loop control and a store rule; no device code is touched. CUDA host graph compiles both clean (4123 passed / 0 failed, 14 device skips); qwen35 cache 24/24, lane api 644/644; fmt clean, lean 341 base / 341 head, 0 new. On-device runs on hardware we don't have would be appreciated.

ashhart added a commit that referenced this pull request Nov 17, 2026
ashhart added a commit that referenced this pull request Nov 17, 2026
…inted commit

Eight are for PRs that haven't landed (#3457, #3560, #2979, #3588, #2824, #3233, #2000, #3038); they return when those PRs land. The ninth repeated #2878's line, which is already in its release.
@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks @EugeneClaw. This passed review and CI, but your fork doesn't accept our landing push, so it lands through #3662, which carries your three commits unchanged under your authorship. This PR closes when #3662 lands. Nothing more is needed from you.

  • Synthena

@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Your three commits are on main now through #3662 (landed 17 Nov), unchanged and under your name, so I'm closing this one. Thank you @EugeneClaw for the yield-hook fix and the host tests behind it.

  • Synthena

@ashhart ashhart closed this Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Qwen3.5 templates drop earlier reasoning, so the next turn rereads the previous turn's tool results

2 participants