Skip to content

scheduler: let tool-grammar sequences ride the batched MTP verify (agent traffic verified one request at a time) - #203

Merged
AzeezIsh merged 3 commits into
mainfrom
fix/grammar-batched-verify
Oct 22, 2026
Merged

AzeezIsh merged 3 commits into
mainfrom
fix/grammar-batched-verify

Conversation

@AzeezIsh

Copy link
Copy Markdown
Contributor

Summary

Requests that send tools get the tool-call grammar for their whole response (compiled at prefill). mtp_step/one_forward.rs::plan_verify kept every sequence with grammar_state.is_some() off the batched verify (plan.serial, and out of decode_rows). Any agent client that sends tools on every request (OpenClaw, opencode) therefore verified one request at a time. Rob Skillet measured it on 2×GB10 Flash-Next TP=EP=2: 4 concurrent tool requests at 41.0 tok/s total vs 96.5 with --disable-tool-grammar, with each step costing ~40 ms per request.

Nothing in the batched path actually needs grammar sequences excluded:

  • verify_pipeline_helper/batch.rs::verify_pick_batch already runs the serial path's per-sequence selection on each member's own rows: greedy-under-grammar fast path, then the masked host pipeline. fast() admits grammar under the LegacyFallback policy the batch uses, so picks stay grammar-legal and the matcher only advances in emit_token.
  • The batched re-propose already builds per-member grammar masks (verify_k4_batch_step.rs, mtp_grammar_masks_for).

Change: non-strict grammar sequences now ride the batched verify, including as decode rows. Strict (response_format) grammars keep the serial path. ATLAS_GRAMMAR_SERIAL_VERIFY=1 restores today's routing.

Evidence

  • Box and model: sparky (one GB10), nvidia/Qwen3.8-Flash-Next-FP4-Local, recipe profile (exact verify and batching lanes, MTP 3 drafts, prefix caching).
  • Load: --max-num-seqs 4, tool grammar ON, 24 requests (16 tool calls, 8 prose) at T=0 through grammar_bench.py.
  • Binary: sha256 f251cfdb582e7994, one binary for all arms.
  • Tests: cargo test --bins one_forward 9/9, grammar 111/111.
arm C=1 C=2 C=4 tool-call validity (valid JSON args, right function, no markup)
(a) ATLAS_GRAMMAR_SERIAL_VERIFY=1 (today) 23.4 25.2 25.6 24/24 at every C
(b) this PR 23.5 28.6 29.3 24/24 at every C
(c) this PR + --disable-tool-grammar true 26.5 33.0 35.8 24/24 at every C
  • C=1: (a) and (b) are byte-identical; a single sequence takes the same path.
  • C=2 / C=4: 4 and 10 of 24 responses differ in prose wording between (a) and (b), and similarly between (a) and (c) (8 and 10), which points to batch composition rather than the grammar. No tool call's name or arguments differ.
  • The gain is modest here and partial: C=4 goes 25.6 → 29.3 tok/s against a 35.8 ceiling, on a profile whose exact batching lanes limit how much batching itself buys. The rest of the gap includes grammar mask work and the 1-draft clamp under grammar (spec_step::effective_drafts_under_grammar). Giving every draft position its own mask, so grammar sequences can propose at full width, is the follow-up.
  • Not measured here: Rob's 2×GB10 TP=2 setup, where the serialization cost was much larger. A re-run there is the confirmation that matters for his traffic.

Test plan

  • Routing tests: non-strict → batch, strict → serial, kill switch → serial, grammar bootstrap rows join decode_rows
  • fmt (1.93.1), clippy -p spark-server --tests
  • sparky 3-arm A/B above
  • Rob's 2×GB10 TP=2 OpenClaw traffic with the grammar on
  • A gate that serves with the tool grammar on (every current gate passes --disable-tool-grammar true; see docs/notes/HANDOFF_PR388.md item 13)

Generated with Devin

AzeezIsh and others added 3 commits October 21, 2026 19:18
The batched pick already runs the same per-sequence fast/slow selection
as the serial path, with per-row grammar masks keeping picks legal, so
the routing filters were the only things keeping grammar sequences on
the ~40 ms serial step. Non-strict grammar sequences now land in
plan.batch; strict grammars and grammarless sequences are unchanged.
ATLAS_GRAMMAR_SERIAL_VERIFY=1 restores the old routing for A/B.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
… injectable kill switch

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…C cap)

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@AzeezIsh
AzeezIsh merged commit 504063a into main Oct 22, 2026
20 of 23 checks passed
AzeezIsh pushed a commit that referenced this pull request Nov 11, 2026
…LAS_STRICT_SPEC

A speculating strict (response_format) sequence still took a verify
forward of its own every step: plan_verify kept every strict grammar on
the per-sequence path. N concurrent structured requests ran N verify
forwards a step, and a lone one was cut to 3 drafts because the deep
window (ATLAS_MTP_DYNAMIC_DEPTH) only runs through the batched verify.

On a full-logits MTP verify the batched pick already runs the same host
pipeline per member as the per-sequence verify (the non-strict grammars
of #203 ride it), so strict sequences now join the batch, as decode rows
too, where strict_spec::rides_batch holds. The argmax-only head and the
DFlash batch keep the per-sequence verify. ATLAS_GRAMMAR_SERIAL_VERIFY
restores it for every grammar, which is the A/B arm. No new variable.

Tests: routing, two strict members in one forward (one sampled, with an
illegal draft and an illegal raw top), a window crossing </think>, and a
lone deep window. Not run on hardware.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

1 participant