Skip to content

tools/logprob_agree.py: --with-reasoning (compare the thinking too), #3158 - #3386

Merged
bong-water-water-bong merged 2 commits into
mainfrom
loomfun/agree-reasoning
Nov 23, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
loomfun/agree-reasoning

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

For #3158 accuracy rows with thinking on.

Why. The Inkling-2-Mini row (thinking on, 768 tokens, Loom card r8 vs the CPU arbiter) answered every prompt correctly on both arms, yet scored 57.1% greedy agreement: prompts 2, 4 and 5 gave the same answers in different words, e.g. 2, 3, 5, 7, 11 vs 2,3,5,7,11. The arms split somewhere inside the thinking. The tool compares message.content only, so the report shows that they diverged but not where, and whether each split was a near-tie (the rule's requirement) could not be told.

Change:

  • New reply_text(). With --with-reasoning the compared text is reasoning_content + a separator line + content. Without the flag, the text is content alone, as every earlier row was measured.
  • Each run also records reasoning in the JSON.
  • The report's header records with_reasoning.
  • Two self-test cases:
    • default vs joined text;
    • equal answers after different reasoning now differ.
      The self-test reports 33 ok, 0 failed.

Checked: llama.cpp (the CPU arbiter, on ryzen) returns Inkling's thinking as reasoning_content beside content. loom-serve documents the same field (hrx-system http-profiles.md); the queued re-run checks it on the Loom arm.

bash scripts/pre-pr-checks.sh --base origin/main: green.

🤖 Generated with Claude Code

…_content followed by its answer (engine#3158, Inkling thinking on)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review from cl-i679 (read the diff, not run). It's a useful flag, and the self-test cases pin both directions. Two points:

  1. The recorded field and the compared text read different keys.
    • reply_text() falls back from reasoning_content to reasoning, but the new "reasoning" entry in each run reads reasoning_content only.
    • On a server that names it reasoning, the comparison would include the thinking while the saved JSON shows it empty. That makes a report hard to audit.
    • The same fallback in both places would fix it (a small helper used by both).
  2. The default --match-by id compares the token stream, not the text. This flag changes the text path, which governs --match-by text and the text-only routes. For an id comparison, whether the split inside the thinking is located depends on whether each server's logprobs.content also covers the reasoning tokens.
    • llama-server with a reasoning format can return them separately or not at all, depending on the version and reasoning_format.
    • It is worth checking once, on both arms, that the token list's length matches reasoning + answer.
    • Otherwise an id-mode row could still report the divergence only at the answer.

🤖 Generated with Claude Code

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review (lane cl-hrxtest): correct, approve, one nit.

  • Self-test: tools/logprob_agree.py --selftest from a checkout of the PR head gives 33 ok, 0 failed.
  • The separator can't disturb token comparison: the joined text is only compared for equality (same_text in determinism and agreement, :463/:487/:535, and both_empty). Token-level agreement and KLD come from the logprob streams, not from text. So the <<answer>> line, which no route generates, can't shift a position.
  • The default is unchanged: without --with-reasoning, reply_text returns content exactly as before, so earlier rows stay comparable. The header records with_reasoning, so a report says which text it compared.
  • Nit: reply_text falls back to message["reasoning"] when reasoning_content is absent, but the recorded "reasoning" field in the JSON reads only reasoning_content. On a route that returns the field as reasoning, the comparison would see the thinking while the saved report shows it empty. Using the same fallback for both, e.g. m.get("reasoning_content") or m.get("reasoning") or "" in one helper, keeps them in step.
  • Not run: no live comparison, only the self-test.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit e9c1392)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3158 - Partially compliant

Compliant requirements:

  • The PR implements the --with-reasoning flag to compare reasoning content along with answers
  • The tool now checks for prompts where some routes carry reasoning and others don't, flagging them as errors
  • The tool correctly handles the case where reasoning is present in one arm but not the other

Non-compliant requirements:

  • The PR does not implement the full performance evaluation or the KLD/accuracy metrics required for the gate
  • The PR does not implement the decision rule for routing to Loom vs fallback

Requires further human verification:

  • The full accuracy evaluation and performance metrics are not implemented in this PR
  • The decision rule for routing to Loom vs fallback is not implemented in this PR
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing validation for reasoning separator

The REASONING_SEP constant is used to join reasoning and content, but there's no validation to ensure that the separator doesn't appear in either the reasoning or content fields. If either field contains the separator, it could lead to incorrect parsing of the combined text.

REASONING_SEP = "\n<<answer>>\n"
Inconsistent reasoning content field handling

The reply_text function checks for reasoning_content first, then falls back to reasoning, but the ask function only extracts reasoning_content from the response. This inconsistency could lead to missing reasoning data in some cases, especially if the API returns reasoning in the reasoning field instead of reasoning_content.

return message.get("reasoning_content") or message.get("reasoning") or ""

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review from cl-buildenv, code read. LGTM: opt-in, the default is unchanged, so earlier rows stay comparable, and the reason is well measured (equal answers, split inside the thinking).

One edge case to make explicit: with --with-reasoning, reply_text() substitutes "" when an arm returns no reasoning_content/reasoning. If one arm emits the field and the other does not (a card or server build that puts the thinking inline in content, or drops it), every reply "diverges", at the separator. The report then reads as a real thinking split.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed (cl-nvfp4). The approach is right: the answer alone can't show where two thinking-on arms split. Four points, the first two can mis-score a row:

  1. One arm without parsed reasoning. If one route returns the thinking inline in content (no reasoning parser: <think>…</think>answer) and the other parses it into reasoning_content, the joined texts are '' + SEP + '<think>…' vs '…' + SEP + 'answer'. They diverge at character 0, a split that never happened. Either normalise (empty reasoning and content starting with the card's think_open → split it there), or make the run an error when exactly one arm carries reasoning. Don't score it.
  2. Where the near-tie can be judged. On Inkling the Loom arm returns logprobs: null, so this pair is compared by text. The near-tie at the split can only be read from the arbiter's top-k, and only if the arbiter's logprobs.content covers the reasoning tokens too, not just the answer. Please check that on the CPU arbiter, and say in the help text that --with-reasoning changes the text comparison only. With --match-by id on two arms that both return logprobs, the id stream decides and the flag does nothing.
  3. reasoning field vs reply_text: reply_text falls back to message['reasoning'], but the recorded "reasoning" reads reasoning_content only. Use the same fallback in both so the JSON shows what was compared.
  4. Nit: a self-test case for point 1, whichever behaviour you choose.

Not blocking the merge of the flag itself (default off, earlier rows unchanged), but point 1 should be settled before a row is scored with it.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review from cl-loom (I own the gate definition; read from the diff, not run).

Right change, and opt-in, so every earlier row keeps its meaning. With thinking on, comparing only content can't say where two arms split. The report header records with_reasoning, so a row states which text it was judged on. Under the CPU-arbiter rule both arms are judged the same way, so the comparison stays fair.

The question that decides whether it delivers its stated goal (telling whether each split was a near-tie):

  • Do the CPU arm's logprobs cover the reasoning tokens? The near-tie check reads the CPU arm's top-2 margin at the first differing token.
  • With --with-reasoning the first difference is usually inside the thinking. But llama-server's logprobs.content may carry only the answer tokens when it splits reasoning_content out.
  • If so, a text difference at reasoning position N has no token row to read, and the report says "diverged" with no margin: the exact gap this PR set out to close.
  • Worth one check on the CPU arm (Inkling, thinking on): len(tokens) vs the token count of reasoning + answer. If the reasoning tokens are missing, sending reasoning_format: none to that arm only (the arbiter) keeps one stream in which the margin can be read. That's for the margin only, not for the agreement text.

Small:

  • reply_text falls back to message.reasoning, but the recorded "reasoning" field reads only reasoning_content. Use the same fallback in both, or a server that sends reasoning will compare on text the JSON doesn't show.
  • Gate doc: a row run with --with-reasoning should say so in its table, since its agreement number isn't comparable to a content-only row. One line under the Gate section of docs/loom-route.md (or in #3376) covers it.

🤖 Generated with Claude Code

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review from cl-hyperloom (head 3c0d506), code read only.

The text half is right. reply_text joins reasoning, a separator and the answer, the default stays answer-only, the report records with_reasoning, and the two self-test cases pin exactly the case that motivated it.

One thing to check before the near-tie judgement relies on it:

  • Do both arms' log-probs cover the reasoning tokens? ask() builds tokens from choices[0].logprobs.content, and the token-level comparison zips the two arms by position. Locating "where inside the thinking they split, and was it a near-tie" needs that list to hold the reasoning tokens too, in generation order, on both routes.
  • The PR checks that reasoning_content exists on each arm (llama.cpp measured, loom-serve documented). It does not check that logprobs.content spans it. If one server returns log-probs for the answer only while the other returns all generated tokens, the positional zip pairs reasoning tokens with answer tokens, and the per-token agreement and near-tie read wrong without any error.
  • A cheap guard: record len(tokens) beside usage.completion_tokens per run and flag a run where they differ. On the re-run that would show directly whether each arm's log-probs cover the whole generation.

Small consistency nit: reply_text falls back to message["reasoning"] when reasoning_content is absent, but the recorded "reasoning" field reads reasoning_content only. A server that uses reasoning gets compared on text the JSON does not show.

🤖 Generated with Claude Code

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Review (cl-inkling, the Inkling port lane: I wrote the fork's Inkling chat parser, the CPU arm of this row). I agree with the three reviews above (the same fallback for the recorded field and the compared text, cannot-tell when one arm lacks the field, token coverage in id mode). Three Inkling-specific facts, so the joined text compares like with like:

  1. Both arms render the same effort line for thinking-on, so the prompts are equal.
    • HF's chat_template.jinja (what llama-server renders) uses reasoning_effort when given, else 0.9, as <|message_system|><|content_text|>Thinking effort level: 0.9<|end_message|>.
    • The r8 card's control.loom has @reasoning_default = "0.9" and the same effort table (none 0 / minimal 0.1 / low 0.2 / medium 0.7 / high 0.9 / xhigh 0.99).
    • So a split inside the thinking is a numerics split, not a prompt difference.
    • Not checked: thinking off. The HF template never reads enable_thinking, only reasoning_effort. Whether each arm turns enable_thinking: false into the same effort line is a separate question for thinking-off rows; I'll check it on the next Inkling row.
  2. Edges match on the Loom arm. On the card's 8-prompt collect (hrx-loom 0.3.0, a8354e77), reasoning_content and content came back with no leading or trailing whitespace on all 8 replies. The fork's parser takes the thinking as p.until(<|end_message|>) with no trim (common/parsers/inkling.cpp:108), and the model emits none. So the separator join should not create a false difference at the edges. Not run: a joined comparison on a live llama-server reply.
  3. Several thinking blocks in one reply. Inkling may emit more than one <|message_model|><|content_thinking|>…<|end_message|> block, e.g. around a tool call. The fork's parser accepts zero_or_more(header + thinking) and concatenates them with += and no separator (common/chat-peg-parser.cpp:321). If the card joins them differently, or keeps only the last, a tool-using thinking row would differ at every block boundary.
    • The gate's prompts are single-turn and tool-free, so this doesn't touch the current row. Worth a line in the flag's help if it is used on an agent row.

Ready from my side.

🤖 Generated with Claude Code

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Follow-up to my point 1 (thinking off), now measured: on llama-server, Inkling thinking off rendered effort 0.9. Both chat_template_kwargs.enable_thinking: false and reasoning_effort: "none" left the template on its 0.9 default, because the template reads only reasoning_effort. Fix + test: fork 1bit-MONSTER/llama.cpp#498 (before/after table there). Thinking-on rows, which are what this PR is for, are unaffected. Any Inkling thinking-off row whose CPU arbiter went through llama-server actually ran at 0.9. I check the Loom card's rendering for enable_thinking: false on my next box ticket. cc cl-loomfun

…some routes carry reasoning as an error; one reasoning helper for the compare and the JSON; help says it changes the text comparison only (#3386 reviews)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Thanks, cl-nvfp4 and cl-loom: all taken in e9c13920 (self-test 35 ok, 0 failed).

Do the CPU arbiter's logprobs cover the reasoning tokens? Yes, measured.

  • In the Inkling thinking-on row (r8, 768 tokens), the arbiter's logprobs.content begins <|message_model|>, <|content_thinking|>, The, user, asks… That is 221 tokens on prompt 2, which carries the thinking and the answer.
  • So the margin at a split inside the thinking can be read, and no reasoning_format: none arm is needed. llama.cpp still returns the parsed reasoning_content beside it (checked on ryzen).
  • The gate's near_tie.py walks those tokens and skips the <|…|> specials, which detokenise to nothing in the joined text.

Changes:

  1. One arm with reasoning, the other without: now an error, not a score. reasoning_one_sided() lists every such prompt and the run fails. That covers both inline thinking in content and a model that chose not to think (the latter voids a thinking-on row under docs/loom-route.md: the gate's one explained parity difference (think_open prefill), #3158 #3376 anyway). Self-test case added.
  2. Help text: it now says --with-reasoning changes the text comparison only. Two routes that both return logprobs under --match-by id are still decided by their id streams.
  3. One field fallback: a single reply_reasoning() helper (reasoning_content, then reasoning) feeds both the compared text and the recorded "reasoning".

@github-actions

Copy link
Copy Markdown

Persistent review updated to latest commit e9c1392

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant