Problem
TransformerDetector.predict_prompt_batch currently loops over examples, so N inputs perform N tokenizations and N model forward passes. Both transformer and LLM batch paths also pair inputs with zip, which silently drops trailing values when input lengths differ.
Scope
Implement true batched inference for the transformer detector:
- Validate
len(prompts) == len(answers) and raise ValueError on mismatch; never truncate.
- Tokenize a padded batch and run one model forward pass per configured batch.
- Preserve input order and remove padding and prompt tokens correctly per sample.
- Support both
tokens and spans, including min_confidence behavior and taxonomy typing where configured.
- Add a configurable
batch_size, or clearly document whole-list batching and its memory limit.
- Keep the LLM detector's concurrent request path separate; it needs the same length validation but is not expected to share a model forward pass.
Acceptance
- Batch output matches the corresponding single-example method for every sample within a documented numerical tolerance.
- Tests cover uneven sequence lengths, batch size 1 and greater than 1, output order, tokens, spans, confidence filtering, empty input, and mismatched lengths.
- A spy or stub model verifies one forward call per transformer batch without downloading a model.
python -m pytest passes.
Non-goals
- Cross-request server batching.
- Automatic OOM recovery in the first implementation.
- Changing detector output schemas.
Problem
TransformerDetector.predict_prompt_batchcurrently loops over examples, so N inputs perform N tokenizations and N model forward passes. Both transformer and LLM batch paths also pair inputs withzip, which silently drops trailing values when input lengths differ.Scope
Implement true batched inference for the transformer detector:
len(prompts) == len(answers)and raiseValueErroron mismatch; never truncate.tokensandspans, includingmin_confidencebehavior and taxonomy typing where configured.batch_size, or clearly document whole-list batching and its memory limit.Acceptance
python -m pytestpasses.Non-goals