Repository navigation
perf(server): keep token-biased requests on the lookahead pipeline - #1951
Merged
Merged
Conversation
The lookahead decode gate reused `row_supports_fused_batch`, which rejects any row with a non-empty `token_bias`. `ignore_eos` is a `-inf` bias on the EOS ids and `logit_bias` is a bias by definition, so both shapes fell back to synchronous decode: 98.6 and 98.3 against 105.0 tok/s unbiased on command-r7b at a 512-token prompt (M1 Ultra, indexers suspended). With PR #1947's decode-only command-buffer budget, which raises only the pipelined path, the same gap measured 13 to 16%. The rejection was an input shape, not sampler state: the fused `[B, vocab] -> [B]` dispatch has no per-row bias input. Token bias does not read generated history, so it folds into the logits before the dispatch, where the per-row sampler already applies it. `config_supports_fused_batch` and `row_supports_fused_batch` keep their strict meaning for callers that apply no bias (`uniform_fused_batch_params`, and through it `batched_sample`); new `..._except_bias` variants admit a biased row for callers that do. `apply_token_bias_rows` applies one map per row in one pass over the union of biased ids, never vocab-sized, with an exact `0.0` delta leaving unbiased rows bitwise unchanged, and panics on a row-count mismatch rather than dropping a bias. It runs at both dispatch points in the per-row chain position. A biased row still takes the per-row sampler while the opt-in `MLXCEL_LANG_BIAS_COUNTERS` readback is enabled. Validated on a real checkpoint: biased requests advance `mlxcel_batch_decode_lookahead_steps_total` and match unbiased throughput, unbiased requests are unchanged, and banning an emitted token yields text identical to the synchronous path. Numbers in `docs/benchmark_results/lookahead-token-bias-m1ultra-2026-09-23.md`. Gate: 11417 passed, 0 failed, clippy and fmt clean. Closes #1950
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The lookahead decode gate reuses the batched-fused predicate, which rejects any row with a non-empty
token_bias.ignore_eosis a-infbias on the EOS ids andlogit_biasis a bias by definition, so both request shapes decoded on the synchronous path. The rejection was an input shape, not sampler state: the fused[B, vocab] -> [B]dispatch carries shared scalar params and has no per-row bias input. Token bias does not read generated history, so it folds into the logits ahead of the dispatch, exactly where the per-row sampler applies it.What changed
config_supports_fused_batch/row_supports_fused_batchkeep their strict meaning for callers that apply no bias (uniform_fused_batch_params, and through itbatched_sample), with new..._except_biasvariants for callers that do.apply_token_bias_rowsapplies oneTokenBiasMapper row in a single pass over the union of biased ids (never vocab-sized). Rows that do not bias an id get an exact0.0delta and come out bitwise unchanged. A row count that disagrees with the logits panics rather than dropping a bias, which would let anignore_eosrequest sample its EOS token.batched_fused_sample_with_biasfor the synchronous fused branch, and beforeapply_row_filterswhen priming a lookahead step.MLXCEL_LANG_BIAS_COUNTERSpre-bias readback is enabled;LANG_BIAS_APPLIED_TOTALis incremented per biased row on the fused path.Measured
c4ai-command-r7b-12-2024-4bit, M1 Ultra, 512-token prompt, 128 tokens, greedy, two binaries, indexers suspended. Every row reportsmlxcel_batch_decode_lookahead_steps_totalso it states which path served it.ignore_eoslogit_biasBiased requests gain 6.2% and 6.5% and match unbiased throughput; unbiased requests are unchanged. On a build carrying #1947's decode-only command-buffer budget, which raises only the pipelined path, the same gap measured 13 to 16%.
Output equivalence: banning id 17939, the first token the unbiased run emits, changes the text on both binaries and to the same SHA-1 (
ef3caa8646c3), while only this branch keeps the pipeline. Full record:docs/benchmark_results/lookahead-token-bias-m1ultra-2026-09-23.md.Validation
cargo test --workspace --profile test-fast --features metal,accelerate: 11417 passed, 0 failed. Clippy and fmt clean. Not measured: multi-sequence batches mixing biased and unbiased rows (unit-tested only), CUDA and ROCm, stochastic sampling.Closes #1950