Skip to content

serve: keep the Qwen3 shared system prompt at message starts - #694

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:fix-qwen3-seat-message-start
Oct 23, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:fix-qwen3-seat-message-start

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Qwen3.5와 Qwen3.6 seat가 message 시작에서 prompt를 자르지 않아 공유 system prompt를 재사용하지 못하던 결함(#378)을, 한 곳의 등록 helper로 고치는 PR입니다.

Closes #378.

What and why

The Qwen3 seats never registered <|im_start|> as the message start, so marked_cuts found no message starts and the prompt call kept only its end as a checkpoint. A later request that shared the system prompt found no checkpoint below the shared length and prefilled it again. With a 3,000-token system prompt on Qwen3.6 the server log read common=3008 ask=3008 kept=0 ... reason=no-checkpoint.

Vocab::with_chat_template (crates/gpu-gates/src/bind.rs:119) now registers the message start through the existing strict with_user_start when the chat template and the special-token vocabulary both carry <|im_start|>. The Qwen3 seat (serve_seats/qwen3.rs:1626) calls it, and the Qwen3.8 seat (serve_seats/qwen38.rs) drops its own copy of the condition and calls the same helper, so the rule is written once. The Qwen3 seat reads the chat template first, so the tokenizer is read once.

serve_client::shared_system_prompt (crates/gpu-gates/src/serve_client.rs:676) is a new serve gate clause that checks the shared system prompt stays in the slot and that the reused run produces the same ids as a fresh run. gate_qwen3_serve and gate_qwen38_serve both call it, so each seat's marker registration is guarded. docs/serving.md now says that Qwen3.5 and Qwen3.6 keep a shared system prompt in the live slot, and keeps the limits for another conversation taking the slot and for saved states.

Release notes: Fixed: Qwen3.5 and Qwen3.6 now reuse a shared system prompt between requests instead of prefilling it each time.

Code shape

  • No second copy. The message-start condition lives in Vocab::with_chat_template; both seats call it and the Qwen3.8 copy is removed. The two serve gates share one clause in serve_client.rs.
  • Model code holds only architecture facts. The seats only call the helper.
  • Dead code is gone. The Qwen3.8 seat's own condition and its constant moved into the helper.
  • No silent failure. A template or vocabulary without the marker is the normal path; registration keeps the existing strict error.
  • Comments state what is true now.
  • No relaxed gate. No band, tolerance or lint moved.
  • cargo fmt is clean on the touched files. I did not run cargo clippy; the maintainers' lint runs on the PR.

Duplication found or removed: qwen38.rs carried its own message-start condition (removed, now bind.rs:119).

What I ran

Card conditions for the reproduction, from nvidia-smi on an RTX 5090 machine:

| NVIDIA-SMI 595.99.02              Driver Version: 595.99.02      CUDA Version: 13.2     |
|   0  NVIDIA GeForce RTX 5090        Off |   00000000:01:00.0 Off |                  N/A |

Host test and FAIL-first, on 29346129. bind.rs and both seat files are identical on the head cd05c6f0.

  • cargo oxide test --arch sm_120 -- -p bloomery-gpu-gates --features deepseek41 --release --lib chat_templates_register_only_a_special_message_start -- --nocapture: test result: ok. 1 passed; 0 failed. It checks four conditions: both markers present, template only, vocabulary only, neither.
  • FAIL-first: with the helper's self.with_user_start(MESSAGE_START) replaced by Ok(self), the same test failed with left: [], right: [2], and the run ended HOST_FAIL_FIRST 101.
  • cargo test -p bloomery-serve --release a_prompt_call_is_cut_at_its_messages -- --nocapture: test result: ok. 1 passed; 0 failed (the existing cut owner test).
  • On the head cd05c6f0, on a DGX Spark, cargo oxide build --arch sm_121 -- -p bloomery-gpu-gates --features deepseek41 --release --bin gate_qwen3_serve --bin gate_qwen38_serve ended Finished release profile [optimized] target(s) in 4m 20s.
  • just gate-gpu-qwen3-serve and just gate-gpu-qwen38-serve not run: I built the two gate binaries (--bin gate_qwen3_serve --bin gate_qwen38_serve) and a maintainer runs the gates.

Reproduction on Qwen3.6-35B-A3B Q4_K_M, main 010729ed against head cd05c6f0, one run of each, seven requests per arm with one generated token each. The system content is 3,000 tokens and the two questions differ, giving prompts of 3,222 and 3,223 tokens with the message start at 3,005. Context 8,192, one slot, draft off, temperature 0. TTFT is the client time to the first token on /completion. The card was idle before the run (CPU_IDLE_PASS load=0.0703125).

Server log for the second request, main then head:

cache reuse common=3008 ask=3008 kept=0 held=3222 reason=no-checkpoint: the recurrent state stands at 3222 and no checkpoint lies at or below 3008
cache reuse common=3008 ask=3008 kept=3005 held=3222 reason=checkpoint: the recurrent state copied back at 3005 for 3008 of 3222 held
Scenario main kept head kept main second TTFT (ms) head second TTFT (ms)
Shared system prompt, different question 0 3005 222.64 33.33
Same conversation continuation 3222 3222 20.17 19.38
Another prompt took the slot 0 0 221.82 234.62

The shared-system case drops by 85.03% (derived). The generated token is the same for the fresh and the reused run on both arms ([8160]).

Hardware

NVIDIA GeForce RTX 5090, driver 595.99.02, power cap 400 W. The compile check ran on a DGX Spark.

What I ran into

None of this blocks the PR.

  • When another prompt takes the slot, the system prefix is still not reused (kept=0 on both arms). That needs saved-state support for Qwen3.5 and Qwen3.6, which is a separate change. The head's TTFT in that row (234.62 ms against 221.82 ms) is one observation, and I did not separate the cost of the extra checkpoint from run-to-run variation.
  • The numbers are a single main/head pair and carry no significance claim. One generated token checks that the reused ids match a fresh run; it is not a long-decode agreement test.
  • The new clause in gate_qwen38_serve compiles, but I did not run it on a Qwen3.8 model. The Qwen3.8 limit of no restore below 4,096 positions from a saved state is unchanged.
  • t0, the full serve gates and lint were not run on my side.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 22, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CLEAN: The changed paths have no must-fix defect.

Non-blocking

⚠ Supply serve-gate results: serve_client.rs:678. Both binaries were built, but neither new clause was run. Run just gate-gpu-qwen3-serve and just gate-gpu-qwen38-serve, including FAIL-first runs with each recurrent seat's marker registration disabled. The reported host mutation proves the helper; these runs check its seat wiring and reused-state token agreement.

⚠ Complete the timing evidence: qwen3.rs:1637. The RTX 5090 TTFT table identifies the model family and quantization, but omits the exact model filename and reproduction commands. Add the server/client commands and their output alongside both hashes, as CONTRIBUTING.md requires.

Checked

Duplicates: three new functions and the relocated MESSAGE_START constant checked. No duplicate owner found. The existing DS41 clause checks its separate chat route and exact restore boundary.

Complexity: plain 31→32, served 62→63, qwen3::run 64→65. Linear clause/setup growth; no new decision tree.

Silent failure: two changed paths followed. An absent marker leaves registration empty as documented; invalid timings.cache_n returns a named gate error.

Tests: replacing bind.rs:128 with Ok(self) fails the expected-[2] assertion; FAIL-first is reported. By inspection, dropping recurrent-seat registration fails the new reuse assertion under the gates' default checkpoint spacing; differing generated ids fail equality.

Gates: shared-system clauses added to both serve gates. No threshold, pin or case relaxed or removed.

Escape catalog: no C1–C4 pattern matched.

Notes

Dryer did not run according to diagnostics.md. This review was static; no tests or card gates were run here.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_qwen38_serve.rs, crates/gpu-gates/src/bin/gate_qwen3_serve.rs, crates/gpu-gates/src/bin/shared/serve_seats/qwen3.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit 4429d60 into midagedev:main Oct 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card

Projects

None yet

Development

Successfully merging this pull request may close these issues.

serve: the Qwen3 seats never cut a prompt at the message start, so a shared system prompt is never reused

1 participant