Skip to content

[Python] Honor fixed object detection batch size - #39953

Merged
jrmccluskey merged 1 commit into
apache:masterfrom
bvolpato:bvolpato/fix-object-detection-fixed-batching
Sep 1, 2026
Merged

[Python] Honor fixed object detection batch size#39953
jrmccluskey merged 1 commit into
apache:masterfrom
bvolpato:bvolpato/fix-object-detection-fixed-batching

Conversation

@bvolpato

@bvolpato bvolpato commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Related to #38782 and #39949.

Why

The object-detection example describes its inference batch size as fixed, but passes inference_batch_size to PytorchModelHandlerTensor. That handler does not consume this keyword. It reaches ModelHandler through **kwargs, where it is ignored, leaving RunInference to use adaptive BatchElements defaults.

This means all four Faster R-CNN benchmark variants have been measuring an unintended batching policy since they were added.

What changed

Pass the configured size through the supported min_batch_size and max_batch_size arguments. Setting both to the same value makes BatchElements use the requested fixed size, currently 8 in the benchmark configuration.

This is separate from #39949 because corrected batching may change runtime. The timeout change can remain draft until a Dataflow run shows whether 30 minutes is still insufficient.

Validation

  • python -m py_compile sdks/python/apache_beam/examples/inference/pytorch_image_object_detection.py
  • yapf==0.43.0 --diff on the changed file
  • ruff==0.15.22 check --ignore I001,UP006 on the changed file
  • git diff --check

The existing Python ML precommit covers PytorchModelHandlerTensor batching behavior.

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @jrmccluskey for label python.

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).

@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, thanks!

@jrmccluskey
jrmccluskey merged commit 4855a35 into apache:master Sep 1, 2026
99 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.

2 participants