MCPcopy Create free account
hub / github.com/AIS-SNU/Smart-Infinity / gather_split_1d_tensor

Function gather_split_1d_tensor

DeepSpeedExample/megatron/mpu/random.py:113–124  ·  view source on GitHub ↗

Opposite of above function, gather values from model parallel ranks.

(tensor)

Source from the content-addressed store, hash-verified

111
112
113def gather_split_1d_tensor(tensor):
114 """Opposite of above function, gather values from model parallel ranks."""
115 world_size = get_model_parallel_world_size()
116 numel = torch.numel(tensor)
117 numel_gathered = world_size * numel
118 gathered = torch.empty(numel_gathered, dtype=tensor.dtype,
119 device=torch.cuda.current_device(),
120 requires_grad=False)
121 chunks = [gathered[i*numel:(i+1)*numel] for i in range(world_size)]
122 torch.distributed.all_gather(chunks, tensor,
123 group=get_model_parallel_group())
124 return gathered
125
126
127class CudaRNGStatesTracker:

Callers 1

backwardMethod · 0.70

Calls 5

numelMethod · 0.80
get_model_parallel_groupFunction · 0.70
current_deviceMethod · 0.45
all_gatherMethod · 0.45

Tested by

no test coverage detected