Datasets:
Download code/reference/12_allgather_gemm.py from willychan21/ParallelKernelBench_Problems: direct link, hf CLI and curl.
- Browser
- Download file 368 Bytes
-
https://huggingface.co/datasets/willychan21/ParallelKernelBench_Problems/resolve/aa1bb86f2c59256de88c97e6d1447957e673607e/code/reference/12_allgather_gemm.py
- Command line
-
hf download hf://datasets/willychan21/ParallelKernelBench_Problems@aa1bb86f2c59256de88c97e6d1447957e673607e/code/reference/12_allgather_gemm.py
-
curl -L -o 12_allgather_gemm.py https://huggingface.co/datasets/willychan21/ParallelKernelBench_Problems/resolve/aa1bb86f2c59256de88c97e6d1447957e673607e/code/reference/12_allgather_gemm.py
368 Bytes
| import torch | |
| import torch.distributed as dist | |
| def solution(A_local: torch.Tensor, B: torch.Tensor) -> torch.Tensor: | |
| world_size = dist.get_world_size() | |
| A_gathered = [torch.empty_like(A_local) for _ in range(world_size)] | |
| dist.all_gather(A_gathered, A_local) | |
| A_global = torch.cat(A_gathered, dim=1) | |
| return torch.matmul(A_global, B) | |