Skip to content

[RunInference] Honor model updates in also in the first batch. - #40667

Merged
tvalentyn merged 6 commits into
apache:masterfrom
tvalentyn:model_updates
Oct 21, 2026
Merged

tvalentyn merged 6 commits into
apache:masterfrom
tvalentyn:model_updates

Conversation

@tvalentyn

@tvalentyn tvalentyn commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
  1. Honor model updates in first batch.

  2. Don't initiate load model calls when there are no updates. In another branch, do an update if the model was invalidated.

  3. Drive-by entries to changes.md from earlier PRs.

Fixes: #40665

@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 resolves a bug (#40665) where RunInference with per-key models (KeyedModelHandler) failed to apply KeyModelPathMapping side-input updates on the first batch when load_model_at_runtime=True. It also avoids redundant update_model calls on every batch when the side input is empty or the per-key model path mapping has not changed.

🔍 General Feedback

  • The fix in _RunInferenceDoFn._load_model and process is clean, well-tested, and properly addresses both the first-batch stale model bug and redundant update_model invocations.
  • One minor edge case was noted in process when using ModelMetadata side inputs together with timeout-based model invalidation, along with a minor CHANGES.md template placeholder removal.

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

Comment thread sdks/python/apache_beam/ml/inference/base.py Outdated
Comment thread CHANGES.md
@tvalentyn

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 fixes a bug (#40665) where RunInference with per-key models (KeyedModelHandler) failed to apply KeyModelPathMapping side-input updates on the first batch when load_model_at_runtime=True. It also prevents redundant update_model calls on every batch when side inputs are empty or unchanged, while properly handling model reloading across all branches when a model is marked invalid.

🔍 General Feedback

  • The updates in _RunInferenceDoFn._load_model and _RunInferenceDoFn.process are clean, consistent across all side-input branches, and well-covered by the new unit tests.

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

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.07%. Comparing base (a8d6afd) to head (b65d462).
⚠️ Report is 22 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40667      +/-   ##
==========================================
+ Coverage   80.04%   80.07%   +0.02%     
==========================================
  Files         490      490              
  Lines       82916    82938      +22     
==========================================
+ Hits        66373    66409      +36     
+ Misses      16543    16529      -14     
Flag Coverage Δ
python 80.07% <100.00%> (+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.

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

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

@github-actions
github-actions Bot requested a review from jrmccluskey October 19, 2026 21:14
@tvalentyn tvalentyn changed the title Model updates [RunInference] Honor model updates in also in the first batch. Oct 19, 2026
Comment thread sdks/python/apache_beam/ml/inference/base.py Outdated
Comment on lines +2264 to +2267
needs_update = (
self._model is None or # No model loaded yet.
self._side_input_path != si_model_metadata.model_id or # New model.
not self._model_metadata.is_valid_tag(self._cur_tag)) # Invalidated.

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.

The needs_update boolean evaluation is repeated multiple times with only slight variations based on si_model_metadata, consider a refactor into a helper (which also streamlines some of the repeated comments)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done, thanks!

@tvalentyn
tvalentyn requested a review from jrmccluskey October 21, 2026 01:40

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

@tvalentyn
tvalentyn merged commit bbd5e28 into apache:master Oct 21, 2026
115 of 117 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.

[Bug]: [RunInference] When load_model_at_runtime=True, the first batch always ignores model side-input updates.

2 participants