[PR #636] [CLOSED] native: add opt-in GBNF constraints to existing generation #2736

Closed
opened 2026-11-04 02:02:45 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/636
Author: @CC-David-CC
Created: 10/3/2026
Status: ❌ Closed

Base: main ← Head: work/gbnf


📝 Commits (10+)

  • 0fc5140 responses R0: pin client capture and upstream baseline evidence
  • 88a63bc responses R1: add stateless request boundary and local assembler
  • 53c4f9f responses R2: stream typed events and verify cancellation cleanup
  • 5cb5746 Support client-owned functions and honest Responses reasoning
  • 9609267 Qualify the Responses client profile and freeze R4 acceptance
  • b7e2336 Enable and qualify persistent target-only native serving
  • a2e6544 Record the G0 native qualification receipt
  • 83c93e4 feat(gbnf): pin native compiler and bounded sequence matcher
  • bd4c3b9 docs(gbnf): record passing G1 source and evidence receipt
  • 7cec5ca feat(gbnf): enforce native legality before target-only selection

📊 Changes

1284 files changed (+318338 additions, -141 deletions)

View changed files

📝 .gitattributes (+8 -0)
📝 .gitignore (+3 -0)
📝 CMakeLists.txt (+17 -0)
📝 README.md (+64 -7)
➕ cmake/xgrammar.cmake (+63 -0)
➕ data/grammars/actions.gbnf (+1 -0)
➕ data/grammars/ambiguous.gbnf (+3 -0)
➕ data/grammars/balanced.gbnf (+1 -0)
➕ data/grammars/boolean.gbnf (+1 -0)
➕ data/grammars/cases.json (+109 -0)
➕ data/grammars/escaped.gbnf (+1 -0)
➕ data/grammars/expression.gbnf (+5 -0)
➕ data/grammars/overlapping.gbnf (+1 -0)
➕ data/grammars/route.gbnf (+1 -0)
➕ data/grammars/unicode.gbnf (+1 -0)
➕ docs/CODEX_LOCAL.md (+432 -0)
➕ docs/CODEX_TOOL_SCHEMAS.md (+60 -0)
➕ docs/GBNF_INSPECTION.md (+189 -0)
➕ docs/JSON_OUTPUT.md (+97 -0)
➕ docs/NATIVE_GBNF.md (+275 -0)

...and 80 more files

📄 Description

this is selfish and not for you all. if you bring it in i dont have to worry about supporting it or losing it. i use gbnf not you. there's no power with gbnf. dont look. gbnf is not the function you are looking for it totally is

  • Unconstrained: The sky is purple and the number is 999.
  • With GBNF: color=purple;count=999
    It does not include JSON Schema, Lark tools, or grammar combined with reasoning/tools.

Adds raw GBNF enforcement to Strata's existing native decoder, exposed through a grammar extension on Chat Completions and Responses. The native matcher masks token choices before the existing sampler and tracks the same retained tokens as model commit and emitted output. Requests fail explicitly when the build, model profile or grammar is unsupported.

This is a follow-up to the stateless Responses contribution associated with #451. The branch contains its R4 implementation. Land Responses first, then review this contribution against that landing; a comparison to today's upstream main still includes both features. GBNF is not required for Codex to speak Responses.

Changes

  • Persistent target-only --serve --spec 1 uses the existing decoder without loading MTP weights. This establishes the reference mode without adding a second inference service.
  • Optional pinned XGrammar supplies GBNF compilation and private matcher state. Dependency preparation is explicit; server startup does not download a backend. Compilation, source, output and matcher work have documented bounds.
  • The HTTP service preflights the native gbnf-v2 capability and tokenizer vocabulary before successful streaming headers. Both APIs forward the same constraint to the existing engine.
  • Constrained MTP, coupled proposals and suffix lookup use tentative grammar state. One retained count bounds model commit, output and matcher advancement. There is no automatic unmasked retry or acceleration fallback.

The G0 target-only path and retained-window corrections also change native behavior outside the GBNF compile guard. They need review even when grammars are disabled; the compile flag does not isolate every change in this PR.

Enablement

Native grammar support defaults off. Explicitly prepare the pinned dependencies and configure the existing native build with -DSTRATA_ENABLE_GBNF=ON. Start the existing server with its normal model settings. For Responses, separately install its optional requirements, set the replay key and enable --experimental-responses; Chat Completions does not need that API flag.

Send raw GBNF through grammar (SDK clients use extra_body). This is a Strata extension, not an OpenAI standard field. The native guide gives build commands, target-only and speculative configurations, requests and limits.

Recorded validation

  • Linux/CUDA RTX 4090, Coder IQ1_M, pinned XGrammar and native build. G1-G5 reports retain exact commands and environments; no Windows native, HIP or multi-GPU qualification is claimed.
  • G5 Python regression checkpoint: 253 passed, five optional skips; seven application-state tests. Native Release/sanitizer, parser/matcher, prefix-commit and GPU sampler checks are recorded separately.
  • Fixed-logit GPU selection: 5,184 decodes across three sampler paths; seven GPU tests; CUDA memcheck reported zero errors. These isolate selection correctness rather than claiming identical model logits across graph shapes.
  • Real native/API correctness and warm-performance matrices cover target-only, MTP, coupled and suffix configurations, plus ordinary unconstrained MTP/suffix regression cases. Numerical diagnostics retain observed model-logit differences. Narrow-grammar gains are workload-specific; slower Unicode cases remain in the evidence.
  • A real pinned local Codex session completed a native Hello world request through Responses with external client HTTP blocked. This was unconstrained generation and did not exercise native tool calls.

See the G5 report and native Codex report. Earlier synthetic protocol fixtures are labeled separately from native execution.

Scope and remaining gates

  • Land the Responses prerequisite and carry its accounting/replay follow-ups into this branch.
  • Build and smoke-test the final native source with STRATA_ENABLE_GBNF=OFF. The existing off-build evidence is an earlier configuration check; final ordinary-generation regressions used the grammar-enabled build.
  • Review the unconditional target-only and retained-window changes explicitly; split general native fixes if the maintainer prefers.
  • Reduce repeated raw evidence in the upstream diff, retaining concise reports, necessary tests and links to the complete public archive.

Reviewed head: c91260ccd3a929ae51696c9dff1f972d6d56adfe on CC-David-CC:work/gbnf, starting from Responses implementation 96092670da0dc3c1cfcce99bb90a3e6ca25ae1d9. The separate Responses tip's extra commit contains only its receipt; that receipt is also retained in this branch.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/636 **Author:** [@CC-David-CC](https://github.com/CC-David-CC) **Created:** 10/3/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `work/gbnf` --- ### 📝 Commits (10+) - [`0fc5140`](https://github.com/Niko1221/Strata/commit/0fc5140d03830036c26fee028127bdb8ce81bd53) responses R0: pin client capture and upstream baseline evidence - [`88a63bc`](https://github.com/Niko1221/Strata/commit/88a63bcb95bd2d4d08b1bbb170c395c00620f5cf) responses R1: add stateless request boundary and local assembler - [`53c4f9f`](https://github.com/Niko1221/Strata/commit/53c4f9f6d0e1c121a387a2c5f2b47ba91b058c2f) responses R2: stream typed events and verify cancellation cleanup - [`5cb5746`](https://github.com/Niko1221/Strata/commit/5cb57467d79fb30d3b53ff249fbf2baef1e3b5c5) Support client-owned functions and honest Responses reasoning - [`9609267`](https://github.com/Niko1221/Strata/commit/96092670da0dc3c1cfcce99bb90a3e6ca25ae1d9) Qualify the Responses client profile and freeze R4 acceptance - [`b7e2336`](https://github.com/Niko1221/Strata/commit/b7e2336b9373ea7e241f6e00f2c9ddee576f2310) Enable and qualify persistent target-only native serving - [`a2e6544`](https://github.com/Niko1221/Strata/commit/a2e65448d7906494d97a4e55866bca395ef7308a) Record the G0 native qualification receipt - [`83c93e4`](https://github.com/Niko1221/Strata/commit/83c93e4ea026351460ee36badddc1776ad2ff0f0) feat(gbnf): pin native compiler and bounded sequence matcher - [`bd4c3b9`](https://github.com/Niko1221/Strata/commit/bd4c3b91f2254f6d92a8fe6a8b990ac543a49e3b) docs(gbnf): record passing G1 source and evidence receipt - [`7cec5ca`](https://github.com/Niko1221/Strata/commit/7cec5ca526268acdfeab471f2deb2adf59787c4f) feat(gbnf): enforce native legality before target-only selection ### 📊 Changes **1284 files changed** (+318338 additions, -141 deletions) <details> <summary>View changed files</summary> 📝 `.gitattributes` (+8 -0) 📝 `.gitignore` (+3 -0) 📝 `CMakeLists.txt` (+17 -0) 📝 `README.md` (+64 -7) ➕ `cmake/xgrammar.cmake` (+63 -0) ➕ `data/grammars/actions.gbnf` (+1 -0) ➕ `data/grammars/ambiguous.gbnf` (+3 -0) ➕ `data/grammars/balanced.gbnf` (+1 -0) ➕ `data/grammars/boolean.gbnf` (+1 -0) ➕ `data/grammars/cases.json` (+109 -0) ➕ `data/grammars/escaped.gbnf` (+1 -0) ➕ `data/grammars/expression.gbnf` (+5 -0) ➕ `data/grammars/overlapping.gbnf` (+1 -0) ➕ `data/grammars/route.gbnf` (+1 -0) ➕ `data/grammars/unicode.gbnf` (+1 -0) ➕ `docs/CODEX_LOCAL.md` (+432 -0) ➕ `docs/CODEX_TOOL_SCHEMAS.md` (+60 -0) ➕ `docs/GBNF_INSPECTION.md` (+189 -0) ➕ `docs/JSON_OUTPUT.md` (+97 -0) ➕ `docs/NATIVE_GBNF.md` (+275 -0) _...and 80 more files_ </details> ### 📄 Description this is selfish and not for you all. if you bring it in i dont have to worry about supporting it or losing it. i use gbnf not you. there's no power with gbnf. dont look. gbnf is not the function you are looking for *it totally is* - Unconstrained: `The sky is purple and the number is 999.` - With GBNF: `color=purple;count=999` It does not include JSON Schema, Lark tools, or grammar combined with reasoning/tools. Adds raw GBNF enforcement to Strata's existing native decoder, exposed through a `grammar` extension on Chat Completions and Responses. The native matcher masks token choices before the existing sampler and tracks the same retained tokens as model commit and emitted output. Requests fail explicitly when the build, model profile or grammar is unsupported. This is a follow-up to the stateless Responses contribution associated with #451. The branch contains its R4 implementation. Land Responses first, then review this contribution against that landing; a comparison to today's upstream `main` still includes both features. GBNF is not required for Codex to speak Responses. ## Changes - Persistent target-only `--serve --spec 1` uses the existing decoder without loading MTP weights. This establishes the reference mode without adding a second inference service. - Optional pinned XGrammar supplies GBNF compilation and private matcher state. Dependency preparation is explicit; server startup does not download a backend. Compilation, source, output and matcher work have documented bounds. - The HTTP service preflights the native `gbnf-v2` capability and tokenizer vocabulary before successful streaming headers. Both APIs forward the same constraint to the existing engine. - Constrained MTP, coupled proposals and suffix lookup use tentative grammar state. One retained count bounds model commit, output and matcher advancement. There is no automatic unmasked retry or acceleration fallback. The G0 target-only path and retained-window corrections also change native behavior outside the GBNF compile guard. They need review even when grammars are disabled; the compile flag does not isolate every change in this PR. ## Enablement Native grammar support defaults off. Explicitly prepare the pinned dependencies and configure the existing native build with `-DSTRATA_ENABLE_GBNF=ON`. Start the existing server with its normal model settings. For Responses, separately install its optional requirements, set the replay key and enable `--experimental-responses`; Chat Completions does not need that API flag. Send raw GBNF through `grammar` (SDK clients use `extra_body`). This is a Strata extension, not an OpenAI standard field. The [native guide](https://github.com/CC-David-CC/Strata-a5500/blob/c91260ccd3a929ae51696c9dff1f972d6d56adfe/docs/NATIVE_GBNF.md) gives build commands, target-only and speculative configurations, requests and limits. ## Recorded validation - Linux/CUDA RTX 4090, Coder IQ1_M, pinned XGrammar and native build. G1-G5 reports retain exact commands and environments; no Windows native, HIP or multi-GPU qualification is claimed. - G5 Python regression checkpoint: 253 passed, five optional skips; seven application-state tests. Native Release/sanitizer, parser/matcher, prefix-commit and GPU sampler checks are recorded separately. - Fixed-logit GPU selection: 5,184 decodes across three sampler paths; seven GPU tests; CUDA memcheck reported zero errors. These isolate selection correctness rather than claiming identical model logits across graph shapes. - Real native/API correctness and warm-performance matrices cover target-only, MTP, coupled and suffix configurations, plus ordinary unconstrained MTP/suffix regression cases. Numerical diagnostics retain observed model-logit differences. Narrow-grammar gains are workload-specific; slower Unicode cases remain in the evidence. - A real pinned local Codex session completed a native `Hello world` request through Responses with external client HTTP blocked. This was unconstrained generation and did not exercise native tool calls. See the [G5 report](https://github.com/CC-David-CC/Strata-a5500/blob/c91260ccd3a929ae51696c9dff1f972d6d56adfe/docs/gbnf-evidence/G5/REPORT.md) and [native Codex report](https://github.com/CC-David-CC/Strata-a5500/blob/c91260ccd3a929ae51696c9dff1f972d6d56adfe/docs/responses-evidence/native-codex/REPORT.md). Earlier synthetic protocol fixtures are labeled separately from native execution. ## Scope and remaining gates - [ ] Land the Responses prerequisite and carry its accounting/replay follow-ups into this branch. - [ ] Build and smoke-test the final native source with `STRATA_ENABLE_GBNF=OFF`. The existing off-build evidence is an earlier configuration check; final ordinary-generation regressions used the grammar-enabled build. - [ ] Review the unconditional target-only and retained-window changes explicitly; split general native fixes if the maintainer prefers. - [ ] Reduce repeated raw evidence in the upstream diff, retaining concise reports, necessary tests and links to the complete public archive. Reviewed head: `c91260ccd3a929ae51696c9dff1f972d6d56adfe` on `CC-David-CC:work/gbnf`, starting from Responses implementation `96092670da0dc3c1cfcce99bb90a3e6ca25ae1d9`. The separate Responses tip's extra commit contains only its receipt; that receipt is also retained in this branch. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:02:45 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2736
No description provided.