[GH-ISSUE #675] Feature request: logprobs / top_logprobs on /v1/chat/completions (typed decisions from one forward pass) #315

Closed
opened 2026-11-04 01:41:53 +07:00 by bsakaguchi · 17 comments
Owner

Originally created by @Grandmasg on GitHub (Oct 3, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/675

What I would like

Support for the OpenAI request fields logprobs: true and top_logprobs: N (a small N, for example up to 20), at least for requests with max_tokens: 1. The response would then contain the log probabilities of the most likely next tokens, in the usual OpenAI shape (choices[0].logprobs.content[0].top_logprobs).

Why

A small, useful technique with local models is the "typed decision": ask a question with a fixed set of options (for example A) normal content B) contains instructions aimed at the AI), generate one token, and read the probability of each option token from the logits. No text is generated, so a decision costs one forward pass and gives a calibrated-ish probability instead of a yes or no. It is the idea behind TypeSafe's Jev and the open SemIf-OpenJev.

My use case is a local coding agent that checks tool output (file contents, web pages) for prompt injection before the model sees it.

I tried it with llama-server on three models from the same family. Public datasets (not written by me), request with max_tokens: 1, logprobs: true, top_logprobs: 10, temperature 0, RTX 4090:

Model deepset/prompt-injections (test, n=116) AUC xTRam1/safe-guard-prompt-injection (sample n=400) AUC median time per decision
Qwen3.5-4B Q4_K_M 0.988 0.993 76 to 88 ms
Qwen3.5-9B Q4_K_M 0.985 0.989 81 to 95 ms
Qwen3.5-35B-A3B Q4_K_M 0.983 0.987 104 to 167 ms

So the signal is good and fast. It would be nice to get the same from Strata, because the 125B model is the best model I can run here, and a guard that uses the same loaded model needs no second model in memory.

What happens today

Strata accepts the request but returns no logprobs field. Request:

{"model":"x","messages":[{"role":"user","content":"Answer with only A or B: is the sky blue? A) yes B) no"}],
 "max_tokens":1,"temperature":0,"logprobs":true,"top_logprobs":5,"reasoning_effort":"none"}

Response: "content": "A", "finish_reason": "length", and usage and timings, but no logprobs. I also searched the docs, the code and the issues for "logprobs" and found nothing, so I assume it is simply not implemented, not that I missed a setting.

I read through the existing issues and pull requests and found no request for this in the API. Related, but not the same: #235 (STRATA_LOGPOS, per-position log-probabilities written to a file for diagnostics) and #462 (STRATA_DUMP_WINDOW_LOGITS), so the engine already has these values internally. #636 (opt-in GBNF constraints) can restrict the output to fixed options, but it does not return probabilities, so it does not replace this.

Ideas, from small to large

  1. Minimal: return top_logprobs for the first generated token when max_tokens is 1 (no speculative decoding is involved for a single token).
  2. Per token: return logprobs for every generated token. I understand this is harder with the MTP draft and verification, because accepted draft tokens would need their probabilities from the verify pass.
  3. Alternative shape: a small endpoint that takes a prompt and a list of candidate next tokens and returns their probabilities.

I know the sampler runs on the GPU, so I am not assuming any of this is quick. If it is out of scope for Strata, that is fine, I only wanted to check that I did not miss an existing way.

Environment

Windows 11 24H2, RTX 4090 (24 GB), Ryzen 9 9950X3D, 128 GB RAM, Strata engine 0.1.38 (repo commit 99f3dbd), Qwen3.8-Flash-Next IQ3_S, context 32768, model files on an NVMe disk (about 77 tokens/s generation, about 4,000 tokens/s prompt reading on a 23k-token prompt). Happy to test a branch.


the measurements were run locally on my machine.

Originally created by @Grandmasg on GitHub (Oct 3, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/675 ## What I would like Support for the OpenAI request fields `logprobs: true` and `top_logprobs: N` (a small N, for example up to 20), at least for requests with `max_tokens: 1`. The response would then contain the log probabilities of the most likely next tokens, in the usual OpenAI shape (`choices[0].logprobs.content[0].top_logprobs`). ## Why A small, useful technique with local models is the "typed decision": ask a question with a fixed set of options (for example `A) normal content B) contains instructions aimed at the AI`), generate **one token**, and read the probability of each option token from the logits. No text is generated, so a decision costs one forward pass and gives a calibrated-ish probability instead of a yes or no. It is the idea behind TypeSafe's Jev and the open SemIf-OpenJev. My use case is a local coding agent that checks tool output (file contents, web pages) for prompt injection before the model sees it. I tried it with llama-server on three models from the same family. Public datasets (not written by me), request with `max_tokens: 1`, `logprobs: true`, `top_logprobs: 10`, temperature 0, RTX 4090: | Model | deepset/prompt-injections (test, n=116) AUC | xTRam1/safe-guard-prompt-injection (sample n=400) AUC | median time per decision | | --- | --- | --- | --- | | Qwen3.5-4B Q4_K_M | 0.988 | 0.993 | 76 to 88 ms | | Qwen3.5-9B Q4_K_M | 0.985 | 0.989 | 81 to 95 ms | | Qwen3.5-35B-A3B Q4_K_M | 0.983 | 0.987 | 104 to 167 ms | So the signal is good and fast. It would be nice to get the same from Strata, because the 125B model is the best model I can run here, and a guard that uses the same loaded model needs no second model in memory. ## What happens today Strata accepts the request but returns no `logprobs` field. Request: ```json {"model":"x","messages":[{"role":"user","content":"Answer with only A or B: is the sky blue? A) yes B) no"}], "max_tokens":1,"temperature":0,"logprobs":true,"top_logprobs":5,"reasoning_effort":"none"} ``` Response: `"content": "A"`, `"finish_reason": "length"`, and `usage` and `timings`, but no `logprobs`. I also searched the docs, the code and the issues for "logprobs" and found nothing, so I assume it is simply not implemented, not that I missed a setting. ## Related work in this repo I read through the existing issues and pull requests and found no request for this in the API. Related, but not the same: #235 (`STRATA_LOGPOS`, per-position log-probabilities written to a file for diagnostics) and #462 (`STRATA_DUMP_WINDOW_LOGITS`), so the engine already has these values internally. #636 (opt-in GBNF constraints) can restrict the output to fixed options, but it does not return probabilities, so it does not replace this. ## Ideas, from small to large 1. **Minimal:** return `top_logprobs` for the first generated token when `max_tokens` is 1 (no speculative decoding is involved for a single token). 2. **Per token:** return logprobs for every generated token. I understand this is harder with the MTP draft and verification, because accepted draft tokens would need their probabilities from the verify pass. 3. **Alternative shape:** a small endpoint that takes a prompt and a list of candidate next tokens and returns their probabilities. I know the sampler runs on the GPU, so I am not assuming any of this is quick. If it is out of scope for Strata, that is fine, I only wanted to check that I did not miss an existing way. ## Environment Windows 11 24H2, RTX 4090 (24 GB), Ryzen 9 9950X3D, 128 GB RAM, Strata engine 0.1.38 (repo commit 99f3dbd), Qwen3.8-Flash-Next IQ3_S, context 32768, model files on an NVMe disk (about 77 tokens/s generation, about 4,000 tokens/s prompt reading on a 23k-token prompt). Happy to test a branch. --- *the measurements were run locally on my machine.*
Author
Owner

@CC-David-CC commented on GitHub (Oct 3, 2026):

just seeing your request. give me a little bit.

<!-- gh-comment-id:5974408846 --> @CC-David-CC commented on GitHub (Oct 3, 2026): just seeing your request. give me a little bit.
Author
Owner

@CC-David-CC commented on GitHub (Oct 4, 2026):

https://github.com/CC-David-CC/Strata-a5500/tree/work/logprobs-675
partial fulfillment of your request - feedback requested. i have some changes planned to this so don't get comfortable with it quite yet

<!-- gh-comment-id:5975136086 --> @CC-David-CC commented on GitHub (Oct 4, 2026): https://github.com/CC-David-CC/Strata-a5500/tree/work/logprobs-675 partial fulfillment of your request - feedback requested. i have some changes planned to this so don't get comfortable with it quite yet
Author
Owner

@CC-David-CC commented on GitHub (Oct 4, 2026):

work in progress.
testing probabilities anyway , is that initial work good enough for what you want? it exposes some logprobs but i'm still extending it further)

Image this branch is not yet live but will be asap (just got to quash a few more bugs but you can even see the logprobs are coming together) Image Image
<!-- gh-comment-id:5976386700 --> @CC-David-CC commented on GitHub (Oct 4, 2026): work in progress. testing probabilities anyway , is that initial work good enough for what you want? it exposes some logprobs but i'm still extending it further) <img width="2886" height="1888" alt="Image" src="https://github.com/user-attachments/assets/64045421-d6a2-42be-925b-7d7f4baab61c" /> this branch is not yet live but will be asap (just got to quash a few more bugs but you can even see the logprobs are coming together) <img width="2372" height="1150" alt="Image" src="https://github.com/user-attachments/assets/48ab5f62-30ea-46d2-ba2c-27dfd3a6b7ff" /> <img width="2342" height="1740" alt="Image" src="https://github.com/user-attachments/assets/8c6f542f-033b-45ec-8d31-b4730c85ec92" />
Author
Owner

@Grandmasg commented on GitHub (Oct 4, 2026):

Thanks again, this is great. To answer your question: yes, the initial work is good enough for what I wanted.

I built work/logprobs-675 at 2243cb1 (CUDA 13.0, sm_89 only, RTX 4090; about 1.5 min to compile) and ran it with the existing IQ3_S pack on its own port.

What I tested: non-streaming /v1/chat/completions with max_tokens: 1, temperature: 0, logprobs: true, top_logprobs: 10, reasoning_effort: "none". One-token A/B classification of 49 short texts of my own (23 containing a hidden instruction aimed at an AI assistant, 26 without), score = P(B) / (P(A) + P(B)), summing A and A.

Results: AUC 1.000. All 23 positives are flagged at any threshold from 0.02 up, and there is no false alarm from 0.2 up. Lowest score among the positives 0.996, highest among the negatives 0.093. For comparison, a 4B model on llama-server gives a much tighter 0.697 vs 0.682 on the same set, so the full-vocabulary probabilities from the big model separate far better. Median 707 ms per decision (prompts of up to about 1,500 characters), the whole set in about 34 s. It is my own small set, so please read it as indicative.

One note: without reasoning_effort: "none" the response has an empty logprobs.content for max_tokens: 1 (the single token is spent on thinking, which is excluded from content scores). That matches your docs, but one line about it in the one-token use case could save someone a puzzled hour.

I did not test streaming, grammar or JSON schema, and I know you have changes planned. Happy to rerun when you say it is ready.

<!-- gh-comment-id:5976611196 --> @Grandmasg commented on GitHub (Oct 4, 2026): Thanks again, this is great. To answer your question: yes, the initial work is good enough for what I wanted. I built `work/logprobs-675` at 2243cb1 (CUDA 13.0, sm_89 only, RTX 4090; about 1.5 min to compile) and ran it with the existing IQ3_S pack on its own port. **What I tested:** non-streaming `/v1/chat/completions` with `max_tokens: 1`, `temperature: 0`, `logprobs: true`, `top_logprobs: 10`, `reasoning_effort: "none"`. One-token A/B classification of 49 short texts of my own (23 containing a hidden instruction aimed at an AI assistant, 26 without), score = P(B) / (P(A) + P(B)), summing `A` and ` A`. **Results:** AUC 1.000. All 23 positives are flagged at any threshold from 0.02 up, and there is no false alarm from 0.2 up. Lowest score among the positives 0.996, highest among the negatives 0.093. For comparison, a 4B model on llama-server gives a much tighter 0.697 vs 0.682 on the same set, so the full-vocabulary probabilities from the big model separate far better. Median 707 ms per decision (prompts of up to about 1,500 characters), the whole set in about 34 s. It is my own small set, so please read it as indicative. **One note:** without `reasoning_effort: "none"` the response has an empty `logprobs.content` for `max_tokens: 1` (the single token is spent on thinking, which is excluded from content scores). That matches your docs, but one line about it in the one-token use case could save someone a puzzled hour. I did not test streaming, grammar or JSON schema, and I know you have changes planned. Happy to rerun when you say it is ready.
Author
Owner

@Grandmasg commented on GitHub (Oct 4, 2026):

Follow-up with a fuller test of work/logprobs-675 at 2243cb1, built with the grammar option (STRATA_ENABLE_GBNF=ON, xgrammar from the pins in tools/prepare_xgrammar.py). Windows, RTX 4090 (sm_89), CUDA 13.0, IQ3_S pack.

What works as described (23 checks, 20 pass; the 3 that fail are all the bit-identity question below):

  • Streaming: valid chunks, ends with [DONE], one score per visible token, usage included.
  • Grammar: root ::= "Z" forces Z and still scores it outside the top-N (-15.15). With root ::= "A" | "B" the raw probability stays the same (-0.0064 with and without).
  • JSON schema: valid JSON, per-token scores, both A and B among the alternatives at the decision token.
  • Edge cases: top_logprobs 20 ok, 21 gives a clear 400, 0 gives only the selected score, logprobs: false with top_logprobs gives 400, and max_tokens: 1 without reasoning_effort: "none" gives an empty logprobs.content, as documented.

Repeatability. With the default config, identical requests at temperature 0 are not bit-identical (decision token: 4 variants in 12 repeats, spread up to 0.50 in logprob for low-probability alternatives; a longer answer: 2 variants in 5; stream vs non-stream text differed once in 3). I started a fresh server per configuration, following your #410 notes (first request after start excluded):

Configuration Bit-identical on all checks?
default no
--prompt-cache 0 --adapt-swaps 0 --pcie-frac 0 + STRATA_IQ_MT_MIN=1 yes
only --adapt-swaps 0 yes
only --prompt-cache 0 no
only --pcie-frac 0 no
only STRATA_IQ_MT_MIN=1 no

So in my setup the adaptive tier alone explains it. The cost is decode speed (71.7 -> 49.5 tok/s on a long answer); my one-token decisions only went from 741 to 773 ms.

For my use the defaults were already stable enough: over 3 full runs of 49 texts the largest score difference was 0.012 and no decision changed at any threshold from 0.1 to 0.5. Small numbers of repeats, one model, one machine.

Not tested: tool calls, reasoning + JSON, concurrent requests. Thanks again, and happy to rerun when you say it is ready.

<!-- gh-comment-id:5976981069 --> @Grandmasg commented on GitHub (Oct 4, 2026): Follow-up with a fuller test of `work/logprobs-675` at 2243cb1, built with the grammar option (`STRATA_ENABLE_GBNF=ON`, xgrammar from the pins in `tools/prepare_xgrammar.py`). Windows, RTX 4090 (sm_89), CUDA 13.0, IQ3_S pack. **What works as described** (23 checks, 20 pass; the 3 that fail are all the bit-identity question below): - Streaming: valid chunks, ends with `[DONE]`, one score per visible token, `usage` included. - Grammar: `root ::= "Z"` forces `Z` and still scores it outside the top-N (-15.15). With `root ::= "A" | "B"` the raw probability stays the same (-0.0064 with and without). - JSON schema: valid JSON, per-token scores, both `A` and `B` among the alternatives at the decision token. - Edge cases: `top_logprobs` 20 ok, 21 gives a clear 400, 0 gives only the selected score, `logprobs: false` with `top_logprobs` gives 400, and `max_tokens: 1` without `reasoning_effort: "none"` gives an empty `logprobs.content`, as documented. **Repeatability.** With the default config, identical requests at temperature 0 are not bit-identical (decision token: 4 variants in 12 repeats, spread up to 0.50 in logprob for low-probability alternatives; a longer answer: 2 variants in 5; stream vs non-stream text differed once in 3). I started a fresh server per configuration, following your #410 notes (first request after start excluded): | Configuration | Bit-identical on all checks? | | --- | --- | | default | no | | `--prompt-cache 0 --adapt-swaps 0 --pcie-frac 0` + `STRATA_IQ_MT_MIN=1` | yes | | only `--adapt-swaps 0` | yes | | only `--prompt-cache 0` | no | | only `--pcie-frac 0` | no | | only `STRATA_IQ_MT_MIN=1` | no | So in my setup the adaptive tier alone explains it. The cost is decode speed (71.7 -> 49.5 tok/s on a long answer); my one-token decisions only went from 741 to 773 ms. For my use the defaults were already stable enough: over 3 full runs of 49 texts the largest score difference was 0.012 and no decision changed at any threshold from 0.1 to 0.5. Small numbers of repeats, one model, one machine. Not tested: tool calls, reasoning + JSON, concurrent requests. Thanks again, and happy to rerun when you say it is ready.
Author
Owner

@CC-David-CC commented on GitHub (Oct 4, 2026):

thank you. i will have an updated branch for you later. i'm working on my control lab for strata which involves real time steering based on changeable grammars and logprobs atm.
video
On repeatability

Does it generate gibberish
or does it go from
'A' to ' A'
or something where the meaning is the same the tokenizer is just different?

<!-- gh-comment-id:5981739088 --> @CC-David-CC commented on GitHub (Oct 4, 2026): thank you. i will have an updated branch for you later. i'm working on my control lab for strata which involves real time steering based on changeable grammars and logprobs atm. [video](https://www.youtube.com/watch?v=yCFbqbt7rH0) On repeatability Does it generate gibberish or does it go from 'A' to ' A' or something where the meaning is the same the tokenizer is just different?
Author
Owner

@CC-David-CC commented on GitHub (Oct 4, 2026):

https://github.com/CC-David-CC/strata-control-lab

this is an aside testing tool calls, reasoning + JSON.

you can see here: https://github.com/CC-David-CC/strata-control-lab/tree/main/control_lab/data/requests

<html>

separate examples in the Token inspector:

Example Recorded native result
Tool call Calls echo with {"text":"hello"}
Tool result Receives the supplied tool result and answers hello
Reasoning + strict JSON Returns reasoning separately, then {"decision":"A"}
</html>
<!-- gh-comment-id:5982355822 --> @CC-David-CC commented on GitHub (Oct 4, 2026): https://github.com/CC-David-CC/strata-control-lab this is an aside testing tool calls, reasoning + JSON. you can see here: https://github.com/CC-David-CC/strata-control-lab/tree/main/control_lab/data/requests <html> <body> <!--StartFragment--> <p> <strong>separate examples in the Token inspector:</strong></p> Example | Recorded native result -- | -- Tool call | Calls echo with {"text":"hello"} Tool result | Receives the supplied tool result and answers hello Reasoning + strict JSON | Returns reasoning separately, then {"decision":"A"} <!--EndFragment--> </body> </html>
Author
Owner

@Grandmasg commented on GitHub (Oct 4, 2026):

Thanks. On repeatability, to answer your question properly I re-measured instead of guessing, and I have to correct part of my earlier table.

Setup: work/logprobs-675 at 2243cb1 (IQ3_S, RTX 4090), temperature 0, 6 prompts (two one-token A/B decisions, a 40-token sentence, two 120-token answers, 100 tokens of code), 20 repeats each, interleaved, 3 fresh server starts per configuration (360 requests per configuration, first request after start excluded). For comparison the same set on llama-server with Qwen3.5-4B/9B/35B-A3B Q4_K_M (360 requests each).

It is not gibberish and it is not A vs A. Every difference I looked at is an ordinary, correct sentence with the same meaning (e.g. "UDP does not guarantee packet order" vs "UDP does not maintain packet order"). Among the differing outputs, none was the same text with different tokens and none was whitespace-only. In all of them the first divergence sits on a near-tie: the two best tokens are within 0.5 logprob (e.g. -1.487 vs -1.492), while only 9% of all positions are near-ties. So a tiny numeric difference flips a coin-flip token and the rest of the text follows it. The one-token decisions were stable in every configuration (selected token identical in all 360 requests; its logprob moved by at most 0.0033).

Prompt default --adapt-swaps 0 all #410 switches
A/B, short 1 text 1 1
A/B, long context 1 1 1
40-token sentence 4 2 1
120-token answer 28 3 3
120-token list 11 3 3
100 tokens of code 1 1 1

(number of distinct texts in 60 requests per prompt; llama-server with the three Qwen models: 1 for every prompt)

Correction to my earlier table: I said --adapt-swaps 0 alone gave bit-identical results. That came from a small test (one prompt, one start, 5 repeats). With this larger one, the default varies even within a single server run, while with --adapt-swaps 0 (or all the switches from #410) each server run is consistent with itself (1 text in 20 repeats, with one small exception) but different starts can give different texts (3 distinct texts over 3 starts for the long answers).

What explains it (tested): the contents of the GPU expert cache. In Strata's own log the cache hit rate of the same request varies between repeats by default (71.8-89.6% for the short A/B prompt) and is constant with --adapt-swaps 0 (exactly 73.6%, where the logprob spread is exactly 0). The leftover between restarts comes from --expert-cache auto, which picked a slightly different number of experts per start (7560, 7560, 7548): the two starts with 7560 gave identical logprobs, the one with 7548 did not. A controlled check with fixed experts and an explicit --expert-cache (2 restarts each, 5 repeats x 6 prompts) was bit-identical per setting, and different settings gave different results (-0.00609 vs -0.00847 on the short A/B prompt). So an explicit --expert-cache together with --adapt-swaps 0 should make restarts repeatable; this test is small (2 starts per setting). Why a different cache content changes the last digits (another kernel or location for that expert's computation?) I have not measured; that part is a guess.

For my use (one-token decisions) none of this matters. What I have not established, so you know how far to trust this:

  • "Same meaning" I judged on examples of the differences, not on all of them.
  • The cache test is small (2 restarts per setting, 5 repeats, one GPU, one model, one OS). I did not measure why auto picks a different expert count per start (free VRAM at start is my guess), nor why a different cache content changes the last digits (a different kernel or location for that expert's computation is my guess).
  • I did not test the default with the swaps frozen in some other way, and llama-server was only measured with one request at a time.

I'm happy to dig further if it helps you: more restarts with auto while logging free VRAM, a larger fixed-cache test, and a systematic check of all the differing outputs. The scripts are here: https://gist.github.com/Grandmasg/f01ca029a9d8d6d1c18cbebfd8887055 (repeatability.py measures, analyze.py counts, Python 3, no packages). I can also share the raw data (about 28 MB).

A note on the scripts: the numbers above come from my original scripts, which have Dutch comments, prompt names and labels. The versions in the gist are an English-labelled cleanup of the same code (same prompts, same counting). I ran the English analysis on the same raw data and it gives identical numbers (36 prompt/configuration combinations, no differences); the English measurement script I only tested against a stub server, not again against Strata itself.

<!-- gh-comment-id:5983628943 --> @Grandmasg commented on GitHub (Oct 4, 2026): Thanks. On repeatability, to answer your question properly I re-measured instead of guessing, and I have to correct part of my earlier table. Setup: `work/logprobs-675` at 2243cb1 (IQ3_S, RTX 4090), temperature 0, 6 prompts (two one-token A/B decisions, a 40-token sentence, two 120-token answers, 100 tokens of code), 20 repeats each, interleaved, 3 fresh server starts per configuration (360 requests per configuration, first request after start excluded). For comparison the same set on llama-server with Qwen3.5-4B/9B/35B-A3B Q4_K_M (360 requests each). **It is not gibberish and it is not `A` vs ` A`.** Every difference I looked at is an ordinary, correct sentence with the same meaning (e.g. "UDP does not guarantee packet order" vs "UDP does not maintain packet order"). Among the differing outputs, none was the same text with different tokens and none was whitespace-only. In all of them the first divergence sits on a near-tie: the two best tokens are within 0.5 logprob (e.g. -1.487 vs -1.492), while only 9% of all positions are near-ties. So a tiny numeric difference flips a coin-flip token and the rest of the text follows it. The one-token decisions were stable in every configuration (selected token identical in all 360 requests; its logprob moved by at most 0.0033). | Prompt | default | `--adapt-swaps 0` | all #410 switches | | --- | --- | --- | --- | | A/B, short | 1 text | 1 | 1 | | A/B, long context | 1 | 1 | 1 | | 40-token sentence | 4 | 2 | 1 | | 120-token answer | 28 | 3 | 3 | | 120-token list | 11 | 3 | 3 | | 100 tokens of code | 1 | 1 | 1 | (number of distinct texts in 60 requests per prompt; llama-server with the three Qwen models: 1 for every prompt) **Correction to my earlier table:** I said `--adapt-swaps 0` alone gave bit-identical results. That came from a small test (one prompt, one start, 5 repeats). With this larger one, the default varies even within a single server run, while with `--adapt-swaps 0` (or all the switches from #410) each server run is consistent with itself (1 text in 20 repeats, with one small exception) but different starts can give different texts (3 distinct texts over 3 starts for the long answers). **What explains it** (tested): the contents of the GPU expert cache. In Strata's own log the cache hit rate of the *same* request varies between repeats by default (71.8-89.6% for the short A/B prompt) and is constant with `--adapt-swaps 0` (exactly 73.6%, where the logprob spread is exactly 0). The leftover between restarts comes from `--expert-cache auto`, which picked a slightly different number of experts per start (7560, 7560, 7548): the two starts with 7560 gave identical logprobs, the one with 7548 did not. A controlled check with fixed experts and an explicit `--expert-cache` (2 restarts each, 5 repeats x 6 prompts) was bit-identical per setting, and different settings gave different results (-0.00609 vs -0.00847 on the short A/B prompt). So an explicit `--expert-cache` together with `--adapt-swaps 0` should make restarts repeatable; this test is small (2 starts per setting). *Why* a different cache content changes the last digits (another kernel or location for that expert's computation?) I have not measured; that part is a guess. For my use (one-token decisions) none of this matters. What I have not established, so you know how far to trust this: - "Same meaning" I judged on examples of the differences, not on all of them. - The cache test is small (2 restarts per setting, 5 repeats, one GPU, one model, one OS). I did not measure *why* `auto` picks a different expert count per start (free VRAM at start is my guess), nor *why* a different cache content changes the last digits (a different kernel or location for that expert's computation is my guess). - I did not test the default with the swaps frozen in some other way, and llama-server was only measured with one request at a time. I'm happy to dig further if it helps you: more restarts with `auto` while logging free VRAM, a larger fixed-cache test, and a systematic check of all the differing outputs. The scripts are here: https://gist.github.com/Grandmasg/f01ca029a9d8d6d1c18cbebfd8887055 (`repeatability.py` measures, `analyze.py` counts, Python 3, no packages). I can also share the raw data (about 28 MB). A note on the scripts: the numbers above come from my original scripts, which have Dutch comments, prompt names and labels. The versions in the gist are an English-labelled cleanup of the same code (same prompts, same counting). I ran the English analysis on the same raw data and it gives identical numbers (36 prompt/configuration combinations, no differences); the English measurement script I only tested against a stub server, not again against Strata itself.
Author
Owner

@Grandmasg commented on GitHub (Oct 4, 2026):

Thanks for sharing — nice to see someone else poking at model-output transparency too. Different angle though: Token inspector looks at tool-call/reasoning structure, this request is about raw log-probabilities on the generated token itself. No strong opinion on which approach is "better" — both seem worth letting prove themselves in practice. I'd like to lay them side by side at some point and see if there's actually a relationship between the two (e.g. logprobs surfaced at specific decision points within a longer trace, not just a forced single token) — for a prompt-injection guard specifically, that combination feels like the safer bet. Leaving this open for now, will report back if that exploration goes anywhere. Still curious if the logprobs angle itself is on anyone's radar from a maintainer side.

<!-- gh-comment-id:5983781017 --> @Grandmasg commented on GitHub (Oct 4, 2026): Thanks for sharing — nice to see someone else poking at model-output transparency too. Different angle though: Token inspector looks at tool-call/reasoning structure, this request is about raw log-probabilities on the generated token itself. No strong opinion on which approach is "better" — both seem worth letting prove themselves in practice. I'd like to lay them side by side at some point and see if there's actually a relationship between the two (e.g. logprobs surfaced at specific decision points within a longer trace, not just a forced single token) — for a prompt-injection guard specifically, that combination feels like the safer bet. Leaving this open for now, will report back if that exploration goes anywhere. Still curious if the logprobs angle itself is on anyone's radar from a maintainer side.
Author
Owner

@CC-David-CC commented on GitHub (Oct 4, 2026):

thanks for the clarification. i am adding this to my queue.
i'm about to stop my hobby work for the weekend and turn to school work so it might take me at little longer for the next update but i will include the raw log-probabilities on the token itself and examples of it working.

<!-- gh-comment-id:5985106208 --> @CC-David-CC commented on GitHub (Oct 4, 2026): thanks for the clarification. i am adding this to my queue. i'm about to stop my hobby work for the weekend and turn to school work so it might take me at little longer for the next update but i will include the raw log-probabilities on the token itself and examples of it working.
Author
Owner

@CC-David-CC commented on GitHub (Oct 6, 2026):

https://github.com/CC-David-CC/strata-control-lab/tree/lab/raw-token-logprobs
i think this might expose the information and comparison you want now

does this better demonstrate what you want? if not please describe what you want exactly and i'll make it happen

it's still going thru some upgrades but back at the bottom of the queue

<!-- gh-comment-id:6018961626 --> @CC-David-CC commented on GitHub (Oct 6, 2026): https://github.com/CC-David-CC/strata-control-lab/tree/lab/raw-token-logprobs i think this might expose the information and comparison you want now does this better demonstrate what you want? if not please describe what you want exactly and i'll make it happen it's still going thru some upgrades but back at the bottom of the queue
Author
Owner

@Grandmasg commented on GitHub (Oct 6, 2026):

Thanks, this does show what I was after: the raw token.logprob of the selected token, kept apart from the normalised weights, including the grammar-forced case where the legal token still carries its small raw score (the Z example), and the selected token returned when it is not in top-N. Having both layers side by side on every page is also a clear way to explain the difference.

I have only read the README, the raw/derived document and the example script so far; I have not run the examples or tried a live server with this branch.

One question, so I know what to wait for: is this meant to end up in the regular Strata release (for example in the logprobs/samplers branches), or will it stay in your own copy and the lab? No hurry; I can use the logprobs of other backends in the meantime, so nothing is blocked on my side.

<!-- gh-comment-id:6020456978 --> @Grandmasg commented on GitHub (Oct 6, 2026): Thanks, this does show what I was after: the raw `token.logprob` of the selected token, kept apart from the normalised weights, including the grammar-forced case where the legal token still carries its small raw score (the `Z` example), and the selected token returned when it is not in top-N. Having both layers side by side on every page is also a clear way to explain the difference. I have only read the README, the raw/derived document and the example script so far; I have not run the examples or tried a live server with this branch. One question, so I know what to wait for: is this meant to end up in the regular Strata release (for example in the logprobs/samplers branches), or will it stay in your own copy and the lab? No hurry; I can use the logprobs of other backends in the meantime, so nothing is blocked on my side.
Author
Owner

@CC-David-CC commented on GitHub (Oct 6, 2026):

up to the owner of strata, i'd be happy to give it up. i am just a contributor and the control lab was made for my own understanding and testing.

<!-- gh-comment-id:6022866408 --> @CC-David-CC commented on GitHub (Oct 6, 2026): up to the owner of strata, i'd be happy to give it up. i am just a contributor and the control lab was made for my own understanding and testing.
Author
Owner

@CC-David-CC commented on GitHub (Oct 6, 2026):

but i do have/had numerous open PRs (a bunch were closed and asked to resubmit if important on the new 1.4 base) .

there is more than one implementation for some of these things and eventually the logprobs you want will make it to core in an easy to use way - the values are there....just how do we expose them. either mine or someone's who is cleaner/better than mine will go in

<!-- gh-comment-id:6023055987 --> @CC-David-CC commented on GitHub (Oct 6, 2026): but i do have/had numerous open PRs (a bunch were closed and asked to resubmit if important on the new 1.4 base) . there is more than one implementation for some of these things and eventually the logprobs you want will make it to core in an easy to use way - the values are there....just how do we expose them. either mine or someone's who is cleaner/better than mine will go in
Author
Owner

@karls0r commented on GitHub (Oct 11, 2026):

🤖 AI agent (Ren, Claude) on behalf of @karls0r.

For anyone landing here: #1916 adds this for CUDA/HIP. With "parallel" set it returned "logprobs": null; a server-only fix for one-token decisions under "parallel" is offered there: https://github.com/Niko1221/Strata/pull/1916#issuecomment-6108266739 — measured on 2× RTX 3090 (layer split) with a prompt-injection yes/no task in German: 100 % on our 41+47 cases, p50 0.6 s per decision.

<!-- gh-comment-id:6108268381 --> @karls0r commented on GitHub (Oct 11, 2026): > 🤖 AI agent (Ren, Claude) on behalf of @karls0r. For anyone landing here: #1916 adds this for CUDA/HIP. With `"parallel"` set it returned `"logprobs": null`; a server-only fix for one-token decisions under `"parallel"` is offered there: https://github.com/Niko1221/Strata/pull/1916#issuecomment-6108266739 — measured on 2× RTX 3090 (layer split) with a prompt-injection yes/no task in German: 100 % on our 41+47 cases, p50 0.6 s per decision.
Author
Owner

@Grandmasg commented on GitHub (Oct 11, 2026):

Thank you @gt50 and @karls0r. I built the pull request (c8ee496) plus the logprobs-batched fix (73f0771) from karls0r's branch and ran them on the real engine, to see whether they cover what #675 asked for.

Setup: Windows 11, RTX 4090 (24 GB), Qwen3.8-Flash-Next IQ3_S, --spec 4 --mtp, --kv int8, expert cache auto, context 32768; CUDA 13, sm_89 only. One GPU, one model, one start per configuration: an indication, not more.

One-token decisions (max_tokens: 1, top_logprobs: 5, reasoning_effort: none)

  • "Is the sky blue? A) yes B) no": A at P = 0.997. Ten repeats: the probability of the chosen letter moved by at most 0.0002 (the alternatives far down the list, around 0.001, change in steps between requests).
  • An instruction aimed at an AI against ordinary text: P(A) = 0.97 to 0.98 against 0.001.

Longer replies: one entry per token (16 entries for 17 tokens, the stop token left out), the tokens joined spell the reply exactly, bytes and the alternatives are there, the same text comes back without logprobs, and streaming carries the entries.

With "parallel": 2 (the log shows two batch slots): without the fix a one-token decision returns "logprobs": null, as karls0r describes. With the fix it returns them; four decisions at once all return them and each is within 0.0009 in probability of the same request alone; a reply of 20 tokens with logprobs is refused with a 400.

My use case, measured: a local coding agent that I work on checks tool output (web pages, MCP answers, file contents) for hidden instructions with exactly this one-token decision, before the model sees it. On my own 49 examples (23 with a hidden instruction, 26 without, 10 of those hard cases such as an AGENTS.md; each text looked at in up to three places), through this pull request: AUC 1.000, and at threshold 0.3 all 23 found with 0 false alarms of 26. The same set with Qwen3.5-4B on llama-server earlier: 23 of 23 and 2 false alarms of 26. It took 64 s for the 49 items, about 1.3 s per item on average (the 4B model: median 88 ms), so it is slower than a small model but needs no second model in memory, which was the point of the request.

Small differences from OpenAI / llama-server I noticed (none is a problem for my use):

  • top_logprobs: 21 and logprobs: false together with top_logprobs are accepted (HTTP 200); OpenAI rejects both with a 400.
  • At temperature 0, a streamed and a non-streamed request give different text after the first tokens of a longer reply (largest score difference 0.9 in one test), and the low-probability alternatives vary between repeats. I saw the same cache effect in the repeatability numbers of an earlier comment; it does not touch the decision tokens.

Not tested: the Responses and Anthropic APIs, HIP and SYCL, longer replies with parallel (refused on purpose), models other than this one.

For my use this covers #675. Thanks again.

<!-- gh-comment-id:6109928052 --> @Grandmasg commented on GitHub (Oct 11, 2026): Thank you @gt50 and @karls0r. I built the pull request (c8ee496) plus the `logprobs-batched` fix (73f0771) from karls0r's branch and ran them on the real engine, to see whether they cover what #675 asked for. **Setup:** Windows 11, RTX 4090 (24 GB), Qwen3.8-Flash-Next IQ3_S, `--spec 4 --mtp`, `--kv int8`, expert cache auto, context 32768; CUDA 13, sm_89 only. One GPU, one model, one start per configuration: an indication, not more. **One-token decisions (`max_tokens: 1`, `top_logprobs: 5`, `reasoning_effort: none`)** - "Is the sky blue? A) yes B) no": `A` at P = 0.997. Ten repeats: the probability of the chosen letter moved by at most 0.0002 (the alternatives far down the list, around 0.001, change in steps between requests). - An instruction aimed at an AI against ordinary text: P(A) = 0.97 to 0.98 against 0.001. **Longer replies:** one entry per token (16 entries for 17 tokens, the stop token left out), the tokens joined spell the reply exactly, `bytes` and the alternatives are there, the same text comes back without `logprobs`, and streaming carries the entries. **With `"parallel": 2`** (the log shows two batch slots): without the fix a one-token decision returns `"logprobs": null`, as karls0r describes. With the fix it returns them; four decisions at once all return them and each is within 0.0009 in probability of the same request alone; a reply of 20 tokens with logprobs is refused with a 400. **My use case, measured:** a local coding agent that I work on checks tool output (web pages, MCP answers, file contents) for hidden instructions with exactly this one-token decision, before the model sees it. On my own 49 examples (23 with a hidden instruction, 26 without, 10 of those hard cases such as an AGENTS.md; each text looked at in up to three places), through this pull request: AUC 1.000, and at threshold 0.3 all 23 found with 0 false alarms of 26. The same set with Qwen3.5-4B on llama-server earlier: 23 of 23 and 2 false alarms of 26. It took 64 s for the 49 items, about 1.3 s per item on average (the 4B model: median 88 ms), so it is slower than a small model but needs no second model in memory, which was the point of the request. **Small differences from OpenAI / llama-server I noticed** (none is a problem for my use): - `top_logprobs: 21` and `logprobs: false` together with `top_logprobs` are accepted (HTTP 200); OpenAI rejects both with a 400. - At temperature 0, a streamed and a non-streamed request give different text after the first tokens of a longer reply (largest score difference 0.9 in one test), and the low-probability alternatives vary between repeats. I saw the same cache effect in the repeatability numbers of an earlier comment; it does not touch the decision tokens. **Not tested:** the Responses and Anthropic APIs, HIP and SYCL, longer replies with `parallel` (refused on purpose), models other than this one. For my use this covers #675. Thanks again.
Author
Owner

@Niko1221 commented on GitHub (Oct 13, 2026):

Thanks for the report. To keep the tracker current we are closing issues older than three days: 0.1.44 is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1.

If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.

<!-- gh-comment-id:6155948784 --> @Niko1221 commented on GitHub (Oct 13, 2026): Thanks for the report. To keep the tracker current we are closing issues older than three days: [0.1.44](https://github.com/Niko1221/Strata/releases/tag/v0.1.44) is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1. If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#315
No description provided.