Skip to content

[Python] Support max_batch_weight in BatchElements and honor element_size_fn in stateful batching - #40603

Closed
tvalentyn wants to merge 2 commits into
apache:masterfrom
tvalentyn:fix-runinference-keyed-batching
Closed

tvalentyn wants to merge 2 commits into
apache:masterfrom
tvalentyn:fix-runinference-keyed-batching

Conversation

@tvalentyn

Copy link
Copy Markdown
Contributor
  • Add max_batch_weight to BatchElements. When set, the batch size limits
    count elements and element_size_fn gives the weight of an element. This
    fixes RunInference failing with a TypeError when a ModelHandler sets
    max_batch_weight.
  • Honor element_size_fn when max_batch_duration_secs is set. This uses a
    separate stateful DoFn that only adds a 'weight' state and keeps the
    transform label, so pipelines that don't set element_size_fn are
    unaffected.
  • Never emit an empty batch when an element exceeds the limits on its own.
  • Warn when length_fn is set without max_batch_duration_secs, since it is
    ignored.<!--

Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • If this contribution is large, please file an Apache Individual Contributor License Agreement.
  • Replace these instructions with a description of your change and why you have made it.
  • Mention the appropriate issue in your description (for example: addresses #123 or fixes #456).
  • Update CHANGES.md with noteworthy changes.

See CONTRIBUTING.md for more details.

-->

…size_fn in stateful batching

* Add max_batch_weight to BatchElements. When set, the batch size limits
  count elements and element_size_fn gives the weight of an element. This
  fixes RunInference failing with a TypeError when a ModelHandler sets
  max_batch_weight.
* Honor element_size_fn when max_batch_duration_secs is set. This uses a
  separate stateful DoFn that only adds a 'weight' state and keeps the
  transform label, so pipelines that don't set element_size_fn are
  unaffected.
* Never emit an empty batch when an element exceeds the limits on its own.
* Warn when length_fn is set without max_batch_duration_secs, since it is
  ignored.
@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.92%. Comparing base (76f6e6d) to head (80e18e0).
⚠️ Report is 178 commits behind head on master.

Additional details and impacted files
@@              Coverage Diff              @@
##             master   #40603       +/-   ##
=============================================
+ Coverage     56.16%   79.92%   +23.75%     
=============================================
  Files          1124      488      -636     
  Lines        178336    82489    -95847     
  Branches       1489        0     -1489     
=============================================
- Hits         100170    65929    -34241     
+ Misses        75645    16560    -59085     
+ Partials       2521        0     -2521     
Flag Coverage Δ
go ?
java ?
python 79.92% <100.00%> (+0.36%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tvalentyn tvalentyn closed this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant