Skip to content

scheduler: speculate strict structured output on full-logits verifies - #336

Merged
AzeezIsh merged 2 commits into
Atlas-Inf:mainfrom
maplepaladin73:devin/strict-spec-full-logits
Nov 10, 2026
Merged

AzeezIsh merged 2 commits into
Atlas-Inf:mainfrom
maplepaladin73:devin/strict-spec-full-logits

Conversation

@maplepaladin73

Copy link
Copy Markdown
Contributor

Summary

response_format requests (json_object, json_schema, tool-or-json unions) compile to strict grammars, and strict sequences were barred from speculation entirely — on the Qwen path they decoded serially at roughly two-thirds the plain decode rate (measured ~24 vs ~32 tok/s live, logs showing serial=1.00 mtp=0.00).

ATLAS_GLM_STRICT_SPEC=1 already re-admits strict sequences, but only on the GLM vocab-split verify head (verify_logits_argmax_only()), which produces argmax ids and therefore needs per-row grammar masks built by strict_spec's matcher walk and uploaded to the device before each verify.

Every other verify writes full logits that the host pick pipeline already masks row by row: span_picks speculatively advances the grammar matcher between positions (and rolls back exactly the advances afterward), so each verify row is masked at its own post-draft state — the same per-position masks the GLM walk constructs. No new masking machinery is needed.

This PR adds ATLAS_STRICT_SPEC=1 (default off) which arms that path:

  • strict_spec::enabled() now branches on verify capability: argmax-only head → existing GLM arm unchanged (glm_strict_spec + DFlash raw-argmax lane); full-logits → strict_spec on any speculation lane (the pipeline pick is lane-independent — native MTP, DFlash, batched verify, and the scored/logprobs path all share verify_pick_*_with_pipeline/span_picks).
  • verify_dflash_step runs the device-mask walk (prepare/upload/send, MASKED_VERIFY width flag, draft trimming) only for argmax-only models. Full-logits strict verifies carry strict = None: drafts ride unmasked and untrimmed, an illegal draft simply loses the accept prefix, and the masked bonus row emits the grammar-legal correction.
  • TestModel gains VerifyScript::full_logits so tests can exercise a scripted full-logits head; verify_logits_argmax_only() honors it.

Grammar correctness is preserved by construction: emitted tokens still pass through emit_token's strict accept_token (a refusal remains fatal), the matcher only ever advances by emitted tokens, and the fill-every-token NPDA invariant is untouched — the pipeline already fills the bitmask once per row.

Test plan

  • cargo test -p spark-server --bin spark strict_spec — 11/11 pass, including new enabled_arms_by_verify_capability and a_full_logits_strict_verify_skips_the_device_mask_walk (asserts no device-mask upload/send, no MASKED_VERIFY width flag, illegal draft rides the verify untrimmed and is corrected by the masked bonus, matcher advances exactly by emitted tokens)
  • cargo test -p spark-server --bin spark scheduler:: — 691 pass, 0 fail
  • cargo fmt --all -- --check clean; cargo clippy -p spark-server --tests clean
  • Live A/B on Qwen Flash (ATLAS_STRICT_SPEC=1): json_object/json_schema decode tok/s vs serial baseline, JSON validity spot-check — to run on the Spark pair after review

Generated with Devin

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA. Thank you!
Posted by the CLA Assistant Lite bot.

response_format grammars are strict, and strict sequences were barred
from speculation outright: json_object/json_schema decoded serially at
roughly two-thirds the plain decode rate. ATLAS_GLM_STRICT_SPEC already
re-admits them, but only on the GLM vocab-split head, whose verify
produces argmax ids and needs per-row masks uploaded to the device.

Every other verify writes full logits that the host pick pipeline
already masks row by row — span_picks speculatively advances the
matcher between positions and rolls back, the same per-position masks
the GLM walk builds. So ATLAS_STRICT_SPEC=1 admits strict sequences on
any full-logits verify lane: drafts ride unmasked and untrimmed, an
illegal draft simply loses the accept prefix, and the masked bonus row
supplies the grammar-legal correction. The GLM arm is unchanged.

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

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@maplepaladin73
maplepaladin73 force-pushed the devin/strict-spec-full-logits branch from 60e7d72 to 4b7fa8e Compare November 10, 2026 14:57
Handoff for the hardware run PR Atlas-Inf#336 still needs: lever off against on,
single stream and 2/4/8 concurrent structured requests, JSON and schema
validity, temperature-0 identity, and engagement from the Done: lines.
The harness is stdlib-only and records no endpoint or host details.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@maplepaladin73

Copy link
Copy Markdown
Contributor Author

Live A/B on the Spark pair (Qwen3.8-Flash-Next-FP4, TP=EP=2)

Test candidate: local/atlas-sparkqwen-main:strict-spec-4b7fa8e = upstream/main 1f6de550b + this commit (4b7fa8e0). Same image both arms; only ATLAS_STRICT_SPEC differs (profile-strict-spec.json vs -off). temp=0, streamed, decode tok/s over the post-TTFT window, n=4/arm, ~220-token completions, thinking model.

arm flag OFF (serial) flag ON delta
plain 63.0 63.2 ~flat (control)
json_object 37.4 57.2 +53%
json_schema 37.5 59.7 +59%

Server-side counters confirm the mechanism exactly:

  • OFF: Grammar constrained decoding active: response_format=... → Done ... serial=1.00 mtp=0.00 tok_step=1.000
  • ON: same grammar lines → Done ... serial=0.00 mtp=1.00 tok_step=2.5-2.7 mean_na=1.5-1.7 (healthy acceptance, no dead-draft storms)

Structured decode goes from ~60% of plain throughput to ~95%.

Correctness: 3/3 grammar battery requests (json_object ×2, strict json_schema ×1) returned valid, schema-conformant JSON at temp 0; zero grammar desync/refusal/engine-error log lines across the run. Requests that remain serial under the flag are gated by the same eligibility rules as plain requests (thinking phase, branch-pending union grammars).

Caveats: single prompt shape, mild ambient traffic on the pair during measurement; absolute tok/s is ~2× the earlier a523a07 baseline because the engine base is newer upstream main, but the ON/OFF delta is same-image and same-session.

Cluster is left running the candidate with ATLAS_STRICT_SPEC=1 for further soak; rollback is deploy-active.env + profile-active.json on both nodes.

@maplepaladin73

maplepaladin73 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Provenance of the earlier 80–88 tok/s figure

That number came from a separate idle-pair measurement on 2026-11-10 07:23 EST, before this change — it is the baseline the structured-output gap was measured against, not a result of this PR.

Deployment at the time (the production pair, unchanged for ~a week prior):

  • Upstream commit a523a07f with the Qwen3.8-Flash-Next-FP4-Local checkpoint
  • 8 lanes × 262K context, GPU memory utilization 0.80, tool grammar disabled, Bearer auth

Method: temp=0, streamed chat completions, max_tokens=256, decode tok/s = completion_tokens / (total − TTFT); arms plain (thinking on/off) and json_object/json_schema, pair idle.

Results: plain 85.9/88.8 tok/s, json_object 35.3/37.1 tok/s.

Why today's numbers differ: the A/B above ran on newer upstream main plus this commit, and other traffic shared the box during part of the run. The apples-to-apples signal for this PR is the ON/OFF delta on the same image: structured decode 37.4 → 57.2 (json_object) and 37.5 → 59.7 (json_schema), i.e. ~90–95% of plain throughput.

@AzeezIsh
AzeezIsh merged commit ed8c57e into Atlas-Inf:main Nov 10, 2026
17 of 24 checks passed
@AzeezIsh

Copy link
Copy Markdown
Contributor

Merged after an A/B on one GB10 (sparky). Setup: a local test merge of main 0e6e5ba9d + this PR, against main itself, both 27B-target builds, with #333's DFlash2 γ=8 profile (ATLAS_EXACT_VERIFY=1, 64 seqs, BF16 KV). Probe: 6 json_object + 6 json_schema (strict) chat requests, greedy, thinking off, 400 max tokens, run at C1 and then C8.

main PR, switch off PR, ATLAS_STRICT_SPEC=1
valid JSON / schema keys 12/12 / 12/12 12/12 / 12/12 12/12 / 12/12
accepted draft tokens (of 1,662) 0 0 1,298
C1 per-request decode, median (tok/s) 13.0 13.0 45.3 (33–70)
C8 per-request decode, median (tok/s) 9.5 9.6 6.2 (3.9–10.2)
  • Exact: with the switch on, every reply is byte-identical to main's serial strict decode, at C1 and C8, so the per-row masking holds up under exact verify.
  • Default path unchanged: switch off is byte-identical to main.
  • Non-strict requests unchanged: with the switch on, greedy_eq C1/C8 is 8/8 identical to serial.
  • strict_spec 11/11 and scheduler:: 694/694 pass.

Caveat for the planned Flash-Next pair A/B: the switch is slower at concurrency on this profile. At C8, per-request decode falls from ~9.5 to ~6.2 tok/s even though drafts are accepted. That points to the full-logits strict verify (host mask per row) costing more than the batched serial step it replaces once 8 sequences share a step. One run per arm; receipts in nq-115b-pr336-strict on sparky.

CI: I approved the fork's workflow runs. clippy, fmt and the rest pass. cargo test fails only on the stale dflash2_selector_abi pin, and rustdoc only on the three links, both already fixed on main by #339.

maplepaladin73 added a commit to maplepaladin73/atlas that referenced this pull request Nov 10, 2026
…rial/on; add the probe script

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

Co-Authored-By: Devin <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.

2 participants