Skip to content

logit_bias: token biases and -100 bans on each row's draw for Qwen CUDA, Qwen3.5-2B Metal and Nemotron Parse HIP - #3146

Open
ashhart wants to merge 1 commit into
mainfrom
lead/logit-bias
Open

ashhart wants to merge 1 commit into
mainfrom
lead/logit-bias

Conversation

@ashhart

@ashhart ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Closes #3110.

logit_bias adds each listed token's value to its logit before every draw, and -100 bans the token. Supported on Qwen3.8-27B and Qwen3.5-MoE on CUDA, Qwen3.5-2B on Metal and Nemotron Parse on HIP. The bias applies on each row's draw, so drafted replies equal undrafted ones. Every other engine now refuses a non-empty logit_bias with a 400 instead of silently ignoring it, and /v1/models names the capability per engine.

Bias lookup is a binary search over the request's sorted entries. A bias token past the model head's vocabulary is refused before launch. On CUDA the bias runs as a small kernel, tf_bias_rows, before the draw. The shared sampling rule was refactored and checked equal to main for every temperature the server accepts.

Tests: the refusal test fails on main (expected 400, got 200, because main ignored the field); test-server-logit-bias-host 24; test-logit-bias-host 18 + 16; a draw-equality test; test-cuda-host 393/393 steps; HIP 78/78; goldens updated for the new capability field; CUDA cross-compiles pass.

Device check pending (GB10, Qwen3.8-27B with MTP and DFlash2): tf-cuda-test kernel-contract tf_bias_rows, where the real kernel passes and the planted control fails. Served checker zig/tests/server/logit_bias_served.py: no bias equals main, a banned token never appears, biased drafted equals undrafted, concurrent equals solo, an unbiased neighbour is unchanged. No-bias decode level with main; first-token latency of a 300-entry bias reported. tf_bias_rows register records move out of pending before a release.

@ashhart
ashhart force-pushed the lead/logit-bias branch 2 times, most recently from a1c44aa to eb90f57 Compare November 19, 2026 02:01
@ashhart ashhart added kind:perf Classified by Synthena as performance improvement synthena:needs-receipt Speed PR awaiting verified perf_receipt.py hash run labels Dec 3, 2026
@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner Author

Synthena Initial Review — Performance receipt required (kind:perf)

Adds logit_bias support (additive biases and -100 hard bans) across the request parsing, lane core, CUDA/Metal/HIP backends, and /v1/models capability reporting, with refusals on unsupported engines and kept_probs interaction.

  • Branch currently has merge conflicts against base.
  • Performance claim detected without a verified tf-receipt-v1 receipt.

Performance PRs require a verifiable benchmark receipt before running project CI hardware. See CONTRIBUTING.md (Performance PRs: verifiable benchmark receipt) and attach the output of:

python3 tools/perf_receipt.py run --base-bin /path/to/base-tf --head-bin /path/to/head-tf --model /path/to/model.tfold --out receipt.json

Findings:

  • [BLOCKER] zig/src/core/engine_api.zig: The submit-time gate rejects bias on prompt-only requests, but the server's chat/completions path parses logit_bias before knowing whether the request will be prompt-only; a prompt-only request with logit_bias will surface as a generic 400 InvalidRequest rather than the documented 400 refusal message, and the refusal test only covers non-prompt-only requests. Suggested fix: Return a specific refusal message from the server parse path (like the kept_probs refusal) when the resolved request is prompt-only, or verify the prompt-only path returns the documented 400 with a clear message and add a test for it.
  • [BLOCKER] zig/kernels/cuda/sample_penalties.cuh: The hard-ban path writes -inf unconditionally, but if the logit is already NaN the result stays NaN (NaN - inf or the ternary selecting -inf only when SUB is +inf; a NaN logit with a normal bias propagates NaN), and a bias of +inf on an already -inf logit is fine, but a nonfinite input logit with a normal bias silently propagates NaN into the draw, which the comment claims is handled but the code only handles the SUB==+inf case. Suggested fix: Either mask nonfinite logits explicitly (e.g. select -inf when !isfinite(*x) as well) or document that nonfinite input logits are out of contract; add a device test for a NaN logit with a normal bias value.
  • [WARNING] zig/src/core/contract/logit_bias_records.zig: The new tf_bias_rows kernel is registered in cuda_pending with usage registry.none, but the PR description says the device check (kernel-contract tf_bias_rows on GB10) is still pending, so the kernel has no measured resource receipt and the pending record cannot move out before release as required. Suggested fix: Run tf-cuda-test kernel-contract tf_bias_rows on the target device, record the measured register/shared-memory usage in place of registry.none, and move the record out of cuda_pending before merging.
  • [WARNING] zig/src/server/kept_probs.zig: kept_probs now refuses logit_bias, but the /v1/models capability field only reports logit_bias support per engine; clients combining the two get a 400 with no capability signal that the combination is unsupported, and the refusal message doesn't mention sending logit_bias as empty. Suggested fix: Document the kept_probs x logit_bias incompatibility in docs/api.md alongside the capability field so clients can avoid the 400.
  • Synthena

@ashhart ashhart added synthena:needs-device Initial diff review passed; waiting for device and slowdown check before READY and removed synthena:needs-receipt Speed PR awaiting verified perf_receipt.py hash run labels Dec 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind:perf Classified by Synthena as performance improvement synthena:needs-device Initial diff review passed; waiting for device and slowdown check before READY

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Request token bias and bans (logit_bias)

1 participant