Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
docs: demonstrate Hello token bias with measured before and after requests
David18e7487e5291
diff --git a/docs/LOGIT_BIAS.md b/docs/LOGIT_BIAS.mdindex 2bb523913..8a92472d8 100644--- a/docs/LOGIT_BIAS.md+++ b/docs/LOGIT_BIAS.md@@ -5,22 +5,51 @@ engine, without continuous batching. The same bias applies to every generatedtoken in the request, including tokens checked together during speculativedecoding. It does not force single-token verification windows.-Supply an OpenAI-style object mapping vocabulary token IDs to numeric biases:+## 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**.++```json+{+ "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).```json{- "model": "your-model",- "messages": [{"role": "user", "content": "Write the Chinese word for hello. Only the word."}],- "max_tokens": 128,+ "model": "bias-validation",+ "messages": [{"role": "user", "content": "Reply with one English greeting, one word only."}],+ "max_tokens": 8,"temperature": 0,- "logit_bias": {"109266": -100}+ "reasoning_effort": "none",+ "logit_bias": {"9419": -100}}```-The equivalent llama.cpp-style pair list is `"logit_bias": [[109266, false]]`.+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.+between arbitrary models. Leading spaces and letter case can also change token IDs.+The four English requests were measured on llm-60 / ISTA IQ3_XXS;+[raw requests, responses and token IDs](measurements/logit-bias-1627-20261008/english/rows.json)+and a [reproduction script](../tools/logit_bias_english_example.py) are included.++## Semantics and limitsBiases must be finite numbers in `[-100, 100]`. Negative values discourage atoken, positive values encourage it, and **-100 excludes it** (`false` in adiff --git a/docs/measurements/logit-bias-1627-20261008/README.md b/docs/measurements/logit-bias-1627-20261008/README.mdindex cc28231da..eaca0573d 100644--- a/docs/measurements/logit-bias-1627-20261008/README.md+++ b/docs/measurements/logit-bias-1627-20261008/README.md@@ -11,7 +11,16 @@ work is included in this branch.main binary, the candidate without MTP, and the candidate with MTP. All requests used a loopback HTTP server andrecorded emitted token IDs at the native-engine boundary.-For the prompt "Write the Chinese word for hello. Only the word.":+The primary usage example is now English: **Hello → Hi**, with an explanation of+why token 9419 was selected and full before/after requests in+[LOGIT_BIAS.md](../../LOGIT_BIAS.md#example-hello-becomes-hi).+Four additional CUDA requests passed: no bias gives `Hello`, object and pair-list+bans of 9419 give `Hi`, then omitting the field restores `Hello`.+These are [separate receipts](english/rows.json) from the 52-check CUDA/HIP matrix,+with a [completion receipt](english/complete.json) and [engine log](english/engine.txt).++The original issue reproduction is preserved below. For the prompt+"Write the Chinese word for hello. Only the word.":| Request | Output | First token | Result ||---|---|---:|---|diff --git a/docs/measurements/logit-bias-1627-20261008/english/complete.json b/docs/measurements/logit-bias-1627-20261008/english/complete.jsonnew file mode 100644index 000000000..526b88c41--- /dev/null+++ b/docs/measurements/logit-bias-1627-20261008/english/complete.json@@ -0,0 +1,6 @@+{+ "status": "passed",+ "requests": 4,+ "token_id": 9419,+ "token_text": "Hello"+}\ No newline at end of filediff --git a/docs/measurements/logit-bias-1627-20261008/english/engine.txt b/docs/measurements/logit-bias-1627-20261008/english/engine.txtnew file mode 100644index 000000000..124282757--- /dev/null+++ b/docs/measurements/logit-bias-1627-20261008/english/engine.txt@@ -0,0 +1,40 @@+[strata] 2026-10-08 22:42:56 engine started: /home/dflanag3/strata-logit-bias-1627-20261008/build/strata --serve --pack /home/dflanag3/fleet-tool-eval-20261007/packs/ista-iq3-llm60-main --native /home/dflanag3/models/ISTA-IQ3_XXS/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00001-of-00002.gguf --ple-gguf /home/dflanag3/models/ISTA-IQ3_XXS/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00002-of-00002.gguf --expert-profile /home/dflanag3/strata-cache-bench-20261008/pr1489/data/expert-profile.bin --expert-cache auto --prefill auto:8192 --spec 2 --suffix-draft 0 --max-context 32768 --kv int8 --stats --vram-reserve-mib 1024+strata generate: PCIe probe: 28.9 GB/s host->device (best of 28.9 28.8 28.9 28.9) -> pcie_frac 0.55 (default 0.55)+strata generate: native pack: /home/dflanag3/fleet-tool-eval-20261007/packs/ista-iq3-llm60-main experts (largest blob 2.33 MB), token embedding IQ3_S in mapped host memory (260 MiB, 0.1 s)+strata generate: 1466 MiB of weights loaded from /home/dflanag3/fleet-tool-eval-20261007/packs/ista-iq3-llm60-main in 0.2 s (302 canonical tensors skipped: served natively)+strata generate: 300 native projection matrices, 1781.11 MiB of weights, in 0.3 s+strata generate: the SSD is kept awake while rows are read: one page of the table after 100 ms without a read, until 60 s after the last request (STRATA_SSD_KEEPALIVE=0 turns it off)+strata generate: profile /home/dflanag3/strata-cache-bench-20261008/pr1489/data/expert-profile.bin: 24576 ranked pairs, built for 24576 slots+strata generate: PLE on, table 320001536 rows of /home/dflanag3/models/ISTA-IQ3_XXS/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_XXS-00002-of-00002.gguf+strata generate: experimental native Q5_K head, 437043200 bytes, in 0.1 s+strata generate: GPU 0: NVIDIA RTX PRO 6000 Blackwell Workstation Edition, compute capability 12.0+strata generate: expert arena read through the file cache (buffered (not Windows))+strata generate: expert arena: cudaHostRegister PORTABLE ok; MAP_HUGETLB unavailable (needed 20464 2 MiB pages, vm.nr_hugepages=0); transparent huge pages requested (MADV_HUGEPAGE)+strata generate: loaded 39.97 GiB at 9.22 GiB/s+strata generate: CPU pool tasks/phase: 48 (automatic), participating threads: 16+strata generate: 15 pool workers on logical processors 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, the host thread on 0 (draining too) (--host-core first)+strata generate: expert cache auto: 89.90 GiB free, 1024 MiB reserved (+0 MiB for the draft head) -> 24576 slots+strata generate: expert cache 24576 slots, 39.97 GiB of VRAM; policy is+strata generate: the GPU computes the experts in the cache; it rounds differently from the CPU,+ so a reply can differ slightly from a run without the cache (same quality:+ bench/results/2026-09-27-cache-parity).+ PROFILE, ranked by routing frequency, no eviction.+strata generate: pre-filled 24576 of 24576 slots from the profile in 1.8 s (23615 MB/s); slot 0 verified+strata generate: R4 hit path ON - resident experts are computed on the GPU+strata generate: 15 expert-pool workers + the host thread+strata generate: session is up (engine 0.1.41)+strata generate: token graph hit path: 24576 resident experts, decided on the device+prefill: the CPU share is ON by default for prompt chunks below 1024 tokens (the idle CPU takes some of the experts the GPU would stream; answers can differ slightly from 0.1.40.3, mean KL ~0.004). STRATA_PREFILL_CPU_SHARE=0 turns it off.+strata serve: prompt chunk auto: 8192 tokens, a 384-slot ring+strata serve: the prompt path borrows 2484 CUDA0 cache slots (3.99 GiB)+strata hc: CUDA0: the hyper-connection read runs as staged (the norm per token and stream, the down projection's activations staged ahead by cp.async); checked bit for bit against the plain read on this card (STRATA_HC_SPLIT=1 or 0 for the earlier ones)+strata verify: window up to 2 tokens, 46.9 MiB of device buffers (100% VRAM resident: zero-doorbell graph)+strata serve: 50796 MiB of VRAM free with everything loaded+strata verify: capturing the 2-token window (50796 MiB of VRAM free)+strata verify: captured the 2-token window (upload no error, sync no error)+strata verify: capturing the 1-token window (50792 MiB of VRAM free)+strata verify: captured the 1-token window (upload no error, sync no error)+strata serve: prompt 22 tokens = 0 reused + 22 read in 169 ms (130.0 tok/s), 2 generated in 13 ms (155.5 tok/s), drafts accepted 0 of 0, 1 checkpoints+strata serve: prompt 22 tokens = 15 reused + 7 read in 30 ms (230.6 tok/s), 2 generated in 13 ms (155.0 tok/s), drafts accepted 0 of 0, 1 checkpoints+strata serve: prompt 22 tokens = 15 reused + 7 read in 30 ms (231.6 tok/s), 2 generated in 12 ms (160.7 tok/s), drafts accepted 0 of 0, 1 checkpoints+strata serve: prompt 22 tokens = 15 reused + 7 read in 30 ms (233.8 tok/s), 2 generated in 12 ms (163.5 tok/s), drafts accepted 0 of 0, 1 checkpointsdiff --git a/docs/measurements/logit-bias-1627-20261008/english/rows.json b/docs/measurements/logit-bias-1627-20261008/english/rows.jsonnew file mode 100644index 000000000..8c084d156--- /dev/null+++ b/docs/measurements/logit-bias-1627-20261008/english/rows.json@@ -0,0 +1,183 @@+[+ {+ "label": "before",+ "request": {+ "model": "bias-validation",+ "messages": [+ {+ "role": "user",+ "content": "Reply with one English greeting, one word only."+ }+ ],+ "max_tokens": 8,+ "temperature": 0,+ "reasoning_effort": "none"+ },+ "response": {+ "id": "chatcmpl-1256d19d63974dfb8877966e",+ "object": "chat.completion",+ "created": 1791513786,+ "model": "bias-validation",+ "choices": [+ {+ "index": 0,+ "message": {+ "role": "assistant",+ "content": "Hello"+ },+ "finish_reason": "stop"+ }+ ],+ "usage": {+ "prompt_tokens": 22,+ "completion_tokens": 2,+ "total_tokens": 24,+ "prompt_tokens_details": {+ "cached_tokens": 0+ }+ }+ },+ "token_ids": [+ 9419,+ 248046+ ]+ },+ {+ "label": "after-object",+ "request": {+ "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+ }+ },+ "response": {+ "id": "chatcmpl-f2875c84e1e54bea835d92d2",+ "object": "chat.completion",+ "created": 1791513787,+ "model": "bias-validation",+ "choices": [+ {+ "index": 0,+ "message": {+ "role": "assistant",+ "content": "Hi"+ },+ "finish_reason": "stop"+ }+ ],+ "usage": {+ "prompt_tokens": 22,+ "completion_tokens": 2,+ "total_tokens": 24,+ "prompt_tokens_details": {+ "cached_tokens": 0+ }+ }+ },+ "token_ids": [+ 12675,+ 248046+ ]+ },+ {+ "label": "after-pairs",+ "request": {+ "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,+ false+ ]+ ]+ },+ "response": {+ "id": "chatcmpl-3a8d472f863a452da5e9ef97",+ "object": "chat.completion",+ "created": 1791513787,+ "model": "bias-validation",+ "choices": [+ {+ "index": 0,+ "message": {+ "role": "assistant",+ "content": "Hi"+ },+ "finish_reason": "stop"+ }+ ],+ "usage": {+ "prompt_tokens": 22,+ "completion_tokens": 2,+ "total_tokens": 24,+ "prompt_tokens_details": {+ "cached_tokens": 0+ }+ }+ },+ "token_ids": [+ 12675,+ 248046+ ]+ },+ {+ "label": "cleared",+ "request": {+ "model": "bias-validation",+ "messages": [+ {+ "role": "user",+ "content": "Reply with one English greeting, one word only."+ }+ ],+ "max_tokens": 8,+ "temperature": 0,+ "reasoning_effort": "none"+ },+ "response": {+ "id": "chatcmpl-d4d2f5c8350842409157f12b",+ "object": "chat.completion",+ "created": 1791513787,+ "model": "bias-validation",+ "choices": [+ {+ "index": 0,+ "message": {+ "role": "assistant",+ "content": "Hello"+ },+ "finish_reason": "stop"+ }+ ],+ "usage": {+ "prompt_tokens": 22,+ "completion_tokens": 2,+ "total_tokens": 24,+ "prompt_tokens_details": {+ "cached_tokens": 0+ }+ }+ },+ "token_ids": [+ 9419,+ 248046+ ]+ }+]\ No newline at end of filediff --git a/tools/logit_bias_english_example.py b/tools/logit_bias_english_example.pynew file mode 100644index 000000000..f9f710eba--- /dev/null+++ b/tools/logit_bias_english_example.py@@ -0,0 +1,81 @@+"""Record the same English greeting request before and after a token ban."""+import argparse+import json+from pathlib import Path+import sys+import urllib.request++ap = argparse.ArgumentParser(description=__doc__)+for name in ['source', 'config', 'candidate', 'output']:+ ap.add_argument('--' + name, type=Path, required=True)+a = ap.parse_args()+source = a.source.resolve()+sys.path[:0] = [str(source), str(source / 'tools')]+from serve.server import StrataEngine, Service, engine_args, child_env, serve+from serve.frontend import ChatTemplate+import strata_tokenizer as ST++cfg = json.loads(a.config.read_text())+cfg = {k: v for k, v in cfg.items() if k in ['args', 'tokenizer', 'gpu', 'lib_dirs', 'env']}+args = list(cfg['args'])+for flag in ['--conversation-cache-spill-dir', '--conversation-cache-disk-mib', '--mtp']:+ if flag in args:+ i = args.index(flag)+ del args[i:i+2]+args = [x for x in args if x != '--conversation-cache-disk-only']+cfg['args'] = args+tp = Path(cfg['tokenizer'])+vocab = json.loads((tp / 'vocab.json').read_text())+tokens = [None] * len(vocab)+for token, index in vocab.items():+ tokens[index] = token+tok = ST.Tokenizer(tokens, (tp / 'merges.txt').read_text().split('\n'),+ json.loads((tp / 'token_type.json').read_text()))+a.output.mkdir(parents=True, exist_ok=True)++class AuditEngine(StrataEngine):+ def generate(self, *args, **kwargs):+ self.emitted = []+ for token in super().generate(*args, **kwargs):+ if token is not None:+ self.emitted.append(token)+ yield token++engine = AuditEngine(str(a.candidate.resolve()), engine_args(cfg), cwd=str(source),+ log=str(a.output / 'engine.txt'), env=child_env(cfg))+server = serve(Service(engine, tok, ChatTemplate(tp / 'chat_template.jinja'),+ model_name='bias-validation'), port=0)+base = dict(model='bias-validation', messages=[dict(role='user', content=+ 'Reply with one English greeting, one word only.')], max_tokens=8,+ temperature=0, reasoning_effort='none')+rows = []+def call(label, **extra):+ request = dict(base, **extra)+ req = urllib.request.Request(f'http://127.0.0.1:{server.server_address[1]}/v1/chat/completions',+ data=json.dumps(request).encode(), headers={'Content-Type': 'application/json'})+ with urllib.request.urlopen(req, timeout=180) as response:+ result = json.loads(response.read())+ row = dict(label=label, request=request, response=result, token_ids=list(engine.emitted))+ rows.append(row)+ (a.output / 'rows.json').write_text(json.dumps(rows, indent=2, ensure_ascii=False))+ print(label, row['token_ids'], result['choices'][0]['message']['content'], flush=True)+ return row++try:+ hello = tok.encode('Hello', parse_special=False)+ print('Hello tokenizer IDs:', hello, flush=True)+ before = call('before')+ assert len(hello) == 1 and hello[0] in before['token_ids'], 'Choose a prompt whose baseline emits Hello'+ banned = hello[0]+ after = call('after-object', logit_bias={str(banned): -100})+ pairs = call('after-pairs', logit_bias=[[banned, False]])+ cleared = call('cleared')+ assert banned not in after['token_ids'] and banned not in pairs['token_ids']+ assert after['token_ids'] == pairs['token_ids']+ assert cleared['token_ids'] == before['token_ids']+ (a.output / 'complete.json').write_text(json.dumps(dict(status='passed', requests=len(rows),+ token_id=banned, token_text=tok.decode([banned])), indent=2))+finally:+ server.shutdown()+ server.server_close()+ engine.close()