Expand description
General structured-output grammar: a schema → flat-table → byte-FSM pipeline for GPU-resident constrained decoding (Workstream G).
G1 (this module) is CPU-only and the REFERENCE for everything downstream: the same compiled tables the CPU FSM here interprets are the buffers the WGSL interpreter (G2) will upload and read, and the serving layer (G3) drives this FSM at the per-column pick-override seam. Keeping one table-interpreter — rather than compiling a shader per schema — is the design’s core bet, and it is de-risked HERE: any JSON-Schema construct that cannot be encoded in the tables surfaces as a pure-Rust compile error before a single byte is generated.
Three pieces:
json_schema—JsonSchemaTables::compileturns aserde_json::Valueschema into flatu32/u8tables (or refuses, naming the construct). See its docs for the exact array layout.json_fsm—JsonFsmwalks those tables byte-by-byte over a fixedjson_fsm::STATE_WORDS-wordFsmState:step_byte,allowed_bytes(the constrained-decode mask),is_complete, andstep_token.token_bytes—TokenByteTablemaps a tokenizer’s token ids to raw output bytes (byte-level BPE via the engine’svocab::build_vocab_blob, with an SPM/Unigram fallback), so the FSM can be advanced one whole token at a time.
§Supported subset (OpenAI strict mode)
object/array/string/number/integer/boolean/null; properties + required with
every property required and matched in the required array’s order (that array is the canonical
key order — a parsed properties object cannot preserve declaration order without serde_json’s
preserve_order, which this workspace does not enable); mandatory additionalProperties:false;
enum/const over scalars; bounded arrays and strings; nesting depth ≤ 10; canonical output with
no whitespace. pattern/anyOf/oneOf/allOf/$ref/format/minimum/… are refused loudly,
with reserved node-kind discriminants (NodeKind::RESERVED_PATTERN et al.) held for the future
regex-DFA extension.
Re-exports§
pub use gpu::GpuGrammar;pub use gpu::GrammarKernels;pub use gpu::GrammarVocab;pub use harness::GpuSchema;pub use harness::GpuVocab;pub use harness::SchemaMeta;pub use json_fsm::FsmState;pub use json_fsm::JsonFsm;pub use json_schema::JsonSchemaTables;pub use json_schema::NodeKind;pub use token_bytes::TokenByteTable;
Modules§
- gpu
- GPU-resident JSON-schema grammar: the WGSL transcription of [
flat_step_byte] + a wgpu harness. - harness
- Flat, GPU-uploadable encoding of the G1 tables + the contract the G2 WGSL interpreter fills in.
- json_
fsm - The fixed table-interpreter: a byte-driven pushdown automaton over
JsonSchemaTables. - json_
schema - JSON-Schema → flat table compiler (the “program” the byte-FSM interprets).
- token_
bytes token id → raw bytestable, so the FSM can be walked one TOKEN at a time (the constrained decoder masks logits over token ids, then advances the grammar by the chosen token’s bytes).