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

Set current device for async_quorum and PG process #125

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion torchft/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ def start_quorum(
allow_heal=allow_heal,
shrink_only=shrink_only,
quorum_timeout=timeout or self._quorum_timeout,
curr_device=(torch.cuda.current_device() if torch.cuda.is_available() else -1),
)
if not self._use_async_quorum:
self.wait_quorum()
Expand All @@ -427,8 +428,10 @@ def wait_quorum(self) -> None:
self._quorum_future.result()

def _async_quorum(
self, allow_heal: bool, shrink_only: bool, quorum_timeout: timedelta
self, allow_heal: bool, shrink_only: bool, quorum_timeout: timedelta, curr_device: int,
) -> None:
if curr_device >= 0 and torch.cuda.is_available():
torch.cuda.set_device(curr_device)
quorum = self._client._quorum(
rank=self._rank,
step=self._step,
Expand Down
7 changes: 7 additions & 0 deletions torchft/process_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,8 @@ def configure(self, store_addr: str, rank: int, world_size: int) -> None:
self._pipe = req_local = _MonitoredPipe(req_local)
self._future_pipe = future_local = _MonitoredPipe(future_local)

curr_device = torch.cuda.current_device() if torch.cuda.is_available() else -1

self._p = p = ctx.Process(
target=self._worker,
args=(
Expand All @@ -989,6 +991,7 @@ def configure(self, store_addr: str, rank: int, world_size: int) -> None:
world_size,
req_remote,
future_remote,
curr_device,
),
daemon=True,
)
Expand Down Expand Up @@ -1024,8 +1027,12 @@ def _worker(
world_size: int,
req_pipe: "Connection[object, object]",
future_pipe: "Connection[object, object]",
curr_device: int,
) -> None:
try:
if curr_device >= 0 and torch.cuda.is_available():
torch.cuda.set_device(curr_device)

store = create_store_client(store_addr)

try:
Expand Down
Loading