feat(inference): complete b10621 sampling and grammar semantics #1436
Description
Parent
- epic(server): close llama-server b10621 compatibility gaps #1431
- Related: feat(sampling): add locally typical sampling (
typical_p) #1377
Problem
Beyond the low-risk aliases in #1430, b10621 exposes sampling algorithms and controls that mlxcel does not implement or maps differently: typical_p, top-n-sigma, dynamic temperature, Mirostat, adaptive-p, XTC edge semantics, sampler ordering, ignore-EOS, grammar/lazy-grammar triggers, preserved tokens, multiple completions, and native cache/progress fields.
Scope
- Use feat(sampling): add locally typical sampling (
typical_p) #1377 fortypical_pand add the remaining algorithms as independently testable sampler stages. - Match b10621 value domains, disable sentinels, defaults, and ordering semantics, including XTC probability/threshold behavior.
- Wire
repeat_last_n/repetition_context_sizeinto the shared repetition, frequency, and presence penalty history; the field is currently parsed but not applied to the core sampler, and fix(server): align llama-server b10621 aliases and defaults #1430 intentionally stops before this arithmetic change. - Correct
dry_penalty_last_nsentinels: b10621 uses0to disable DRY history penalties, while mlxcel currently resolves0as full history; preserve an explicit full-history form without conflating it with upstream disablement. - Add explicit sampler-sequence configuration and validate incompatible/repeated stages.
- Implement ignore-EOS,
ncompletions, time/token limits, keep/discard/cache controls, and response-field selection where supported. - Implement direct GBNF and lazy grammar triggers/preserved-token behavior or reject unsupported grammar forms before generation.
- Keep OpenAI-shaped and native request aliases synchronized without silently dropping recognized fields.
Acceptance criteria
- A field-by-field schema test covers all b10621 sampling request fields, aliases, defaults, and disable sentinels: the pinned manifest plus
tests/llama_compat_manifest.rsandsrc/server/llama_compat_tests.rshold every entry's state, spelling, default, and declaration in both directions; every entry this issue owned leftdeferred(26supported, 3not_applicablewith tested rejection, the remainder split to feat(inference): complete the remaining b10621 sampling and grammar surfaces #1485 with the shard owner set extended). - Deterministic sampler unit tests use fixed logits and seeds for each delivered stage (penalty window, DRY sentinels and off-by-one tier, top-n-sigma/XTC/ignore-eos surfaces) and for configured ordering (
--samplers/--sampler-seq/ nativesamplersaccept exactly the fixed b10621 default order and reject anything else). The unimplemented algorithm stages (Mirostat, dynatemp, adaptive-p) moved to feat(inference): complete the remaining b10621 sampling and grammar surfaces #1485. - Repetition, frequency, and presence penalties use exactly the configured recent-token window, with
0disabling the shared penalty stage and the full-history sentinel (-1) preserving existing behavior. - DRY lookback
0disables the DRY history stage,64is the server default, and the documented full-history sentinel (DRY_FULL_HISTORY, spelled-1on the CLI flags) remains available without changing the meaning of upstream-shaped requests. The>=off-by-one tier and thedry_base < 1.0fallback also landed. - Grammar tests cover eager/lazy operation, triggers, preserved tokens, malformed input, and tokenizer edge cases. Moved to feat(inference): complete the remaining b10621 sampling and grammar surfaces #1485 together with the grammar flags and fields; mlxcel's constrained decoding currently covers only the OpenAI-shaped
response_format. - Unknown or unsupported semantic fields return actionable errors rather than being ignored for every surface this issue claimed (sampler order, XTC domains, native rejections); the fields split to feat(inference): complete the remaining b10621 sampling and grammar surfaces #1485 remain deferred there rather than claimed.
- Existing OpenAI request behavior remains compatible where field names overlap:
repetition_context_size(aliasrepeat_last_n) kept its spelling and now actually reaches the sampler, and every default-off surface preserves the byte-identical baseline.
Numerical validation
For any implementation that changes arithmetic or kernel selection, run the teacher-forced logit-trace procedure from docs/benchmarks.md at realistic decode and verify widths and report disagreement at decided positions. Byte identity or perplexity alone is insufficient.
Split: the remaining algorithms and value-domain ports (Mirostat, dynatemp, adaptive-p, grammar surfaces, logit-bias, dry-sequence-breaker strings, min_keep, n_probs, post_sampling_probs, backend_sampling, and the temp/top-k/top-p/seed default-resolution divergences) moved to #1485, which now co-owns the sampling-and-grammar shard.
Activity
fix: align llama-server b10621 compatibility (#1454)
fix(compat): forbid a supported b10621 entry from carrying a divergence
test(server): add pinned b10621 compatibility manifest and gates
fix(server): accept space-separated negative values on server flags
fix(server): honor string stop sequences on the MLX serving path
fix(compat): move the native completion remainder to #1477
feat(sampling): add top-n-sigma logit filtering with a row-filter hook (
fix(server): correct b10621 stop, XTC, and DRY domain semantics
feat(server): implement the b10621 sampler remainder and the GBNF gra…
feat(server): implement the b10621 sampler remainder and the GBNF gra…
fix(server): report b10621 tokens_cached and accept verbose on the na…
feat(server): implement the b10621 sampler remainder and the GBNF gra…
feat(server): implement the b10621 sampler remainder and the GBNF gra…
fix(bench): measure every model over the same interval
perf(cuda): convert bf16 weights to f16 at load on pre-Ampere GPUs (#…
feat(inference): complete b10621 sampling semantics and windows (labl…
perf(cuda/quant): add a Volta tensor-core arm to qmm_naive (#1678)