Skip to content

[RunInference] Validate model handler batching arguments - #40718

Merged
jrmccluskey merged 6 commits into
apache:masterfrom
alisha-1000:fix-runinference-batching-argument-validation
Oct 23, 2026
Merged

jrmccluskey merged 6 commits into
apache:masterfrom
alisha-1000:fix-runinference-batching-argument-validation

Conversation

@alisha-1000

Copy link
Copy Markdown
Contributor

Summary

  • Validate that max_batch_weight requires element_size_fn.
  • Reject combinations of max_batch_weight with batch_length_fn or batch_bucket_boundaries.
  • Validate that batch_bucket_boundaries requires batch_length_fn.
  • Add unit tests for invalid batching argument combinations.

Testing

  • ModelHandlerBatchingArgsTest: 17 passed.
  • git diff --check: passed.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Review Summary

This PR adds constructor-time validation in ModelHandler.__init__ to fail fast when max_batch_weight is provided without element_size_fn, or when max_batch_weight is combined with length-bucketing arguments (batch_length_fn or batch_bucket_boundaries). The implementation and unit tests in base.py and base_test.py are clean and align with the validation rules in BatchElements.__init__.

🔍 General Feedback

  • Consider verifying or standardizing RemoteModelHandler subclasses (VertexAIModelHandlerJSON in vertex_ai_inference.py and GeminiModelHandler in gemini_inference.py), which inherit from RemoteModelHandler and construct self._batching_kwargs directly without calling ModelHandler.__init__, so they currently defer this validation until BatchElements construction.
  • In base_test.py, test_batch_elements_kwargs_all_args was repurposed to test only length-aware arguments while dropping assertions for max_batch_weight and element_size_fn; keeping a separate test for weight-based batching kwargs would preserve full unit test coverage for batch_elements_kwargs().

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

💬 Inline Findings

  • sdks/python/apache_beam/ml/inference/base_test.py (line 2588): 🟢 Nit: Replacing max_batch_weight and element_size_fn here removes the test coverage in ModelHandlerBatchingArgsTest verifying that max_batch_weight and element_size_fn are populated into batch_elements_kwargs() when valid. Consider keeping a separate test method (e.g., test_batch_elements_kwargs_weight_args) that asserts max_batch_weight and element_size_fn are present in batch_elements_kwargs().

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @jrmccluskey for label python.
Backup reviewer: claudevdm (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.47059% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.93%. Comparing base (a8d6afd) to head (92ad9f4).
⚠️ Report is 58 commits behind head on master.

Files with missing lines Patch % Lines
...on/apache_beam/ml/inference/anthropic_inference.py 0.00% 2 Missing ⚠️
...ython/apache_beam/ml/inference/openai_inference.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40718      +/-   ##
==========================================
- Coverage   80.04%   79.93%   -0.12%     
==========================================
  Files         490      493       +3     
  Lines       82916    83419     +503     
==========================================
+ Hits        66373    66682     +309     
- Misses      16543    16737     +194     
Flag Coverage Δ
python 79.93% <76.47%> (-0.12%) ⬇️

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

Copy link
Copy Markdown
Contributor

R: @Eliaaazzz

@github-actions

Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@Eliaaazzz Eliaaazzz left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for following up on #40644! The validation matches the combinations we agreed on, and the explicit calls in the remote handlers cover the constructors that bypass ModelHandler.init. I didn't find a blocking correctness issue. One small documentation suggestion inline.

Comment thread sdks/python/apache_beam/ml/inference/base.py

@jrmccluskey jrmccluskey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; the recurring validation tests per model handler are a little overkill (testing in base_test.py should be sufficient) but harmless.

@jrmccluskey
jrmccluskey merged commit 1d8e837 into apache:master Oct 23, 2026
86 of 88 checks passed
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.

5 participants