Skip to content

Only feed total memory readings to the ModelManager resource estimator - #40646

Open
schizophrenicmaniac wants to merge 1 commit into
apache:masterfrom
schizophrenicmaniac:fix/40636-bug-runinference-modelmanager-nnls
Open

schizophrenicmaniac wants to merge 1 commit into
apache:masterfrom
schizophrenicmaniac:fix/40636-bug-runinference-modelmanager-nnls

Conversation

@schizophrenicmaniac

Copy link
Copy Markdown
Contributor

ModelManager._spawn_new_model was recording peak_during_load - baseline_snap as an observation for {tag: 1}, while release_model records total peak memory for the snapshot of all loaded models. Since ResourceEstimator._solve fits Σ count·cost + bias ≈ reading, the delta rows and total rows contradict each other. With a single model loaded, both kinds even end up in the same history bucket. The delta was also noisy, because the peak window isn't reset before a load.

This removes the spawn-time observation, so the estimator now only sees total memory readings with the full model snapshot from release_model. Profiling unknown models in isolation mode is unchanged, since the initial estimate is still set on release from the isolation baseline.

I added a test that loads two known models at the same time and checks that the estimator history only contains total readings for the combined snapshot. It fails on master, where a 2000 MB delta is recorded for {model_b: 1} while 3000 MB is in use.

Fixes #40636

@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 resolves #40636 by removing the spawn-time memory delta observation in ModelManager._spawn_new_model, ensuring ResourceEstimator only receives consistent total memory readings alongside the full active model snapshot during release_model. The change is well-scoped and includes a clear unit test verifying the fix.

🔍 General Feedback

  • Removing the delta observation from _spawn_new_model eliminates the contradiction in the NNLS solver (where a bias term is fit against total memory) and prevents noisy readings from unreset peak windows during concurrent model loads.
  • Isolation mode profiling for unknown models remains intact via set_initial_estimate on model release.
  • The new unit test test_model_manager_observations_use_total_memory accurately exercises the multi-model scenario and verifies the estimator history state.

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

@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.94%. Comparing base (76f6e6d) to head (4180712).
⚠️ Report is 216 commits behind head on master.

Files with missing lines Patch % Lines
...s/python/apache_beam/ml/inference/model_manager.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             master   #40646       +/-   ##
=============================================
+ Coverage     56.16%   79.94%   +23.77%     
=============================================
  Files          1124      488      -636     
  Lines        178336    82558    -95778     
  Branches       1489        0     -1489     
=============================================
- Hits         100170    65999    -34171     
+ Misses        75645    16559    -59086     
+ Partials       2521        0     -2521     
Flag Coverage Δ
go ?
java ?
python 79.94% <0.00%> (+0.38%) ⬆️

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: RunInference ModelManager NNLS model approximates different data points

1 participant