Skip to content

Certify one grammar candidate for eligible greedy sampling - #2519

Merged
leehack merged 3 commits into
mainfrom
fix/greedy-routing
Dec 1, 2026
Merged

leehack merged 3 commits into
mainfrom
fix/greedy-routing

Conversation

@leehack

@leehack leehack commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

Changelog

  • [core] Greedy strict-grammar requests on large native GGUF vocabularies take the shortlist path at any topK, with unchanged output.

Production-readiness scope

  • User-facing scope — Shorter grammar sampling time with temp <= 0 and typical sampling, XTC and dynamic temperature disabled.
  • Supported platforms and paths — Native llama.cpp with the existing grammar wrapper export and at least 131,072 vocabulary tokens.
  • Fallbacks — Older runtimes and ineligible requests retain the existing sampler path. A failed certificate applies grammar to the full vocabulary. Stochastic requests still use the ordinary shortlist for topK 1–64.
  • Follow-ups — Keep Grammar-constrained sampling is slow on large-vocabulary models (Gemma 4, 262k tokens) #2444 open for stochastic sampling improvements in the owner runtime. The greedy-wrapper contract docs and test in llamadart-native#259 must land before this PR is marked ready.

Completeness checklist

  • Implemented the declared scope.
  • Documented eligibility and fallback behavior.
  • Updated the performance guide, package skill and PR changelog. The scope is internal native routing.
  • Tested the routing regression, sampler ownership, missing export and real-model parity.
  • Validation coverage registry check passes. The public capability inventory is unchanged.
  • Reviewed changes for secret-bearing logs, errors and metadata.
  • Stochastic work remains tracked by Grammar-constrained sampling is slow on large-vocabulary models (Gemma 4, 262k tokens) #2444.

PR type guidance

  • Bugfix — The greedy chain needs only the best legal candidate, but it previously requested a full topK certificate or skipped the wrapper altogether. Tests verify the wrapper argument and the following native sampler.

Test Plan

On the current head, the 28 grammar routing unit rows, focused formatting, root analysis and the platform-boundary check passed on macOS arm64. The two new rows at temp: 0.01 and temp: 0.1 both failed the audit mutation temp <= 0 → temp < 0.5 by receiving wrapper K=1 instead of K=40.

The checklist below preserves local validation from the original implementation head 29dfcd364f. Current-head CI and independent review are tracked separately.

  • dart run tool/prepare_workspace.dart
  • python3 tool/ci/check_format.py, dart analyze and dart run tool/testing/check_platform_boundaries.dart
  • dart test -p vm -j 1 --exclude-tags local-only --coverage=coverage (16,795 passed, 136 skipped)
  • Chrome is N/A for the native-only sampler change.
  • coverage-lib local row (93.85% line coverage, 70% required)
  • 26 grammar routing unit rows, 55 validation coverage and package skill tests, and 2,945 full tooling tests
  • Local-only Gemma 4 parity, release docs verification, docs-site build, website analysis and 32 website tests

Matrix Evidence

Broad local test and model results below are from 29dfcd364f. The current-head delta is one test-only commit and a clean merge of main. The sampler implementation is byte-identical to the audited version.

Matrix row Scope covered Platform / model / backend Result Evidence
static-format-analyze Format, analysis and platform boundaries macOS arm64, pinned Flutter 3.47.1 PASS No format changes or analyzer issues
root-vm Native root tests macOS arm64 PASS 16,795 passed, 136 skipped with local-only tests excluded
root-chrome Browser tests Chrome N/A Native-only sampler routing
coverage-lib Line coverage macOS arm64 PASS 93.85% (38,288/40,798), exceeds the 70% threshold
structured-output-adversarial Grammar enforcement and token parity Apple M4 Max CPU, two threads, Gemma 4 E2B IT Q4_K_S, native v1.1.0-4 PASS locally Full-mask and wrapper runs agree for greedy K=0/1/40/65, typical sampling, seeded K=64, escaped JSON and partial UTF-8. Cancellation and reload pass.
docs-site Built docs, links and release docs metadata macOS arm64 PASS 5,047 pages and zero broken internal links
high-risk-exact-head-independent-qa Blocking-only review Independent auditor-deep PENDING Draft until audit and owner contract land

Model SHA-256 0a2fac16f388b4839f075dedb681357aec3e73a96bd66b413e462b6853550c99. On four warm K=40 comparisons, wrapper sampling took 1.09–1.26 ms/token and the full mask took 20.34–22.50 ms/token. K=1 with the wrapper took 1.07–1.12 ms/token.

Review Notes

  • The independent blocking audit was clean at 29dfcd364f. The current head adds two unit rows and merges main. The pinned llama.cpp runtime installs a no-op named ?top-k for K=0 and top-k for positive K. The real unit chain verifies that both occupy the slot immediately after grammar.
  • Fresh GitHub CI is pending on 0a336e14b1a775420f1e1ea053fbe1e66f0d1762.

High-risk regression review

  • Classification — high-risk (backendRuntime)
  • Implementation task — Grammar-constrained sampling is slow on large-vocabulary models (Gemma 4, 262k tokens) #2444 greedy grammar routing
  • Independent blocking QA task — Clean auditor-deep verdict at 29dfcd364f. Current-head review is pending.
  • Exact head / base used for delta validation — 0a336e14b1a775420f1e1ea053fbe1e66f0d1762 / e168d24e016deb51aa64a5f933200061ad42da62.
  • Production-branch deletion, bypass, or miswire proof — The K=0, 40 and 65 greedy rows fail on main and pass on this head. All seven original unit mutations failed their expected rows. The audit's temp < 0.5 mutation now fails both near-zero positive-temperature rows.
  • Affected-family evidence — Gemma 4 E2B parity on the original audited head, as recorded above. Removing the typical guard did not diverge or abort on this model and prompt. The unit test detected that mutation by recording 1 instead of 40.
  • Other evidence — Input rendering and output parsing are outside the changed native sampler path.
  • Known PR-caused P1 regressions — 0 observed locally. The original audit found no blocking findings. Current-head independent review is pending.
  • Unresolved review threads — 0 at the local evidence update.
Unit mutation Failing rows
Pass the requested K to the wrapper Greedy K=40, 0 and 65
Require K=1–64 for every chain Greedy K=0 and 65
Remove the typical guard typicalP: 0.9 at K=40 and K=0
Remove the XTC guard xtcProbability: 0.5
Remove the dynamic-temperature guard dynatempRange: 0.5
Allow temperature below 1 temp: 0.8
Allow temperature below 0.5 temp: 0.01 and temp: 0.1
Remove the stochastic K range Stochastic K=0 and K=65

@leehack
leehack marked this pull request as ready for review December 1, 2026 04:54
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Chat app preview removed for leehack/llamadart-chat-pr-2519.

@leehack
leehack merged commit 6a9d078 into main Dec 1, 2026
45 of 46 checks passed
@leehack
leehack deleted the fix/greedy-routing branch December 1, 2026 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant