Manuscript Offprint

arXiv:2611.02297

FactorSpec: Serving Exact Relational Constraints as Speculative Drafts

Jianchang Su, Dawei Xiang, Wei Zhang

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Speculative decoding speeds up LLM serving by drafting tokens that the target model verifies in one pass, and its gain grows with the drafts the target accepts. Structured outputs should be an ideal case, because much of a record follows from relations among its fields: an itinerary's days follow from its cities' stays and flights. Serving engines, however, draft such text by proposing it from the prompt or a learned head, and their grammar masks enforce only syntax, so the model must satisfy the relations, which it violates: on NATURAL PLAN's trip problems, Qwen3-8B writes a valid itinerary for 10%, and retries that name the violated relation raise this to 14%. We present FactorSpec, which serves exact relational constraints as speculative drafts. FactorSpec compiles a JSON Schema and its relations into a factor graph with an exact feasibility check, drafts every token the constraint determines as certain, verifies each request at a width chosen for it, and computes the masks in worker processes outside the scheduler while the GPU runs. In SGLang, its drafts yield up to 10.5 tokens per verify step, up to 1.9×1.9\times those of the fastest n-gram drafter, and it decodes up to 1.43×1.43\times faster than speculators tuned per load, at a grammar mask's cost; it also leads in vLLM. Because every record is also valid, it serves up to 13.9×13.9\times the valid records per GPU-second of syntax-only baselines.

1 INTRODUCTION

Speculative decoding (Leviathan et al., 2023; Chen et al., 2023) speeds up LLM serving by drafting tokens that the target verifies in one forward pass, and its gain grows with the drafts the target accepts. Structured outputs, such as tool calls and plans, should be an ideal case, because much of a record follows from relations among its fields: a refund's item must belong to its order, and an itinerary's days follow from its cities' stays and the direct flights between them. Serving engines such as SGLang (Zheng et al., 2024b) and vLLM (Kwon et al., 2023), however, check only syntax, and the model violates the relations: on 999 trip problems of three to seven cities from NATURAL PLAN (Zheng et al., 2024a), Qwen3-8B writes a valid itinerary for 10%, and retries that name the violated relation reach 14% (Section 2.4).

Existing approaches each cover part of this. Grammar engines (Dong et al., 2025; Willard & Louf, 2023) answer in microseconds but enforce syntax, and an enum schema closes the gap where a record copies values from its prompt. Semantic constrained decoders (Scholak et al., 2021; Poesia et al., 2022; Mündler et al., 2025) check relations locally, which on joint relations leads a decoder to infeasible prefixes: served in an engine, arc consistency leaves 12 to 64%

Figure

Figure 1. Decoding the tour of Figure 4 after its first stop, three ways. A grammar mask admits every city, and the model chooses token by token. An n-gram drafter proposes text it has seen, which the target keeps where it agrees. FactorSpec's relations admit only Oslo on day 3, then Lima on day 6; it drafts the determined tokens, the target accepts them all, and the record completes in two steps.

of planning records incomplete. Solver pipelines (Liu et al., 2023; Pan et al., 2023) compute a valid answer outside the model, which then still decodes it token by token. The engines' drafters (Li et al., 2025b) propose likely or repeated text, and jump-forward decoding (Zheng et al., 2024b) skips the tokens a grammar determines; the text the relations compute, such as the day a stay must end, lies outside all of them.

Drafting from the relations themselves would serve both speed and validity, but it poses two systems problems. The first is speed at serving load: a drafter's gain shrinks as the batch grows (Liu et al., 2026), as one width per step spends slots on guesses. The second is cost: an exact check over joint relations, such as an all-different over cities or

1^{1}University of Connecticut, Storrs, CT, USA. Correspondence to: Wei Zhang wei.13.zhang@uconn.edu.

Preprint.

arithmetic over days, is far heavier than a grammar mask, and on the scheduler thread it would delay every request of the step.

Our insight is that an exact constraint is itself a drafter (Figure 1). It knows which positions it determines, so it can propose those tokens, and it knows for each request how many of its drafts the target will accept. It also knows its next state before the target samples a determined token, so it can compute ahead while the device runs. The constraint thus turns its cost into a source of speed.

FactorSpec builds this insight into speculative decoding for structured outputs. A client declares a record as a JSON Schema and a list of relations, which compile to a factor graph with an exact feasibility check and a token-level structure engine that admits a token only if it extends to a valid record. Against the speed problem, speculative drafters propose the constraint's determined runs as certain drafts, alone or grafted with the engine's n-gram corpus or EAGLE-3 head, and verify each request at a width chosen for it. Against the cost problem, a constraint service of worker processes holds each request's session outside the scheduler process and writes mask rows into shared memory while the forward pass runs.

We evaluate FactorSpec in SGLang and vLLM on six tool-calling and planning workloads and find that exactness is both fast and cheap. On Qwen3-8B, each verify step accepts up to 10.5 tokens, up to 1.9× those of the fastest n-gram shape, because a determined run is accepted whole. That acceptance length lets the combined drafter match or outrun the engine's speculator tuned per load at 8, 64 and 128 requests in flight (Figure 6), by up to 1.43× where the relations compute the record and 1.01 to 1.12× where the model chooses most of it. The masks alone run at 0.95 to 1.07 of XGrammar's throughput up to 64 in flight, because the workers overlap the GPU, so the cost of exactness is host CPU. Because every record is also valid, the gain in usable output is far larger: FactorSpec serves up to 13.9× the valid planning records per GPU-second of syntax-only baselines. A solver makes every record valid too, so against it the margin is speed, 1.04 to 1.46×; where gold follows a fixed objective the solver's records match gold more often. These results hold, as leads or ties, across two engines, four models, tensor parallelism and sampling.

This paper makes the following contributions.

  • The constraint as a lossless drafter that knows which drafts are certain, with per-request verify widths, where engines verify a step at one width (Sections 3.1 to 3.3).

  • Exact per-token enforcement of joint relations, where semantic decoders check local ones: a memoized feasibility check over factor graphs, a structure engine that keeps every admitted token completable, and a JSON Schema

frontend (Sections 3.4 and 3.5).

  • A constraint service outside the scheduler process, where grammar engines run inside it: worker processes write shared-memory mask rows and compute ahead (Section 3.6).

  • An evaluation in two engines, on three model sizes, two families and six workloads, against speculators tuned per load, enum schemas, retries, reasoning, solvers and enumerated schemas (Section 5).

References (58)