Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core][Distributed] add cleanup code for model parallel #4471

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions vllm/distributed/parallel_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,21 @@ def is_pynccl_enabled_for_all_reduce():
"""check if pynccl is enabled for all reduce"""
global _ENABLE_PYNCCL_FOR_ALL_REDUCE
return _ENABLE_PYNCCL_FOR_ALL_REDUCE


class _Destructor:
"""
Python does not support destructors for modules. This class is a
workaround to ensure that the model parallel groups are destroyed.
This is needed because many Python objects hold resources that live
outside of Python's garbage collection system, e.g. process groups,
NCCL communicators, etc.
"""

def __del__(self):
destroy_model_parallel()


# When `_destructor` is garbage collected, the model parallel groups will be
# destroyed.
_destructor = _Destructor()
Loading