Repository navigation
scheduler: speculate strict structured output on full-logits verifies - #336
Conversation
|
All contributors have signed the CLA. Thank you! |
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>
60e7d72 to
4b7fa8e
Compare
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>
Live A/B on the Spark pair (Qwen3.8-Flash-Next-FP4, TP=EP=2)Test candidate:
Server-side counters confirm the mechanism exactly:
Structured decode goes from ~60% of plain throughput to ~95%. Correctness: 3/3 grammar battery requests ( 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 |
Provenance of the earlier 80–88 tok/s figureThat 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):
Method: temp=0, streamed chat completions, 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. |
|
Merged after an A/B on one GB10 (sparky). Setup: a local test merge of main
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 CI: I approved the fork's workflow runs. clippy, fmt and the rest pass. |
…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>
Summary
response_formatrequests (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 showingserial=1.00 mtp=0.00).ATLAS_GLM_STRICT_SPEC=1already 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 bystrict_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_picksspeculatively 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_specon any speculation lane (the pipeline pick is lane-independent — native MTP, DFlash, batched verify, and the scored/logprobs path all shareverify_pick_*_with_pipeline/span_picks).verify_dflash_stepruns the device-mask walk (prepare/upload/send,MASKED_VERIFYwidth flag, draft trimming) only for argmax-only models. Full-logits strict verifies carrystrict = None: drafts ride unmasked and untrimmed, an illegal draft simply loses the accept prefix, and the masked bonus row emits the grammar-legal correction.TestModelgainsVerifyScript::full_logitsso 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 strictaccept_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 newenabled_arms_by_verify_capabilityanda_full_logits_strict_verify_skips_the_device_mask_walk(asserts no device-mask upload/send, noMASKED_VERIFYwidth 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 failcargo fmt --all -- --checkclean;cargo clippy -p spark-server --testscleanATLAS_STRICT_SPEC=1): json_object/json_schema decode tok/s vs serial baseline, JSON validity spot-check — to run on the Spark pair after reviewGenerated with Devin