Repository navigation
[Python] Fix max_models_per_worker_hint not being enforced in KeyedModelHandler - #40500
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #40500 +/- ##
============================================
+ Coverage 56.16% 56.35% +0.18%
Complexity 2288 2288
============================================
Files 1124 1125 +1
Lines 178336 178494 +158
Branches 1489 1489
============================================
+ Hits 100170 100591 +421
+ Misses 75645 75382 -263
Partials 2521 2521
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Assigning reviewers: R: @shunping for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
There was a problem hiding this comment.
Hi @schizophrenicmaniac, thanks for contributing.
Could you explain a bit more on why you take away the locking mechanism to protect accessing _incremented_process_ids or _max_models when calling increment_max_models?
|
@shunping The lock there was created fresh on each call ( |
|
Ok, the overall changes sounds reasonable to me. However, I am not super familiar with the design of this code, so maybe @tvalentyn can give a second opinon? |
|
thanks. |
The
max_models_per_worker_hintlimit for a KeyedModelHandler with several model handlers was never actually enforced.run_inferencecreated a newthreading.Lock()on every call, so acquiring it always succeeded. Each deserialized copy of the handler (one per DoFn instance, plus new copies when bundle processors are recreated) still had the hint set, so every copy added it to the shared_ModelHandlerManageragain. In the repro from the issue, five handler copies raised the limit to 5 and all three models stayed loaded with a hint of 1.This change makes
_ModelHandlerManager.increment_max_modelstake an optionalprocess_idand count each process only once.KeyedModelHandler.run_inferencepassesos.getpid(). The pid is computed on the caller's side because the manager is proxied from a separate MultiProcessShared process. Calls without a process id work as before.I added a unit test for the manager and one based on the repro in the issue (five pickled handler copies sharing one manager, hint of 1). The repro test fails on master and passes with this change. I also added a CHANGES.md entry.
Fixes #40468