okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
0116b0049
main
Per-request token biases
POST /v1/chat/completions accepts logit_bias with a supporting CUDA, HIP or Metal
engine, also with continuous batching (each slot keeps its own bias). The same bias applies to every generated
token in the request, including tokens checked together during speculative
decoding. It does not force single-token verification windows.
Example: Hello becomes Hi
We use Hello because it is a familiar word, it is exactly one token in the
tested tokenizer, and the unbiased model naturally chooses it for this prompt.
The tokenizer maps Hello to token ID 9419. That number identifies the token;
it is not its logit or probability. The value -100 is the requested bias,
which this implementation treats as a hard exclusion.
Before: send this request without a bias. The measured response was Hello.
{
"model" : "bias-validation" ,
"messages" : [{"role" : "user" , "content" : "Reply with one English greeting, one word only." }],
"max_tokens" : 8 ,
"temperature" : 0 ,
"reasoning_effort" : "none"
}
After: add only logit_bias. The measured response was Hi (token 12675).
{
"model" : "bias-validation" ,
"messages" : [{"role" : "user" , "content" : "Reply with one English greeting, one word only." }],
"max_tokens" : 8 ,
"temperature" : 0 ,
"reasoning_effort" : "none" ,
"logit_bias" : {"9419" : -100 }
}
The equivalent llama.cpp-style pair list is "logit_bias": [[9419, false]];
it also produced Hi. Removing the field on the next request restored Hello.
Nothing is banned by default. This is a per-request example, not a built-in list.
The model value above is the test server's alias; use your server's model name.
Numeric pair values are also supported, for example [[42, 2.5]].
Token IDs belong to the loaded model's tokenizer; the example ID is not portable
between arbitrary models. Leading spaces and letter case can also change token IDs.
The four English requests were measured on ISTA IQ3_XXS; a
reproduction script is included.
Semantics and limits
Biases must be finite numbers in [-100, 100]. Negative values discourage a
token, positive values encourage it, and -100 excludes it (false in a
pair list has the same meaning). The bias is added before repetition/frequency/
presence penalties, temperature, and candidate filtering. Raw model logits
are not overwritten. Banning a token does not ban a word or language: other
token sequences may produce the same text.
Omitting the field, null, {}, or [] clears the previous request's bias.
Biases are request sampling state; they are not stored in a conversation cache.
They do not change the model weights or prompt KV. A fixed dense vocabulary
vector is uploaded when the bias changes and reused within the request.
Malformed entries, duplicate IDs in pair lists, IDs outside the vocabulary,
out-of-range biases, or banning the entire vocabulary return HTTP 400. Validation
on the chat route occurs before SSE streaming headers are sent. Nonempty biases
also return HTTP 400 with older engines or the current SYCL engine, rather than
being silently ignored. The engine advertises
logit_bias=1 in its INFO response when this implementation is present.
MTP target verification applies the bias; the draft model is not biased, so a restrictive list may reduce draft acceptance. Ordinary MTP was tested. The experimental coupled/rejection-sampling combinations and multi-GPU execution were not validated in this campaign. There is no startup bias-file option in this change: send the field with each request.
1# Per-request token biases 2 3`POST /v1/chat/completions` accepts `logit_bias` with a supporting CUDA, HIP or Metal 4engine, also with continuous batching (each slot keeps its own bias). The same bias applies to every generated 5token in the request, including tokens checked together during speculative 6decoding. It does not force single-token verification windows. 7 8## Example: Hello becomes Hi 9 10We use `Hello` because it is a familiar word, it is exactly one token in the 11tested tokenizer, and the unbiased model naturally chooses it for this prompt. 12The tokenizer maps `Hello` to **token ID 9419**. That number identifies the token; 13it is not its logit or probability. The value **-100** is the requested bias, 14which this implementation treats as a hard exclusion. 15 16Before: send this request without a bias. The measured response was **Hello**. 17 18``` json 19{ 20"model" : "bias-validation" , 21"messages" : [{ "role" : "user" , "content" : "Reply with one English greeting, one word only." }], 22"max_tokens" : 8 , 23"temperature" : 0 , 24"reasoning_effort" : "none" 25} 26``` 27 28After: add only `logit_bias`. The measured response was **Hi** (token 12675). 29 30``` json 31{ 32"model" : "bias-validation" , 33"messages" : [{ "role" : "user" , "content" : "Reply with one English greeting, one word only." }], 34"max_tokens" : 8 , 35"temperature" : 0 , 36"reasoning_effort" : "none" , 37"logit_bias" : { "9419" : -100 } 38} 39``` 40 41The equivalent llama.cpp-style pair list is `"logit_bias": [[9419, false]]`; 42it also produced **Hi**. Removing the field on the next request restored **Hello**. 43Nothing is banned by default. This is a per-request example, not a built-in list. 44The `model` value above is the test server's alias; use your server's model name. 45Numeric pair values are also supported, for example `[[42, 2.5]]`. 46Token IDs belong to the loaded model's tokenizer; the example ID is not portable 47between arbitrary models. Leading spaces and letter case can also change token IDs. 48The four English requests were measured on ISTA IQ3_XXS; a 49[reproduction script](../tools/logit_bias_english_example.py) is included. 50 51## Semantics and limits 52 53Biases must be finite numbers in `[-100, 100]`. Negative values discourage a 54token, positive values encourage it, and **-100 excludes it** (`false` in a 55pair list has the same meaning). The bias is added before repetition/frequency/ 56presence penalties, temperature, and candidate filtering. Raw model logits 57are not overwritten. Banning a token does not ban a word or language: other 58token sequences may produce the same text. 59 60Omitting the field, `null`, `{}`, or `[]` clears the previous request's bias. 61Biases are request sampling state; they are not stored in a conversation cache. 62They do not change the model weights or prompt KV. A fixed dense vocabulary 63vector is uploaded when the bias changes and reused within the request. 64 65Malformed entries, duplicate IDs in pair lists, IDs outside the vocabulary, 66out-of-range biases, or banning the entire vocabulary return HTTP 400. Validation 67on the chat route occurs before SSE streaming headers are sent. Nonempty biases 68also return HTTP 400 with older engines or the current SYCL engine, rather than 69being silently ignored. The engine advertises 70`logit_bias=1` in its `INFO` response when this implementation is present. 71 72MTP target verification applies the bias; the draft model is not biased, so a 73restrictive list may reduce draft acceptance. Ordinary MTP was tested. The 74experimental coupled/rejection-sampling combinations and multi-GPU execution 75were not validated in this campaign. There is no startup bias-file option in 76this change: send the field with each request.