Skip to main content
Back to timeline
arXivSource publication:

FactorSpec turns relational constraints into speculative drafts, accepting up to 10.5 tokens per verify step while every record stays valid

Synopsis

In structured output, relations among a record's fields could determine many tokens, yet serving engines draft from the prompt or a learned head and grammar masks enforce only syntax, so models often violate those relations. FactorSpec compiles a JSON Schema and its relations into a factor graph, treats tokens the constraint uniquely determines as certain drafts through an exact feasibility check, and picks a verify width per request. In SGLang its drafts accept up to 10.5 tokens per verify step on trip planning, up to 1.9 those of the fastest n-gram drafter shape, and decode up to 1.43 faster than speculators tuned per load, at a grammar mask's cost.

AI-generated editorial illustration: FactorSpec: Serving Exact Relational Constraints as Speculative Drafts

Interpretation

Tokens that a structured record's field relations uniquely determine can now be submitted directly as speculative drafts, so the target model verifies a whole run in one forward pass instead of generating it token by token and hoping the relations hold. Serving engines previously proposed candidates from the prompt or a learned draft head, and grammar masks guaranteed only syntax; on NATURAL PLAN trip problems of three to seven cities, Qwen3-8B wrote a valid itinerary for 10%, and retries that named the violated relation reached 14%. In SGLang, each verify step accepts up to 10.5 tokens per request on trip planning, up to 1.9 those of the fastest n-gram drafter shape; at 8, 64 and 128 requests in flight it leads speculators tuned per load by up to 1.43, and by 1.01 to 1.12 on the tool calls.

The method declares a record as a JSON Schema plus a list of relations, compiles them into a factor graph, and uses an exact feasibility check to find positions with a single admissible value, which form draft runs the target accepts whole. An exact check is far heavier than a grammar mask and on the scheduler thread would delay every request of the step; opening one field costs up to 10 ms at the 99th percentile on meeting planning. A constraint service keeps each request's session in eight worker processes outside the scheduler and writes mask rows into shared memory while the forward pass runs; mask throughput is 0.95 to 1.07 of XGrammar up to 64 in flight, at a cost of about eight host cores per GPU.

Because every record is also valid, the gain in usable output exceeds the speed gain: against syntax-only baselines it serves up to 13.9 times the valid planning records per GPU-second. A solver also makes every record valid, but its answer still enters the grammar engine one token per step; where gold follows a fixed objective, the solver's meeting schedules match gold more often. Against the solver, FactorSpec serves 1.28 to 1.46 times its valid itineraries and meeting schedules per GPU-second; on meeting planning the solver's earliest plans match gold in 46% to 56% of problems against FactorSpec's 14% to 16%.

Perspective

The demonstrated setting is six tool-calling and planning workloads on SGLang 0.5.16 and vLLM 0.21.0, with Qwen3-8B, Qwen3-1.7B, Qwen3-14B and Llama 3.1 8B on two RTX A6000 GPUs and a 64-core host, at up to 128 requests in flight. Declarations require finite domains and a table budget, a new relation kind needs a server-side extension, and writing correct relations is the application's task.

The finding that host work hides behind the device step was measured on one GPU type at up to 128 requests in flight; a faster GPU shortens the step and may need more workers per rank. Verify-width rounding makes 1 to 4 of 64 greedy meeting records differ, all valid; three runs per cell repeat the same prompts, so a speed lead of a few percent is a tie. The lead narrows as free text grows, from 1.77 times XGrammar to 1.13 when trip planning adds 128-token notes.