MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / _conv_gather

Function _conv_gather

sat/sgm/modules/cp_enc_dec.py:163–195  ·  view source on GitHub ↗
(input_, dim, kernel_size)

Source from the content-addressed store, hash-verified

161
162
163def _conv_gather(input_, dim, kernel_size):
164 cp_world_size = get_context_parallel_world_size()
165
166 # Bypass the function if context parallel is 1
167 if cp_world_size == 1:
168 return input_
169
170 group = get_context_parallel_group()
171 cp_rank = get_context_parallel_rank()
172
173 # print('in _conv_gather, cp_rank:', cp_rank, 'input_size:', input_.shape)
174
175 input_first_kernel_ = input_.transpose(0, dim)[:kernel_size].transpose(0, dim).contiguous()
176 if cp_rank == 0:
177 input_ = input_.transpose(0, dim)[kernel_size:].transpose(0, dim).contiguous()
178 else:
179 input_ = input_.transpose(0, dim)[kernel_size - 1 :].transpose(0, dim).contiguous()
180
181 tensor_list = [torch.empty_like(torch.cat([input_first_kernel_, input_], dim=dim))] + [
182 torch.empty_like(input_) for _ in range(cp_world_size - 1)
183 ]
184 if cp_rank == 0:
185 input_ = torch.cat([input_first_kernel_, input_], dim=dim)
186
187 tensor_list[cp_rank] = input_
188 torch.distributed.all_gather(tensor_list, input_, group=group)
189
190 # Note: torch.cat already creates a contiguous tensor.
191 output = torch.cat(tensor_list, dim=dim).contiguous()
192
193 # print('out _conv_gather, cp_rank:', cp_rank, 'input_size:', output.shape)
194
195 return output
196
197
198def _pass_from_previous_rank(input_, dim, kernel_size):

Callers 4

backwardMethod · 0.70
forwardMethod · 0.70
encodeMethod · 0.50
decodeMethod · 0.50

Calls 3

Tested by

no test coverage detected