Skip to content

strip_thinking: keep the post-trace text verbatim, as oe-eval does - #363

Merged
abhishekraok merged 5 commits into
mainfrom
fix/strip-thinking-no-lstrip
Sep 11, 2026
Merged

abhishekraok merged 5 commits into
mainfrom
fix/strip-thinking-no-lstrip

Conversation

@abhishekraok

Copy link
Copy Markdown
Collaborator

Follow-up to #361, toward #348. The runner's strip did .lstrip() after removing the trace; oe-eval's r1_style processor keeps the post-</think> text byte-for-byte (and removes <answer> tags). The trim is not cosmetic for IFEval: the loose variants drop the response's first line — with the leading newline kept that line is empty, with it trimmed it's real content — and nth_paragraph_first_word indexes paragraphs before dropping empty ones.

Measured on the paper's Olmo-3-7B-Think ifeval run (Beaker results 01KAD4RGRYERJZY4SHEPXYPBX4, 541 prompts), scoring the raw outputs through the runner transform then IFEvalScorer:

transform verdict agreement with oe-eval
oe-eval's r1_style (this PR) 539/541
#361 as merged (.lstrip()) 528/541

The 12 extra disagreements all flip a loose verdict to pass (keywords:forbidden_words ×4, nth_paragraph_first_word ×3, repeat_prompt, two_responses, no_comma, number_words, keywords:frequency), so the merged behavior inflates Think-model IFEval loose scores by ~2 points relative to oe-eval. Instruct-model runs (no trace) are unaffected.

Change: strip_thinking_traces now reuses extract_think_answer, the existing regex-for-regex mirror of r1_style. Tests adapted for the preserved whitespace; two added (verbatim text, <answer> tags).

🤖 Generated with Claude Code

https://claude.ai/code/session_01LMFjgUqHjQA3aCeB4QmEHZ

The runner's strip trimmed leading whitespace after </think>, which
oe-eval's r1_style processor does not. IFEval's loose variants drop the
response's first line, and paragraph checks index on blank-line splits,
so trimming the leading newline changed verdicts: on the paper's
Olmo-3-7B-Think ifeval run, agreement with oe-eval fell from 539/541 to
528/541, with 12 rows flipping a loose verdict to pass. Reuse
extract_think_answer, which mirrors r1_style including <answer> tags.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LMFjgUqHjQA3aCeB4QmEHZ
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-09T18:54:09.764745Z 7dab7b5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@gregorybchris

Copy link
Copy Markdown
Collaborator

I realized maybe I should have run an agent review on your previous strip_thinking PR, so I did that after you merged and Claude had a pretty long writeup. The thing about BPB sounded plausible as something worth fixing. Same with the task hash.

I think you could consider these out of PR scope or pull fixes into this PR or tell me that these are not real concerns.. but wanted to add them here in case helpful.

Review of PR #361 (abhishekr/strip-thinking, +263/−4 across 6 source and 4 test files). Lint, type checks, and the touched tests all pass. Two findings are worth blocking on. The rest are worth fixing or at least discussing before merge.

Blocking

1. Every task hash changes on merge, even with the flag off. TaskConfig.to_dict() in src/olmo_eval/evals/tasks/common/base.py:296 unconditionally emits "strip_thinking": False. The task hash is computed over the full serialized dict, so pre- and post-merge runs of the same task get different hashes. That breaks pairwise dedup and best-suite intersection in analysis/pairwise.py, changes prediction filename suffixes, and invalidates saved results-viewer filters. The convention elsewhere in that function is to emit optional fields only when set. Fix: emit the key only when strip_thinking is true.
2. The strip regex is quadratic and runs on the event loop. re.sub(r"(?s).*</think>", "", text) at base.py:620 backtracks fully at each position after the last tag. Measured cost per output:

| Answer length | re.sub | rpartition |
|---------------|--------|------------|
| 5k chars      | 5 ms   | ~µs        |
| 50k chars     | 371 ms | ~µs        |
| 100k chars    | ~1.8 s | ~µs        |
   This runs synchronously inside score_and_store under the scoring semaphore, so a long-form task with many large answers stalls concurrent scoring and worker health checks. text.rpartition("</think>")[2].lstrip() is semantically identical. The same regex already exists in evals/extract/reasoning.py::extract_think_answer, so a shared helper would fix both.

Should fix

3. BPB metrics disagree with the scorer. BitsPerByteScorer now normalizes by original_text bytes, but BPBMetricByteAvg.compute and _select_gold_output in common/metrics/base.py still count the stripped text. Corpus BPB weights no longer match per-instance values, and an output that is entirely a trace becomes empty text and is silently dropped. Latent today since BPB tasks are loglikelihood-only, but the PR's own scorer test makes the combination nominally supported.
4. The vLLM reasoning-parser path is not covered. With --reasoning-parser set, the provider reads only message.content and drops reasoning_content, so no tag remains and the strip no-ops. Logprobs then span the full generation while bytes count only the answer, which is exactly the skew this PR fixes for the tag case. Pre-existing gap, but the tag-keyed design cannot cover it. Prepending reasoning_content into original_text at the provider, or a first-class reasoning field on LMOutput, would.
5. Three normalizations for logits_per_char. The prediction row in runners/io/builders.py:69 divides by original chars, the live per-char MC metric divides by stripped chars, and the offline Postgres recompute divides by the row's num_chars. The stored field no longer equals sum_logits / num_chars. Low realism, but pick one convention.
6. The strip has no single choke point, and the tested path is dead in production. It is bolted on before two score_responses call sites. The preparation.py call only runs for errored trackers, and the one runner-level test exercises only that path. A regression in the live results.py:224 path would pass CI. A Task.score() template method that strips then awaits score_responses would centralize it, with a test through process_results.

Design and cleanup

7. Last-tag semantics are lossy. A literal </think> in a code answer strips the real answer. A generation truncated right after </think> scores as empty, while an unterminated <think> scores as the full raw trace. No finish_reason is stored to tell these apart. This matches oe-eval's behavior and the PR's tests, so it is a defensible choice, but sage.py already has a more careful strip_think that could be shared.
8. Only outputs[*].text is stripped. Assistant turns in trajectory and request_trace keep the trace. No current scorer reads them, but harness scaffolds fill turn content with raw text, so a future agentic judge would silently see the trace. Extend the strip or document the limitation.
9. Small duplication and dead code. num_chars_all is emitted only when original_text exists, unlike its sibling num_tokens_all, so downstream readers will KeyError on non-thinking runs. Two separate if "original_text" in meta blocks guard the same key. The original_text or text expression and the BPB formula are duplicated between builders and the scorer. The if output.metadata is None guard is dead since metadata defaults to a dict. A full_text property on LMOutput would give one definition.
10. TASK_CONFIG_FIELDS is hand-maintained and already stale. The PR adds one entry to a frozenset in cli/utils.py:130 that omits eight real TaskConfig fields, so -o judge_model=x is rejected as an invalid override. Deriving it from dataclasses.fields(TaskConfig) plus priority is a drop-in, and the same function already does this for SamplingParams.

Emit strip_thinking in TaskConfig.to_dict only when set, so task hashes
of runs that never used the option are unchanged from before the field
existed. Replace the greedy (?s).*</think> regex in extract_think_answer
with rpartition: the regex backtracks quadratically on long answers
(1.2 s at 50k chars, 3.9 s at 100k) and runs on the scoring event loop.
Drop the dead metadata guard and document what the strip does and does
not touch.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LMFjgUqHjQA3aCeB4QmEHZ
abhishekraok and others added 2 commits September 10, 2026 16:38
finalize_task only runs for errored trackers; the production path is
score_and_store inside process_results, which had no strip coverage.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LMFjgUqHjQA3aCeB4QmEHZ
@abhishekraok

Copy link
Copy Markdown
Collaborator Author

Claude Code · https://claude.ai/code/session_01LMFjgUqHjQA3aCeB4QmEHZ

Thanks — went through all ten against the code. Verdicts and where each landed:

Pulled into this PR

  • (1) Task hashes: confirmed — compute_task_hash is sha256 over the full to_dict(), and the unconditional strip_thinking: False changed every hash when Add a strip_thinking task option that drops the reasoning trace before scoring #361 merged. Now emitted only when set, so hashes of runs that never used the option return to their pre-Add a strip_thinking task option that drops the reasoning trace before scoring #361 values (test added).
  • (2) Quadratic regex: confirmed and worse than measured here — 1.2 s at 50k chars, 3.9 s at 100k. extract_think_answer (which this PR routes the strip through) now uses rpartition; tests pin equivalence with the reference regexes on the edge cases, plus a timing test.
  • (6) Test coverage: confirmed — finalize_task only runs for errored trackers. Added a test through process_results → score_and_store.
  • (7)(8)(9-guard): documented in the docstring (last-tag semantics, only outputs[*].text is touched); dead metadata is None guard removed.

Split out

@abhishekraok
abhishekraok merged commit 3eaa9fb into main Sep 11, 2026
10 checks passed
@abhishekraok
abhishekraok deleted the fix/strip-thinking-no-lstrip branch September 11, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants