Skip to content
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
2 changes: 1 addition & 1 deletion deepspeed/comm/ccl.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def gather(self, tensor, gather_list, dst, group=None, async_op=False):
def scatter(self, tensor, gather_list, dst, group=None, async_op=False):
return self.run_collective(name="scatter", tensor=tensor, gather_list=gather_list, dst=dst, group=group)

def barrier(self, group=None, async_op=False):
def barrier(self, group=None, async_op=False, device_ids=None):
return self.run_collective(name="barrier", group=group, async_op=async_op)

def monitored_barrier(self, group=None, timeout=None, wait_all_ranks=False):
Expand Down
2 changes: 1 addition & 1 deletion deepspeed/comm/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def scatter(tensor,
@timed_op
def barrier(group=None, async_op=False, device_ids=None, prof=False, log_name='barrier', debug=get_caller_func()):
global cdb
return cdb.barrier(group=group, async_op=async_op)
return cdb.barrier(group=group, async_op=async_op, device_ids=device_ids)


@timed_op
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/comm/test_barrier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) DeepSpeed Team.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add the required Signed-off-by trailer

This non-merge commit has no Signed-off-by trailer, so the repository's DCO validation will reject it; recreate the commit using --signoff with the configured author identity.

AGENTS.md reference: AGENTS.md:L8-L8

Useful? React with 👍 / 👎.

# SPDX-License-Identifier: Apache-2.0

# DeepSpeed Team

from unittest.mock import MagicMock, sentinel

import pytest

import deepspeed.comm.comm as comm
from deepspeed.comm.ccl import CCLBackend


@pytest.mark.parametrize("call_kwargs", [{}, {"device_ids": [0]}])
def test_public_barrier_forwards_device_ids(monkeypatch, call_kwargs):
backend = MagicMock()
backend.barrier.return_value = sentinel.work
monkeypatch.setattr(comm, "cdb", backend)
monkeypatch.setattr(comm.comms_logger, "enabled", False)
expected_device_ids = call_kwargs.get("device_ids")

result = comm.barrier(**call_kwargs)

assert result is sentinel.work
backend.barrier.assert_called_once_with(group=None, async_op=False, device_ids=expected_device_ids)
assert backend.barrier.call_args.kwargs["device_ids"] is expected_device_ids


@pytest.mark.parametrize("call_kwargs", [{}, {"device_ids": [0]}])
def test_ccl_barrier_accepts_device_ids(call_kwargs):
backend = CCLBackend.__new__(CCLBackend)
backend.run_collective = MagicMock(return_value=sentinel.work)

result = backend.barrier(**call_kwargs)

assert result is sentinel.work
backend.run_collective.assert_called_once_with(name="barrier", group=None, async_op=False)
Loading