Repository navigation
serve: logit_bias is read, and plain steps and MTP passes draw from the same biased rows - #966
Conversation
…he same biased rows OpenAI's logit_bias object (token id to a number in -100..=100) was a 400. It is now added to each row before every pick by one owner, genloop's Bias: the step's draw and an MTP pass's verified-row draw run the same transform, so a drafted run takes the plain run's ids. ignore_eos's stop ids join it as -inf. A greedy request reads its row only where the bias can move the argmax. A structured-output request adds the bias before the schema's mask, so the bias reorders the allowed ids and lets in no other; logprobs read the row before the bias. Other forms (llama-server's array of pairs, false, a token's text), ids past the vocabulary, values out of range and one id named twice are 400s naming the field. generation_settings reports the bias as llama-server does.
There was a problem hiding this comment.
Verdict: CLEAN: No must-fix finding remains after validation.
Non-blocking
⚠ Complete gate evidence: crates/serve/tests/penalty.rs:200. The PR reports passing runs but no FAIL-first output. Record failures with the bias addition and duplicate-key guard removed, followed by the passing gate command. Include the nvidia-smi card and driver output to complete the card evidence.
Optimization headroom
- E. Less work: crates/serve/src/genloop.rs:1964. Structured requests with a nonzero bias and no logprobs can modify their owned logits buffer directly. This avoids one full row copy,
4 × n_vocabbytes per decision token [derived]; requests with logprobs still need the original row.
Checked
Duplicates: plain draws, draft draws and schema choices use the shared Bias transform. Dryer reported zero pairs.
Complexity: crapper flagged no changed function.
Silent failure: invalid bias ids and values produce named 400s. Bias ids are checked against the tokenizer vocabulary that sizes the logits row.
Tests: static mutation inspection confirms assertions for the bias addition, signed-zero normalization, schema transform, sampler wrapping, and range, vocabulary and duplicate-key checks. Mutations were not executed.
Gates: no tolerance or threshold moved; no existing test was removed.
Adversarial checks: out-of-vocabulary ids and duplicate ids with alternate decimal spellings are rejected. Bias precedes schema selection and stop bans.
Escape catalog: C1–C4 do not match the changed code. No ledger lessons are in force.
Notes
Review was static. No build or gate was run here. GPU evidence is incomplete because the PR omits the nvidia-smi output.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
logit_bias를 읽어서 일반 step과 MTP 검증 단계가 같은 bias가 더해진 행에서 토큰을 뽑게 했습니다.What and why
logit_biaswas a 400 on every route. This PR reads it on/completion,/v1/completions,/v1/chat/completionsand/v1/responses(also/responses): the object form from token id to a number in -100..=100, added to that id's logit before every pick. It works for greedy, sampled and structured-output requests, with or without the MTP draft. Plain steps and MTP verification steps apply the same row transform, so a drafted server returns the same ids as an undrafted one. A structured-output request adds the bias before the schema mask, so the bias reorders the ids the schema allows and lets in no other. Underignore_eosthe stop ids stay at -inf.logprobsreport the model's own row. Malformed input (a non-object, a key that is not a vocabulary id, a value out of range, one id named twice, in either spelling or as a repeated JSON key) is a 400 naming the field.generation_settings.logit_biasreports the applied bias.Release notes: Added:
logit_biasis accepted on/completion,/v1/completions,/v1/chat/completionsand/v1/responses, with the same ids from the MTP draft as from a plain step.Code shape
The review reads these first. A box left unticked needs one line of why.
copying it (
AGENTS.md"Common code first",docs/rust-quality.mdR14). Where I found an existing copy, Inamed it below.
(tensor shapes, the attention kind, the quant). A common owner gained no per-model branch, flag or trait method.
tools/check-comments.sh).PIN(YYYY-MM-DD):and its reason.
cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line), or "none": the existingbanninghelper incrates/serve/src/genloop.rsis generalized intoBiasandbiased, which the step path (Gen::answer) and the MTP path (Engine::advance_sampled) both use. No copy was added.What I ran
Base
7163db37ff5c25f41870df1692bce5777536f22e. Model:Qwen3.8-Flash-Next-FP4-Local. Server:BLOOMERY_DRAFT={mtp,off} bloomery-serve -m <Qwen3.8-Flash-Next-FP4-Local folder> --parallel 1 --ctx-size 16896.The serve GPU gate (the same test list as the
gate-serverecipe,--include-ignored) on the card:Real
bloomery-serveon/completion(promptThe capital of France is, 24 tokens,return_tokens; id 11751 is the first token " Paris", id 41674 is " banana"), each case run withBLOOMERY_DRAFT=mtpandBLOOMERY_DRAFT=off:logit_bias,{}or{"11751": 0}: ids[11751, 13, 561, ...], the same ids as no bias{"11751": -100}(greedy, temperature 0.8 seeds 7 and 8): id 11751 absent from the returned ids{"41674": 100}(greedy, seeds 7 and 8): every returned id is 41674{"11751": -100, "41674": 4.5}: same ids with and without the draft{"11751": 101}: 400logit_bias["11751"] must be a number in -100..=100, not 101Structured output (
/v1/chat/completions,response_formatjson_schema enumParisorLyon), same result with and without the draft:/v1/completionsand/v1/chat/completionswith{"41674": 100}give "banana banana ..." and match between the two servers. Banning the first token on those two routes, by id (MTP server):Request-parse gate and real server on the card (head
3f08d5ba0a1a2a014c89bf57171a996482d83c56, MTP draft, same model and server command), covering a repeatedlogit_biaskey on every route andn=2with a ban:Hardware (if the change is for a machine)
DGX Spark, NVIDIA GB10, driver 595.84.
AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.