Skip to content

Scope RunInference model_identifier annotation to BeamML_RunInference - #40671

Merged
tvalentyn merged 2 commits into
apache:masterfrom
AMOOOMA:fix-model-identifier-and-metric-tag
Oct 22, 2026
Merged

tvalentyn merged 2 commits into
apache:masterfrom
AMOOOMA:fix-model-identifier-and-metric-tag

Conversation

@AMOOOMA

@AMOOOMA AMOOOMA commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Previously, RunInference.annotations() attached model_identifier to the outer RunInference composite PTransform, which caused all nested sub-transforms (such as WatchFilePattern side-input polling transforms, BatchElements, BeamML_RunInference_MonitoringOutlet, preprocess/postprocess transforms, etc.) to inherit the model_identifier annotation. Runners that group steps by model_identifier to look up num_loaded_models_<model_identifier> would then attach model_identifier to steps that never execute _RunInferenceDoFn.

This PR removes model_identifier from RunInference.annotations() and attaches transform_annotations(model_identifier=self._model_tag) directly around BeamML_RunInference in RunInference.expand().

Testing

  • Added test_run_inference_only_attaches_model_identifier_to_inference_step in base_test.py.
  • Updated test_run_inference_monitoring_outlet_shadows_model_identifier in vertex_ai_model_monitoring_v2_test.py.

@AMOOOMA
AMOOOMA force-pushed the fix-model-identifier-and-metric-tag branch from 8f9def8 to ab4245c Compare October 19, 2026 22:43
@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.07%. Comparing base (a8d6afd) to head (1e0b941).
⚠️ Report is 35 commits behind head on master.

Files with missing lines Patch % Lines
sdks/python/apache_beam/ml/inference/base.py 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40671      +/-   ##
==========================================
+ Coverage   80.04%   80.07%   +0.02%     
==========================================
  Files         490      490              
  Lines       82916    83005      +89     
==========================================
+ Hits        66373    66465      +92     
+ Misses      16543    16540       -3     
Flag Coverage Δ
python 80.07% <94.11%> (+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.

@AMOOOMA
AMOOOMA marked this pull request as ready for review October 20, 2026 16:56
@AMOOOMA

AMOOOMA commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

R: @tvalentyn

@github-actions

Copy link
Copy Markdown
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@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

@AMOOOMA AMOOOMA changed the title Scope RunInference model_identifier annotation and preserve ModelManager metric_tag across model updates Scope RunInference model_identifier annotation to BeamML_RunInference Oct 21, 2026
@AMOOOMA
AMOOOMA force-pushed the fix-model-identifier-and-metric-tag branch from 7ddd3f0 to 93cfdef Compare October 21, 2026 21:19
@AMOOOMA
AMOOOMA force-pushed the fix-model-identifier-and-metric-tag branch from 93cfdef to c11ecad Compare October 21, 2026 21:23
batched_elements_pcoll
| 'BeamML_RunInference' >> run_inference_pardo)
with batched_elements_pcoll.pipeline.transform_annotations(
model_identifier=self._model_tag):

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.

do we want to add this annotation even when not using ModelManager, or should we downscope this ?

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.

based on offline discussion sounds like it is probably ok to keep as is.

run_inference_pardo.with_exception_handling(
exc_class=self._exc_class,
use_subprocess=self._use_subprocess,
threshold=self._threshold,

@tvalentyn tvalentyn Oct 21, 2026 •

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.

it appears that if threshold < 1, then we add a few more nodes in the pipeline graph that will unintentionally get this annotation, see:

if self._threshold < 1.0:
.

I don't have an opinion yet how to best account for this.

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.

Good catch, I agree we should probably refactor this. I will add a comment for now and make a feature request for the refactor and follow up to keep this change smaller.

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.

#40715 here for tracking

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.

possible direction to consider (note: this is a draft rn #40738)

self.assertTrue(len(outlet_transforms) > 0)
for t in outlet_transforms:
self.assertEqual(t.annotations.get("model_identifier"), b"")
self.assertFalse(t.annotations.get("model_identifier"))

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.

should we remove

?

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.

Ah yes we should, that got lost in the split, will add it back.

@AMOOOMA
AMOOOMA force-pushed the fix-model-identifier-and-metric-tag branch from 7fab7c7 to 1e0b941 Compare October 21, 2026 23:01
@tvalentyn
tvalentyn merged commit c8b5acf into apache:master Oct 22, 2026
86 checks passed
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.

2 participants