Split the tensor along its last dimension and keep the corresponding slice.
(input_)
| 33 | |
| 34 | |
| 35 | def _split(input_): |
| 36 | """Split the tensor along its last dimension and keep the |
| 37 | corresponding slice.""" |
| 38 | |
| 39 | world_size = get_model_parallel_world_size() |
| 40 | # Bypass the function if we are using only 1 GPU. |
| 41 | if world_size==1: |
| 42 | return input_ |
| 43 | |
| 44 | # Split along last dimension. |
| 45 | input_list = split_tensor_along_last_dim(input_, world_size) |
| 46 | |
| 47 | # Note: torch.split does not create contiguous tensors by default. |
| 48 | rank = get_model_parallel_rank() |
| 49 | output = input_list[rank].contiguous() |
| 50 | |
| 51 | return output |
| 52 | |
| 53 | |
| 54 | def _gather(input_): |
no test coverage detected