Implement inject_span="trial" in RepengGenerator - #50
Merged
Conversation
Injects only from the newline before "Trial 1" onward (prompt tail + response), matching the paper's stricter span, instead of the whole forward pass. The preamble is forwarded with control off to build its KV cache, then generation continues from the anchor with control on. Adds resolve_inject_span_start() to compute the anchor token index and tests covering both "full" (token 0) and "trial" (anchor newline), on a fake offset-mapping tokenizer and on the real Qwen2.5-0.5B-Instruct tokenizer. Closes bamdadd#11 Co-Authored-By: Claude Sonnet 5 <[email protected]>
bamdadd
pushed a commit
that referenced
this pull request
Jul 31, 2026
Injects only from the newline before "Trial 1" onward (prompt tail + response), matching the paper's stricter span, instead of the whole forward pass. The preamble is forwarded with control off to build its KV cache, then generation continues from the anchor with control on. Adds resolve_inject_span_start() to compute the anchor token index and tests covering both "full" (token 0) and "trial" (anchor newline), on a fake offset-mapping tokenizer and on the real Qwen2.5-0.5B-Instruct tokenizer. Closes #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
inject_span="trial"inRepengGenerator: injection now applies only from the newline immediately before"Trial 1"onward (prompt tail + generated response), matching the paper's stricter protocol, instead of only supporting"full"(whole forward pass).resolve_inject_span_start(tokenizer, prompt, inject_span), which computes the anchor token index for"trial"and returns0for"full"; unknown span names still raiseNotImplementedError.generate_batchnow forwards the pre-anchor preamble with control off (to build its KV cache), then continues generation from the anchor with control on — reusing the same cached-generation path as"full"for the anchor-onward span."full"behavior is unchanged (same single-call code path as before).Test plan
resolve_inject_span_startusing a fake offset-mapping tokenizer ("full"→ token 0;"trial"→ lands on the anchor newline; unknown span →NotImplementedError).RepengGeneratorstill rejects unknowninject_spanvalues without loading a model.@pytest.mark.slowtest on the realQwen/Qwen2.5-0.5B-Instructtokenizer confirming the computed index lands on the newline before"Trial 1"in the rendered prompt, and that"full"still resolves to token 0.uv run pytest -q(full suite, including slow) passes.uv run ruff check/uv run ruff format --check/uv run mypy src/introspection_scaling/harness.pyall pass.Closes #11
🤖 Generated with Claude Code