proposal: batched inference for TransformerDetector (#23) - #114
Open
YassinNouh21 wants to merge 1 commit into
Open
YassinNouh21 wants to merge 1 commit into
YassinNouh21 wants to merge 1 commit into
Conversation
YassinNouh21
force-pushed
the
proposal/batched-inference
branch
from
September 18, 2026 07:54
aadc3e0 to
1e63a98
Compare
YassinNouh21
force-pushed
the
proposal/batched-inference
branch
from
September 18, 2026 07:55
1e63a98 to
aa78786
Compare
This branch has not been deployed
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
Design proposal for #23, no code in this PR. One file,
docs/proposals/0023-batched-inference.md: what is wrong today with line references, the batching design, and a test plan. Implementation can follow as a separate PR once the approach is agreed.The short version: batch only the forward pass. Tokenize pairs together with padding, take each row's real length from
attention_mask(the currentanswer_startformula uses the padded width,hallucination_dataset.py:178), run one forward per micro-batch, then decode every row with one shared_decode_rowthat the single path also uses.flowchart LR A["validate"] --> B["sort by length,<br/>micro-batch"] --> C["tokenize together,<br/>answer_start per row"] --> D["one forward"] --> E["_decode_row<br/>per row"] --> F["restore order"] S["predict_prompt"] --> EAlso fixes the silent
ziptruncation attransformer.py:452andllm.py:612,614with a shared length check inBaseDetector.Worked example from the doc, three pairs padded to
[3, 13]with the test-suite tokenizer:L - answer_len - 1mask.sum() - answer_len - 1[PAD]paris[PAD]parisshortshortOnly the longest row is right today.
Related issue
Refs #23
Type of change
Testing
mkdocs buildChecklist
Rights & sign-off (required)
distributed under the repository's MIT license
(see CONTRIBUTING).