(input_, dim, kernel_size)
| 161 | |
| 162 | |
| 163 | def _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 | |
| 198 | def _pass_from_previous_rank(input_, dim, kernel_size): |
no test coverage detected