Skip to content

perf: true batched inference for TransformerDetector (fixes #23) - #113

Open
c71qu3 wants to merge 1 commit into
KRLabsOrg:mainfrom
c71qu3:feat/transformer-batch-processing
Open

c71qu3 wants to merge 1 commit into
KRLabsOrg:mainfrom
c71qu3:feat/transformer-batch-processing

Conversation

@c71qu3

@c71qu3 c71qu3 commented Sep 17, 2026

Copy link
Copy Markdown

TransformerDetector.predict_prompt_batch now performs padded batch tokenization and a single model forward pass per configured batch_size, preserving input order and correctly trimming prompt/padding per sample for both tokens and spans. Add strict len(prompts) == len(answers) validation (no silent zip truncation), including in the LLM detector request path.

Tests cover uneven sequence lengths, batch_size 1 and >1, output order, tokens, spans, min_confidence filtering, empty input, and mismatch errors; a spy/stub verifies one forward call per transformer batch without downloading a model.

Summary

Related issue

Type of change

  • Bug fix
  • Feature
  • Documentation
  • Tests
  • Refactor or maintenance

Testing

  • ruff format --check lettucedetect/ lettucedetect_api/ tests/
  • ruff check lettucedetect/ lettucedetect_api/ tests/ --extend-exclude lettucedetect/integrations/
  • python -m pytest
  • Other:

Checklist

  • I kept the PR focused on one change.
  • I added or updated tests/docs when needed.
  • I checked that no secrets, API keys, or credentials are included.

Rights & sign-off (required)

  • I certify that I have the right to submit this code and that it may be
    distributed under the repository's MIT license
    (see CONTRIBUTING).

)

TransformerDetector.predict_prompt_batch now performs padded batch tokenization
and a single model forward pass per configured batch_size, preserving input
order and correctly trimming prompt/padding per sample for both tokens and spans.
Add strict len(prompts) == len(answers) validation (no silent zip truncation),
including in the LLM detector request path.

Tests cover uneven sequence lengths, batch_size 1 and >1, output order, tokens,
spans, min_confidence filtering, empty input, and mismatch errors; a spy/stub
verifies one forward call per transformer batch without downloading a model.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant