Skip to content

Spawn MultiProcessShared RunInference models in dedicated processes (#40673) - #40816

Draft
damccorm wants to merge 2 commits into
apache:masterfrom
damccorm:spawn-models-dedicated-process
Draft

damccorm wants to merge 2 commits into
apache:masterfrom
damccorm:spawn-models-dedicated-process

Conversation

@damccorm

@damccorm damccorm commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Note: Stacked on #40822 (MultiProcessShared spawn_process fixes). Once #40822 merges into master, only the RunInference commit (apache_beam/ml/inference/base.py and base_test.py) remains in this PR.

Summary

Addresses #40673 using approach (b) from the issue discussion: spawn shared MultiProcessShared models in dedicated processes (spawn_process=True).

Root Cause

When MultiProcessShared(..., always_proxy=True, spawn_process=False) is used, the process that initializes the shared object both runs the _SingletonRegistrar server (Server.accepter) on a background thread and connects to its own server via BaseProxy. If an unreachable BaseProxy is part of a reference cycle and Python's cyclic GC runs during an allocation on the accepter thread, BaseProxy._decref opens a blocking client connection to that same server while accepter is blocked inside _decref, deadlocking the server (and any callers waiting on _process_local_lock).

Changes

  • apache_beam/ml/inference/base.py:
    • Pass spawn_process=True on the always_proxy=True MultiProcessShared handles (_RunInferenceDoFn._load_model, _RunInferenceDoFn._run_inference, load_model_status, _SharedModelWrapper, and finish_bundle's unsafe_hard_delete).
    • Use always_proxy=False for worker-local ModelManager so its process_wide=True metrics stay in the SDK worker without self-proxying.
  • Tests (apache_beam/ml/inference/base_test.py):

@github-actions github-actions Bot added python size/xl XL: >=1000 lines changed labels Oct 26, 2026
@damccorm
damccorm force-pushed the spawn-models-dedicated-process branch from 5c9e479 to 3271020 Compare October 26, 2026 16:58
@github-actions github-actions Bot added size/l L: 250-999 lines changed and removed size/xl XL: >=1000 lines changed labels Oct 26, 2026
@damccorm
damccorm force-pushed the spawn-models-dedicated-process branch from 3271020 to c5e3077 Compare October 26, 2026 17:29
@github-actions github-actions Bot added size/m M: 50-249 lines changed and removed size/l L: 250-999 lines changed labels Oct 26, 2026
@damccorm
damccorm force-pushed the spawn-models-dedicated-process branch from c5e3077 to e7e1768 Compare October 26, 2026 18:41
@damccorm
damccorm force-pushed the spawn-models-dedicated-process branch from e7e1768 to 8ceb461 Compare October 26, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python size/m M: 50-249 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant