Skip to content

[Python][RunInference] Deduplicate ModelHandler wrappers via _DelegatingModelHandler - #41051

Open
damccorm wants to merge 1 commit into
apache:masterfrom
damccorm:refactor-delegating-model-handler
Open

damccorm wants to merge 1 commit into
apache:masterfrom
damccorm:refactor-delegating-model-handler

Conversation

@damccorm

@damccorm damccorm commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #40906. We were duplicating a ton of logic there and in other PRs, so this is trying to simplify things.

Refactors the single-base ModelHandler wrapper classes (MaybeKeyedModelHandler, _PrebatchedModelHandler, _PreProcessingModelHandler, and _PostProcessingModelHandler) to inherit from a shared _DelegatingModelHandler base class instead of duplicating ~15 pass-through methods on each wrapper class.

Also forwards set_environment_vars() to the underlying ModelHandler in _DelegatingModelHandler (and single-model KeyedModelHandler) so custom set_environment_vars() overrides on wrapped handlers are preserved alongside _env_vars.

@github-actions github-actions Bot added python size/m M: 50-249 lines changed labels Nov 6, 2026
@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.07692% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 57.46%. Comparing base (d3078c1) to head (052c7fc).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
sdks/python/apache_beam/ml/inference/base.py 98.07% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #41051      +/-   ##
============================================
- Coverage     57.48%   57.46%   -0.02%     
  Complexity     2492     2492              
============================================
  Files          1204     1204              
  Lines        171265   171181      -84     
  Branches       2103     2103              
============================================
- Hits          98456    98375      -81     
+ Misses        70157    70154       -3     
  Partials       2652     2652              
Flag Coverage Δ
python 80.20% <98.07%> (-0.02%) ⬇️

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.

@damccorm
damccorm marked this pull request as ready for review November 6, 2026 20:51

@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 cleanly deduplicates the single-base ModelHandler wrapper classes (MaybeKeyedModelHandler, _PrebatchedModelHandler, _PreProcessingModelHandler, and _PostProcessingModelHandler) by introducing a shared _DelegatingModelHandler base class. It also properly delegates set_environment_vars() across wrappers and single-model KeyedModelHandler instances, with solid unit test coverage.

🔍 General Feedback

  • The _DelegatingModelHandler abstraction significantly reduces boilerplate (~140 net lines removed) and ensures future ModelHandler hooks only need to be forwarded in one place.
  • Forwarding set_environment_vars() and preserving _model_identifier in _DelegatingModelHandler.__init__ improves consistency across wrapper chains.
  • Updating _is_multi_model_keyed_handler to unwrap any _DelegatingModelHandler makes the check more general and covers MaybeKeyedModelHandler as well.

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

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @tvalentyn for label python.
Backup reviewer: shunping (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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant