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

Function _gather

sat/vae_modules/cp_enc_dec.py:102–132  ·  view source on GitHub ↗
(input_, dim)

Source from the content-addressed store, hash-verified

100
101
102def _gather(input_, dim):
103 cp_world_size = get_context_parallel_world_size()
104
105 # Bypass the function if context parallel is 1
106 if cp_world_size == 1:
107 return input_
108
109 group = get_context_parallel_group()
110 cp_rank = get_context_parallel_rank()
111
112 # print('in _gather, cp_rank:', cp_rank, 'input_size:', input_.shape)
113
114 input_first_frame_ = input_.transpose(0, dim)[:1].transpose(0, dim).contiguous()
115 if cp_rank == 0:
116 input_ = input_.transpose(0, dim)[1:].transpose(0, dim).contiguous()
117
118 tensor_list = [torch.empty_like(torch.cat([input_first_frame_, input_], dim=dim))] + [
119 torch.empty_like(input_) for _ in range(cp_world_size - 1)
120 ]
121
122 if cp_rank == 0:
123 input_ = torch.cat([input_first_frame_, input_], dim=dim)
124
125 tensor_list[cp_rank] = input_
126 torch.distributed.all_gather(tensor_list, input_, group=group)
127
128 output = torch.cat(tensor_list, dim=dim).contiguous()
129
130 # print('out _gather, cp_rank:', cp_rank, 'output_size:', output.shape)
131
132 return output
133
134
135def _conv_split(input_, dim, kernel_size):

Callers

nothing calls this directly

Calls 3

Tested by

no test coverage detected