MCPcopy
hub / github.com/deepspeedai/DeepSpeed / reduce_boolean_flags

Function reduce_boolean_flags

tests/unit/common.py:572–581  ·  view source on GitHub ↗
(flag: bool, op=all)

Source from the content-addressed store, hash-verified

570
571
572def reduce_boolean_flags(flag: bool, op=all) -> bool:
573 if not dist.is_initialized():
574 return flag
575 device = get_accelerator().current_device()
576 tensor_flag = torch.tensor(1 if flag else 0, dtype=torch.int, device=device)
577 world_size = dist.get_world_size()
578 tensor_flag_buf = torch.zeros(world_size, dtype=torch.int, device=device)
579 dist.all_gather_into_tensor(tensor_flag_buf, tensor_flag)
580 list_flags = [bool(f) for f in tensor_flag_buf.tolist()]
581 return op(list_flags)
582
583
584def allclose_on_all_ranks(actual, expected, assert_message=None, **kwargs) -> None:

Callers 2

testMethod · 0.90
allclose_on_all_ranksFunction · 0.85

Calls 5

get_acceleratorFunction · 0.90
get_world_sizeMethod · 0.80
is_initializedMethod · 0.45
current_deviceMethod · 0.45

Tested by 1

testMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…