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

Function _conv_gather

sat/vae_modules/cp_enc_dec.py:162–194  ·  view source on GitHub ↗
(input_, dim, kernel_size)

Source from the content-addressed store, hash-verified

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

Callers 4

encodeMethod · 0.90
decodeMethod · 0.90
backwardMethod · 0.70
forwardMethod · 0.70

Calls 3

Tested by

no test coverage detected