Skip to content

Support for “real” batch processing #23

Description

@talbaumel

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:

  1. Validate len(prompts) == len(answers) and raise ValueError on mismatch; never truncate.
  2. Tokenize a padded batch and run one model forward pass per configured batch.
  3. Preserve input order and remove padding and prompt tokens correctly per sample.
  4. Support both tokens and spans, including min_confidence behavior and taxonomy typing where configured.
  5. Add a configurable batch_size, or clearly document whole-list batching and its memory limit.
  6. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions