Repository navigation
proposal: batched inference for TransformerDetector (#23) - #114
YassinNouh21 wants to merge 1 commit into
Conversation
aadc3e0 to
1e63a98
Compare
1e63a98 to
aa78786
Compare
|
Thanks a lot for writing this up, @YassinNouh21. It's a clear design and it names exactly the traps an implementation has to avoid. #113 has now landed and covers your main points: it takes each row's answer start from the tokenizer's Two notes on the analysis. On We'd rather not add a
Thanks again, this made the review much easier. |
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).