Skip to content

[RunInference] Load updated models in the ONNX and XGBoost model handlers - #41389

Merged
damccorm merged 2 commits into
apache:masterfrom
karthik-0306:fix-onnx-xgboost-model-refresh
Nov 25, 2026
Merged

damccorm merged 2 commits into
apache:masterfrom
karthik-0306:fix-onnx-xgboost-model-refresh

Conversation

@karthik-0306

Copy link
Copy Markdown
Contributor

Fixes #41384

OnnxModelHandlerNumpy and XGBoostModelHandler didn't implement update_model_path, so when RunInference got a new ModelMetadata on model_metadata_pcoll (for example from WatchFilePattern), load_model() reloaded the original model_uri / model_state and the pipeline kept using the old model without an error. Both handlers now update the path, as the PyTorch, sklearn, TensorFlow and HuggingFace handlers already do. The update is on the XGBoostModelHandler base class, so the Numpy, Pandas, SciPy and Datatable handlers all get it. ONNX predictions now also set model_id, which was always None.

Testing:

  • test_pipeline_updates_model_from_side_input starts on model a (y = 2x + 0.5) and sends model b (y = 5x + 0.5) on the side input. On master it gets 4.5 with model_id=None; with the fix it gets 10.5 with model_id set to model b.
  • The new test_update_model_path tests for ONNX and XGBoost fail on master and pass with the fix.
  • Three existing ONNX tests now expect model_id to be set.
  • onnx_inference_test.py (TensorFlow tests not run locally): 12 passed, 1 skipped. xgboost_inference_test.py, sklearn_inference_test.py and base_test.py: 177 passed, 4 skipped.
  • yapf and ruff are clean on the touched files. CHANGES.md updated.

R: @jrmccluskey

@github-actions github-actions Bot added python size/s S: 10-49 lines changed labels Nov 16, 2026

@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 #41384 by implementing update_model_path on OnnxModelHandlerNumpy and XGBoostModelHandler, enabling side-input model updates via model_metadata_pcoll (such as WatchFilePattern), and populating PredictionResult.model_id in OnnxModelHandlerNumpy.run_inference. The implementation is clean, consistent with existing ModelHandler implementations (such as SklearnModelHandlerNumpy and TFModelHandlerNumpy), and well-covered by unit and pipeline tests.

🔍 General Feedback

  • Defining update_model_path on the XGBoostModelHandler base class cleanly propagates model refresh support to all XGBoost handler variants (Numpy, Pandas, SciPy, and Datatable).
  • The added unit tests (test_update_model_path, test_update_model_path_without_path_keeps_model) and end-to-end pipeline test (test_pipeline_updates_model_from_side_input) thoroughly verify both model reloading and model_id propagation.

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

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @damccorm 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).

@github-actions

Copy link
Copy Markdown
Contributor

Reminder, please take a look at this pr: @damccorm

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.05%. Comparing base (a5daa5e) to head (54022d7).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
.../python/apache_beam/ml/inference/onnx_inference.py 0.00% 3 Missing ⚠️
...thon/apache_beam/ml/inference/xgboost_inference.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #41389      +/-   ##
============================================
- Coverage     58.05%   58.05%   -0.01%     
  Complexity     2842     2842              
============================================
  Files          1210     1210              
  Lines        173310   173314       +4     
  Branches       2329     2329              
============================================
- Hits         100617   100615       -2     
- Misses        69978    69987       +9     
+ Partials       2715     2712       -3     
Flag Coverage Δ
python 80.68% <0.00%> (-0.01%) ⬇️

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

Comment thread CHANGES.md Resolved
@damccorm
damccorm merged commit d86e346 into apache:master Nov 25, 2026
86 of 87 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.

[Bug]: OnnxModelHandlerNumpy and XGBoostModelHandler ignore model updates from model_metadata_pcoll

2 participants