Datasets:
File size: 368 Bytes
453129d | 1 2 3 4 5 6 7 8 9 10 11 12 | import torch
import torch.distributed as dist
@torch.no_grad()
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)
|