Datasets:
File size: 486 Bytes
453129d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import torch
import torch.distributed as dist
@torch.no_grad()
def solution(
A_local: torch.Tensor,
B_local: torch.Tensor,
) -> torch.Tensor:
rank = dist.get_rank()
world_size = dist.get_world_size()
M, K = A_local.shape
K_B, N = B_local.shape
A_local = A_local.contiguous()
B_local = B_local.contiguous()
C_local = torch.matmul(A_local, B_local)
C = C_local.clone()
dist.all_reduce(C, op=dist.ReduceOp.SUM)
return C
|