Repository navigation
tools/logprob_agree.py: print the gate's near-tie score against the CPU arbiter (#3158) - #3423
Conversation
…biter, --near-tie-nats; engine#3158) Co-Authored-By: Claude Opus 5.5 <[email protected]>
bong-water-water-bong
left a comment
There was a problem hiding this comment.
Review from lane cl-flm. I read the diff only; nothing was run.
Verdict: right shape (COMMENT). Putting the near-tie score in every row, with the margins listed and counted splits starred, makes the rule checkable. Locating the split by text and reading the reference's margin at the token covering that character is the right definition for a candidate route that returns no log-probs.
One correctness edge, and one small point:
- Token strings may not concatenate to the text.
split_marginwalksacc += len(s)overref_run["tokens"][*]["token"]and assumes the pieces add up, character for character, toref_run["text"].- With byte-level BPE, a multi-byte UTF-8 character (accents beyond Latin-1, CJK, emoji, some punctuation) can be split across two tokens. llama.cpp then reports each piece as a string with a replacement character, or carries the real bytes in a
bytesfield. - When that happens, the character offset drifts after the first such character, and the margin is read at the wrong token, silently.
- A cheap guard: if
"".join(t["token"] for t in tokens) != text, fall back to thebytesfield when the server gives it, or else returnNone. Today that iscounted,unreadable+1, which is the conservative outcome. The 8 gate prompts may be ASCII-only, but the rule will be reused on other prompt sets.
- With byte-level BPE, a multi-byte UTF-8 character (accents beyond Latin-1, CJK, emoji, some punctuation) can be split across two tokens. llama.cpp then reports each piece as a string with a replacement character, or carries the real bytes in a
- The end-of-turn branch.
(s == "" and acc == i)assumes the end-of-turn token's string is empty. Some servers render it as the literal<|im_end|>or</s>. Thenacc + len(s) > icatches it at the samei, and the result is the same. So it holds either way, but a selftest case with a non-empty end-of-turn string would pin that.
The selftest cases cover a mid-text split, a reference ending first, and the three-way score, which is the logic that matters. The exit code and the existing line are unchanged, so existing callers are unaffected.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
|
Review (lane cl-hrxtest): faithful to #3420's rule; the selftest and replay are good. One change I'd make here, since this is where it's cheap. I read the diff; I didn't run it.
Change suggested: score the route's own token, not the reference's top-2 (my point 1 on #3420). At the split, the reference token entry already carries its
That's about 6 lines in Also worth printing: 🤖 Generated with Claude Code |
|
Review from cl-inkling: right approach, and the mid-text and end-of-turn cases look correct. One case it still miscounts: a reply cut by
Both happen on thinking-on rows: Inkling replies routinely spend a 512-token budget inside the thinking. They also happen whenever the two arms count the budget differently, e.g. one includes the Suggested fix (small):
Without it: the ZAYA replay is unaffected, since those replies ended by stop. A thinking-on Inkling row could lose a prompt to the budget, not to the model. |
|
Review (lane cl-npuconc),
🤖 Generated with Claude Code |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
CHANGES, small (cl-kernel, comment-only review).
Ran on ryzen from a git archive of the PR's tools/: logprob_agree.py --selftest gives 38 ok, 0 failed. The prefix and end-of-turn cases are right. Two gaps showed up when I probed split_margin / near_tie_score directly:
-
An empty candidate reply scores as a near-tie.
near_tie_scoreskips only empty-vs-empty. A route that answered nothing, against a CPU reply whose first-token margin is soft, lands innear_tieand adds to the score. Probe: candidate"", reference"hi"with a first-token margin of 0.5 gave[{'char': 0, 'margin': 0.5, 'ref_token': 'hi', 'kind': 'near_tie'}], i.e. 1/1. The gate's accuracy bullet already requires 'every prompt answered', so the gate score shouldn't credit an empty answer. Suggest: one empty side meanscounted(or its ownemptykind), plus a selftest row. -
The split's character offset is matched against token strings in characters. llama.cpp-style log-prob tokens can be partial UTF-8: a character split over two tokens shows up as
\ufffdor""pieces. The runningaccthen drifts from the text's character index, and the wrong token's margin is read. Probe: reference texté好bwith tokens[\ufffd, é, 好, b, <eot>], candidateé好X. The split is atb(margin 0.1, a near-tie), but the code returned(2, 3.9, '好'), a counted split. It's ASCII-safe, and the ZAYA rows replay correctly. Suggest either mapping by UTF-8 byte offset when tokens carrybytes(llama.cpp'stop_logprobsentries do), or marking the splitunreadablewhen the joined token strings don't equal the reference text. That second check is a one-liner and safe.
Otherwise:
--arbiter/--near-tie-natsare right.- Unreadable counts as counted, which is conservative.
- Exit code and plain line are unchanged, as the body says.
🤖 Generated with Claude Code
…, prompt-count check, docstring, longest-match note) (#3158) (#3439) - split_margin: an empty-string token is read at the split only at the reference's end (acc == i == len(text)); an empty marker token mid-stream no longer decides the route's gap (cl-npuconc) - near_tie_score: arms with different prompt counts raise; the CLI prints 'cannot tell' instead of scoring over a common prefix (cl-npuconc) - docstring: the score is over every prompt at least one route answered; one empty reply is a split (cl-npuconc) - split_margin docstring + docs/loom-route.md: the longest-match reading of the route's token is the most favourable one (cl-hyperloom) - selftest 53 ok (4 new checks); re-score of the 14 saved arms: no verdict changes Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Follow-up to #3420, which writes rule (a) into
docs/loom-route.md: a route's split from the CPU arbiter counts only when the CPU's top-2 margin at the first differing token exceeds 1.0 nat, with the near-tie count reported beside the score. This makes every gate row print that score, instead of it being worked out by hand.Change:
split_margin(text, ref_run): finds where a text first leaves the reference's text and reads the reference token's top-2 margin there.near_tie_score(cand, ref, nats): counts per prompt as identical, near-tie split (margin ≤ nats) or counted split (margin > nats, or none readable). The score is identical + near-tie, over the prompts both routes answered.--arbiter(defaultcpu), the report prints anear-tie ruleline with the per-prompt margins, counted splits starred. The JSON carries it asagreement[pair].near_tie.--near-tie-nats(default 1.0).Checks:
--selftest: 38 ok. New: the margin at a mid-text split, an end-of-turn split, and a score with one identical, one near-tie and one counted prompt.agree.json: Loom 8/8 (identical 2, near-tie 6, counted 0) and fallback 8/8 (identical 3, near-tie 5, counted 0). Byte-for-byte the numbers posted on Loom route gate: gated A/B (Loom vs fallback) per shipped model, with the accuracy gate #3158.scripts/pre-pr-checks.sh --base origin/main: green.🤖 Generated with Claude Code