Datasets:
Download code/reference/2_allgather.py from willychan21/ParallelKernelBench_Problems: direct link, hf CLI and curl.
- Browser
- Download file 273 Bytes
-
https://huggingface.co/datasets/willychan21/ParallelKernelBench_Problems/resolve/aa1bb86f2c59256de88c97e6d1447957e673607e/code/reference/2_allgather.py
- Command line
-
hf download hf://datasets/willychan21/ParallelKernelBench_Problems@aa1bb86f2c59256de88c97e6d1447957e673607e/code/reference/2_allgather.py
-
curl -L -o 2_allgather.py https://huggingface.co/datasets/willychan21/ParallelKernelBench_Problems/resolve/aa1bb86f2c59256de88c97e6d1447957e673607e/code/reference/2_allgather.py
273 Bytes
| import torch | |
| import torch.distributed as dist | |
| def solution(tensor: torch.Tensor) -> torch.Tensor: | |
| world_size = dist.get_world_size() | |
| out = tensor.new_empty((world_size,) + tensor.shape) | |
| dist.all_gather_into_tensor(out, tensor) | |
| return out | |