MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / _split

Function _split

deepspeed/compression/basic_layer.py:655–672  ·  view source on GitHub ↗

Split the tensor along its last dimension and keep the corresponding slice.

(input_)

Source from the content-addressed store, hash-verified

653
654
655def _split(input_):
656 """Split the tensor along its last dimension and keep the
657 corresponding slice."""
658 group = g_mpu.get_model_parallel_group()
659
660 # Bypass the function if we are using only 1 GPU.
661 if dist.get_world_size(group=group) == 1:
662 return input_
663
664 # Split along last dimension.
665 world_size = dist.get_world_size(group=group)
666 input_list = split_tensor_along_last_dim(input_, world_size)
667
668 # Note: torch.split does not create contiguous tensors by default.
669 rank = dist.get_rank(group=group)
670 output = input_list[rank].contiguous()
671
672 return output
673
674
675def _gather(input_):

Callers 2

forwardMethod · 0.85
backwardMethod · 0.85

Calls 5

get_world_sizeMethod · 0.80
contiguousMethod · 0.80
get_rankMethod · 0.45

Tested by

no test coverage detected