problem_id int64 1 87 | stem stringlengths 6 48 | reference_code stringlengths 204 14k | reference_path stringlengths 19 61 | input_tensor_spec_path stringclasses 1
value | world_size int64 4 4 | default_m int64 1.02k 1.02k | default_n int64 1.02k 1.02k | default_dtype stringclasses 1
value | default_trials int64 5 5 |
|---|---|---|---|---|---|---|---|---|---|
1 | 1_allreduce | import torch
import torch.distributed as dist
@torch.no_grad()
def solution(tensor: torch.Tensor) -> torch.Tensor:
out = tensor.clone()
dist.all_reduce(out, op=dist.ReduceOp.SUM)
return out
| reference/1_allreduce.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
2 | 2_allgather | import torch
import torch.distributed as dist
@torch.no_grad()
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
| reference/2_allgather.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
3 | 3_broadcast | import torch
import torch.distributed as dist
@torch.no_grad()
def solution(tensor: torch.Tensor, src: int = 0) -> torch.Tensor:
out = tensor.clone()
dist.broadcast(out, src=src)
return out
| reference/3_broadcast.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
4 | 4_reduce | import torch
import torch.distributed as dist
@torch.no_grad()
def solution(tensor: torch.Tensor, dst: int = 0) -> torch.Tensor:
out = tensor.clone()
dist.reduce(out, dst=dst, op=dist.ReduceOp.SUM)
return out
| reference/4_reduce.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
5 | 5_scatter | import torch
import torch.distributed as dist
@torch.no_grad()
def solution(tensor: torch.Tensor, src: int = 0) -> torch.Tensor:
rank = dist.get_rank()
if rank == src:
world_size = dist.get_world_size()
scatter_list = [chunk.squeeze(0).contiguous() for chunk in tensor.chunk(world_size, dim=0)... | reference/5_scatter.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
6 | 6_gather | import torch
import torch.distributed as dist
@torch.no_grad()
def solution(tensor: torch.Tensor, dst: int = 0) -> torch.Tensor:
rank = dist.get_rank()
if rank == dst:
world_size = dist.get_world_size()
gather_list = [torch.empty_like(tensor) for _ in range(world_size)]
else:
gath... | reference/6_gather.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
7 | 7_reducescatter | import torch
import torch.distributed as dist
@torch.no_grad()
def solution(tensor: torch.Tensor) -> torch.Tensor:
world_size = dist.get_world_size()
chunk_size = tensor.shape[0] // world_size
out = tensor.new_empty((chunk_size,) + tensor.shape[1:])
dist.reduce_scatter_tensor(out, tensor, op=dist.Redu... | reference/7_reducescatter.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
8 | 8_alltoall | import torch
import torch.distributed as dist
@torch.no_grad()
def solution(tensor: torch.Tensor) -> torch.Tensor:
out = torch.empty_like(tensor)
dist.all_to_all_single(out, tensor)
return out | reference/8_alltoall.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
9 | 9_layernorm_backward | import torch
import torch.distributed as dist
@torch.no_grad()
def solution(X_hat: torch.Tensor, dY: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
d_beta = dY.sum(dim=0)
d_gamma = (dY * X_hat).sum(dim=0)
dist.all_reduce(d_beta, op=dist.ReduceOp.SUM)
dist.all_reduce(d_gamma, op=dist.ReduceOp.SUM)... | reference/9_layernorm_backward.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
10 | 10_embedding_lookup | import torch
import torch.distributed as dist
@torch.no_grad()
def solution(
indices: torch.Tensor,
local_shard: torch.Tensor,
) -> torch.Tensor:
rank = dist.get_rank()
world_size = dist.get_world_size()
shard_size = local_shard.shape[0]
embed_dim = local_shard.shape[1]
indices = indic... | reference/10_embedding_lookup.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
11 | 11_allgather_gemm_AT | 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()
M, K_local = A_local.shape
K = world_size * K_local
A_local_t = A_local.transpose(0, 1).contiguous()
A_t_buf = A_local_t.new_empt... | reference/11_allgather_gemm_AT.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
12 | 12_allgather_gemm | 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_gather... | reference/12_allgather_gemm.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
13 | 13_gemm_allreduce | 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_... | reference/13_gemm_allreduce.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
14 | 14_gemm_allgather | import torch
import torch.distributed as dist
@torch.no_grad()
def solution(
A: torch.Tensor,
B: torch.Tensor,
) -> torch.Tensor:
rank = dist.get_rank()
world_size = dist.get_world_size()
M, K = A.shape
K_B, N_local = B.shape
A = A.contiguous()
B = B.contiguous()
C_local =... | reference/14_gemm_allgather.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
15 | 15_combined_sharded_gemms | import torch
import torch.distributed as dist
import torch.nn.functional as F
@torch.no_grad()
def solution(
x_local: torch.Tensor,
W1: torch.Tensor,
W2: torch.Tensor,
) -> torch.Tensor:
rank = dist.get_rank()
world_size = dist.get_world_size()
M = x_local.shape[0]
M_local = M // world_siz... | reference/15_combined_sharded_gemms.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
16 | 16_gemm_reducescatter | 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_local = A_local.shape
K_B, N = B_local.shape
M_local = M // world_size
... | reference/16_gemm_reducescatter.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
17 | 17_rope_allgather | import torch
import torch.distributed as dist
from typing import Tuple
def rotate_half(x: torch.Tensor) -> torch.Tensor:
half_dim = x.shape[-1] // 2
x1, x2 = x[..., :half_dim], x[..., half_dim:]
return torch.cat((-x2, x1), dim=-1)
def solution(
q_local: torch.Tensor,
k_local: torch.Tensor,
c... | reference/17_rope_allgather.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
18 | 18_tp_rms_norm | import torch
import torch.distributed as dist
def solution(local_hidden_states: torch.Tensor, local_weight: torch.Tensor, variance_epsilon: float) -> torch.Tensor:
input_dtype = local_hidden_states.dtype
# Upcast to float32 for stable variance calculation
local_hidden_states = local_hidden_states.to(torch.... | reference/18_tp_rms_norm.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
19 | 19_blocked_fp8_quantize | import torch
import torch.distributed as dist
import triton
import triton.language as tl
from typing import Tuple
@triton.jit
def block_fp8_quant_kernel(x_ptr, y_ptr, s_ptr, BLOCK_SIZE: tl.constexpr):
pid = tl.program_id(axis=0)
offs = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)
x = tl.load(x_ptr + offs).... | reference/19_blocked_fp8_quantize.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
20 | 20_blocked_fp8_dequantize | import torch
import torch.distributed as dist
import triton
import triton.language as tl
@triton.jit
def block_fp8_dequant_kernel(y_ptr, s_ptr, x_ptr, num_elements, BLOCK_SIZE: tl.constexpr):
pid = tl.program_id(axis=0)
offs = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)
mask = offs < num_elements
s = ... | reference/20_blocked_fp8_dequantize.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
21 | 21_clip_grad_norm_no_ep | from typing import List, Optional
import torch
import torch.distributed as dist
def _local_pth_sum(grad_tensors: List[torch.Tensor], p: float) -> torch.Tensor:
dev = None
acc = None
for g in grad_tensors:
if g is None:
continue
g_local = g
if dev is None:
d... | reference/21_clip_grad_norm_no_ep.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
22 | 22_clip_grad_norm_ep | from typing import List, Optional
import torch
import torch.distributed as dist
def _local_pth_sum(grad_tensors: List[torch.Tensor], p: float) -> torch.Tensor:
dev = None
acc = None
for g in grad_tensors:
if g is None:
continue
g_local = g
if dev is None:
d... | reference/22_clip_grad_norm_ep.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
23 | 23_grad_acc_loss | import torch
import torch.distributed as dist
from typing import Tuple, Optional
def forward(
loss: torch.Tensor,
local_valid_tokens: torch.Tensor,
global_valid_tokens: torch.Tensor,
) -> Tuple[torch.Tensor, torch.Tensor]:
if local_valid_tokens.item() == 0:
loss = torch.nan_to_num(loss)
l... | reference/23_grad_acc_loss.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
24 | 24_load_balancing_loss_fn | import torch
import torch.distributed as dist
from typing import Union, Tuple, Optional
def solution(
gate_logits: Union[torch.Tensor, Tuple[torch.Tensor, ...]],
num_experts: int,
top_k: int = 2,
attention_mask: Optional[torch.Tensor] = None,
) -> torch.Tensor:
if isinstance(gate_logits, (tuple, li... | reference/24_load_balancing_loss_fn.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
25 | 25_importance_sampling_loss | import torch
import torch.nn.functional as F
import torch.distributed as dist
from typing import Tuple, Any
def solution(
hidden_states: torch.Tensor,
weight: torch.Tensor,
labels: torch.Tensor,
old_logprobs: torch.Tensor,
advantages: torch.Tensor,
ignore_index: int = -100,
) -> Tuple[torch.Ten... | reference/25_importance_sampling_loss.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
26 | 26_moe_token_preprocess | from typing import List, Optional, Tuple
import torch
import torch.distributed as dist
def _preprocess_impl(
expert_mask: torch.Tensor,
num_experts: int,
ep_group: dist.ProcessGroup,
) -> Tuple[List[int], List[int], torch.Tensor, torch.Tensor]:
ep_size = ep_group.size()
num_local_experts = num_ex... | reference/26_moe_token_preprocess.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
27 | 27_moe_all2all_primitive | from typing import List, Optional, Union
import torch
import torch.distributed as dist
def solution(
local_tensor: torch.Tensor,
input_split_sizes: Optional[Union[List[int], torch.Tensor]] = None,
output_split_sizes: Optional[Union[List[int], torch.Tensor]] = None,
group: Optional[dist.ProcessGroup] ... | reference/27_moe_all2all_primitive.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
28 | 28_moe_pre_all2all | from typing import List, Optional, Tuple, Union
import torch
import torch.distributed as dist
def _permute(tokens: torch.Tensor, routing_map: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
num_tokens, _ = tokens.shape
num_experts = routing_map.shape[0]
routing_map = routing_map.bool()
token_indi... | reference/28_moe_pre_all2all.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
29 | 29_moe_post_all2all | from typing import List, Optional, Union
import torch
import torch.distributed as dist
def _sort_chunks_by_idxs(
input: torch.Tensor,
split_sizes: Union[torch.Tensor, List[int]],
sorted_idxs: List[int],
) -> torch.Tensor:
if isinstance(split_sizes, torch.Tensor):
split_sizes = split_sizes.tol... | reference/29_moe_post_all2all.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
30 | 30_moe_epgroupgemm_lora_backward | from typing import Optional, Tuple
import torch
import torch.distributed as dist
def solution(
grad_fc1_1_lora_A: torch.Tensor,
grad_fc1_2_lora_A: torch.Tensor,
grad_fc2_lora_B: torch.Tensor,
group: Optional[dist.ProcessGroup] = None,
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
group = ... | reference/30_moe_epgroupgemm_lora_backward.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
31 | 31_fused_moe_fwd | from typing import List, Optional, Tuple, Union
import torch
import torch.distributed as dist
class _AllToAll(torch.autograd.Function):
@staticmethod
def forward(ctx, group, input, output_split_sizes, input_split_sizes):
ctx.group = group
ctx.output_split_sizes = output_split_sizes
ct... | reference/31_fused_moe_fwd.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
32 | 32_fused_moe_fwd_lora | from typing import List, Optional, Tuple, Union
import torch
import torch.distributed as dist
class _AllToAll(torch.autograd.Function):
@staticmethod
def forward(ctx, group, input, output_split_sizes, input_split_sizes):
ctx.group = group
ctx.output_split_sizes = output_split_sizes
ct... | reference/32_fused_moe_fwd_lora.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
33 | 33_ulysses_all_to_all_tensor_primitive | from typing import Optional
import torch
import torch.distributed as dist
def solution(
x: torch.Tensor,
scatter_dim: int,
gather_dim: int,
group: Optional[dist.ProcessGroup] = None,
) -> torch.Tensor:
group = group or dist.group.WORLD
world_size = dist.get_world_size(group)
if world_size... | reference/33_ulysses_all_to_all_tensor_primitive.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
34 | 34_ulysses_all_gather_into_tensor_primitive | from typing import Optional
import torch
import torch.distributed as dist
def solution(
x: torch.Tensor,
group: Optional[dist.ProcessGroup] = None,
) -> torch.Tensor:
group = group or dist.group.WORLD
world_size = dist.get_world_size(group)
if world_size == 1:
return x.contiguous()
x... | reference/34_ulysses_all_gather_into_tensor_primitive.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
35 | 35_ulysses_all_gather_variable_primitive | from typing import List, Optional, Tuple
import torch
import torch.distributed as dist
def solution(
x: torch.Tensor,
gather_dim: int,
group: Optional[dist.ProcessGroup] = None,
) -> torch.Tensor:
group = group or dist.group.WORLD
world_size = dist.get_world_size(group)
if world_size == 1:
... | reference/35_ulysses_all_gather_variable_primitive.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
36 | 36_ulysses_gather_seq_scatter_heads | from typing import Optional
import torch
import torch.distributed as dist
from torch.distributed import ProcessGroup
def _all_to_all(
local_input: torch.Tensor,
scatter_dim: int,
gather_dim: int,
group: dist.ProcessGroup,
) -> torch.Tensor:
seq_world_size = dist.get_world_size(group)
input_li... | reference/36_ulysses_gather_seq_scatter_heads.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
37 | 37_ulysses_gather_heads_scatter_seq | from typing import Optional
import torch
import torch.distributed as dist
from torch.distributed import ProcessGroup
def _pad_tensor(x: torch.Tensor, dim: int, padding_size: int, padding_value: int = 0) -> torch.Tensor:
shape = list(x.shape)
shape[dim] = padding_size
pad = torch.full(shape, padding_value... | reference/37_ulysses_gather_heads_scatter_seq.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
38 | 38_ulysses_gather_seq_scatter_heads_qkv | from typing import Any, Optional, Tuple
import torch
import torch.distributed as dist
from torch import Tensor
from torch.distributed import ProcessGroup
def _pad_tensor(x: Tensor, dim: int, padding_size: int, padding_value: int = 0) -> Tensor:
shape = list(x.shape)
shape[dim] = padding_size
pad = torch.... | reference/38_ulysses_gather_seq_scatter_heads_qkv.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
39 | 39_ulysses_attention_e2e | from typing import Any, Optional, Tuple
import torch
import torch.nn.functional as F
import torch.distributed as dist
from torch import Tensor
from torch.distributed import ProcessGroup
def _pad_tensor(x: Tensor, dim: int, padding_size: int, padding_value: int = 0) -> Tensor:
shape = list(x.shape)
shape[dim]... | reference/39_ulysses_attention_e2e.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
40 | 40_ddp | from __future__ import annotations
import math
import torch
import torch.distributed as dist
import torch.nn.functional as F
from torch import Tensor
from torch._utils import _flatten_dense_tensors, _unflatten_dense_tensors
def solution(
X_local: Tensor,
y_local: Tensor,
W1: Tensor,
b1: Tensor,
... | reference/40_ddp.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
41 | 41_zero1_optimizer_shard | from __future__ import annotations
import math
import torch
import torch.distributed as dist
import torch.nn.functional as F
from torch import Tensor
from torch._utils import _flatten_dense_tensors, _unflatten_dense_tensors
def solution(
X_local: Tensor,
y_local: Tensor,
W1: Tensor,
b1: Tensor,
... | reference/41_zero1_optimizer_shard.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
42 | 42_zero2_optimizer_shard_grad | from __future__ import annotations
import math
import torch
import torch.distributed as dist
import torch.nn.functional as F
from torch import Tensor
from torch._utils import _flatten_dense_tensors, _unflatten_dense_tensors
def solution(
X_local: Tensor,
y_local: Tensor,
W1: Tensor,
b1: Tensor,
... | reference/42_zero2_optimizer_shard_grad.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
43 | 43_fused_adam_grad_unshard_allgather | from __future__ import annotations
import math
import torch
import torch.distributed as dist
from torch import Tensor
@torch.no_grad()
def solution(
grad_shard: Tensor,
master_shard: Tensor,
exp_avg: Tensor,
exp_avg_sq: Tensor,
lr: float,
beta1: float,
beta2: float,
eps: float,
s... | reference/43_fused_adam_grad_unshard_allgather.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
44 | 44_quantized_grad_allreduce | from __future__ import annotations
import torch
import torch.distributed as dist
import torch.nn.functional as F
from torch import Tensor
@torch.no_grad()
def _block_int8_quant_dequant(x_flat: Tensor, block_size: int) -> Tensor:
n = x_flat.numel()
if n == 0:
return x_flat.clone()
flat = x_flat.co... | reference/44_quantized_grad_allreduce.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
45 | 45_reducescatter_fused_rmsnorm | from __future__ import annotations
import torch
import torch.distributed as dist
from torch import Tensor
@torch.no_grad()
def solution(
rs_input_1d: Tensor,
gamma: Tensor,
eps: float,
) -> Tensor:
world_size = dist.get_world_size()
n = rs_input_1d.numel()
chunk = n // world_size
hidden ... | reference/45_reducescatter_fused_rmsnorm.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
46 | 46_fsdp_adamw_sharded | from __future__ import annotations
import math
import torch
from torch import Tensor
@torch.no_grad()
def solution(
flat_param_shard: Tensor,
flat_grad_shard: Tensor,
exp_avg_shard: Tensor,
exp_avg_sq_shard: Tensor,
lr: float,
beta1: float,
beta2: float,
eps: float,
weight_decay:... | reference/46_fsdp_adamw_sharded.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
47 | 47_fsdp_step_e2e | from __future__ import annotations
import math
from typing import Sequence
import torch
import torch.distributed as dist
import torch.nn.functional as F
from torch import Tensor
from torch._utils import _flatten_dense_tensors, _unflatten_dense_tensors
def solution(
X_local: Tensor,
y_local: Tensor,
flat... | reference/47_fsdp_step_e2e.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
48 | 48_fsdp_and_tp | from __future__ import annotations
import torch
import torch.distributed as dist
import torch.nn.functional as F
from torch import Tensor
def _make_tp_fsdp_groups(n_tp: int, n_fsdp: int, rank: int):
tp_group = None
fsdp_group = None
for j in range(n_fsdp):
ranks = [j * n_tp + ii for ii in range(n... | reference/48_fsdp_and_tp.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
49 | 49_moe_ep_balanced | from typing import List, Optional, Tuple, Union
import torch
import torch.distributed as dist
class _AllToAll(torch.autograd.Function):
@staticmethod
def forward(ctx, group, input, output_split_sizes, input_split_sizes):
ctx.group = group
ctx.output_split_sizes = output_split_sizes
ct... | reference/49_moe_ep_balanced.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
50 | 50_moe_ep_wide | from typing import List, Optional, Tuple, Union
import torch
import torch.distributed as dist
class _AllToAll(torch.autograd.Function):
@staticmethod
def forward(ctx, group, input, output_split_sizes, input_split_sizes):
ctx.group = group
ctx.output_split_sizes = output_split_sizes
ct... | reference/50_moe_ep_wide.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
51 | 51_moe_ep_narrow | from typing import List, Optional, Tuple, Union
import torch
import torch.distributed as dist
_EP_SUBGROUP_CACHE: dict[tuple[int, int], None | list] = {}
def _resolve_ep_group_for_narrow_moe(num_experts: int) -> dist.ProcessGroup:
if not dist.is_initialized():
raise RuntimeError("torch.distributed must ... | reference/51_moe_ep_narrow.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
52 | 52_fp8_reduce_scatter_grads | from __future__ import annotations
import torch
import torch.distributed as dist
from torch import Tensor
_FP8_E4M3_MAX = 448.0
@torch.no_grad()
def _update_amax_history(amax_history: Tensor, cur_abs_max: Tensor) -> Tensor:
out = torch.roll(amax_history, shifts=-1, dims=0)
out[-1] = cur_abs_max.to(dtype=out... | reference/52_fp8_reduce_scatter_grads.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
53 | 53_fp8_allgather_params | from __future__ import annotations
import torch
import torch.distributed as dist
from torch import Tensor
_FP8_E4M3_MAX = 448.0
@torch.no_grad()
def _update_amax_history(amax_history: Tensor, cur_abs_max: Tensor) -> Tensor:
out = torch.roll(amax_history, shifts=-1, dims=0)
out[-1] = cur_abs_max.to(dtype=out... | reference/53_fp8_allgather_params.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
54 | 54_ring_attention | from typing import Optional, Tuple
import torch
import torch.distributed as dist
import torch.nn.functional as F
@torch.jit.script
def _update_out_and_lse(
out: torch.Tensor, lse: torch.Tensor,
block_out: torch.Tensor, block_lse: torch.Tensor,
) -> Tuple[torch.Tensor, torch.Tensor]:
block_out = block_ou... | reference/54_ring_attention.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
55 | 55_ring_attention_tp | from typing import Optional, Tuple
import torch
import torch.distributed as dist
import torch.nn.functional as F
@torch.jit.script
def _update_out_and_lse(
out: torch.Tensor, lse: torch.Tensor,
block_out: torch.Tensor, block_lse: torch.Tensor,
) -> Tuple[torch.Tensor, torch.Tensor]:
block_out = block_... | reference/55_ring_attention_tp.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
56 | 56_ring_attention_pp | from typing import Optional, Tuple
import torch
import torch.distributed as dist
import torch.nn.functional as F
@torch.jit.script
def _update_out_and_lse(
out: torch.Tensor, lse: torch.Tensor,
block_out: torch.Tensor, block_lse: torch.Tensor,
) -> Tuple[torch.Tensor, torch.Tensor]:
block_out = block_... | reference/56_ring_attention_pp.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
57 | 57_ring_attention_backward_dp | from typing import Optional, Tuple
import torch
import torch.distributed as dist
class RingComm:
def __init__(self, group: dist.ProcessGroup):
self._group = group
self._ops: list = []
self._reqs = None
self.rank = dist.get_rank(group)
self.world_size = dist.get_world_size(... | reference/57_ring_attention_backward_dp.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
58 | 58_openclip_contrastive_loss | from typing import Optional
import torch
import torch.distributed as dist
import torch.nn.functional as F
def _siglip_loss(
image_features: torch.Tensor,
text_features: torch.Tensor,
logit_scale: float,
logit_bias: float,
negative_only: bool,
) -> torch.Tensor:
batch = image_features.size(0)
... | reference/58_openclip_contrastive_loss.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
59 | 59_physicsnemo_distributed_rfft | from typing import Optional, Sequence
import torch
import torch.distributed as dist
def _all_to_all_transpose(
tensor: torch.Tensor,
split_dim: int,
group: dist.ProcessGroup,
) -> list[torch.Tensor]:
world_size = dist.get_world_size(group)
chunk = tensor.shape[split_dim] // world_size
send = ... | reference/59_physicsnemo_distributed_rfft.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
60 | 60_physicsnemo_distributed_irfft | from typing import Optional, Sequence
import torch
import torch.distributed as dist
import torch.nn.functional as F
def _all_to_all_transpose(
tensor: torch.Tensor,
split_dim: int,
group: dist.ProcessGroup,
) -> list[torch.Tensor]:
world_size = dist.get_world_size(group)
chunk = tensor.shape[spli... | reference/60_physicsnemo_distributed_irfft.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
61 | 61_gsplat_3d_gaussian_splatting | import math
from typing import List, Optional, Tuple, Union
import torch
import torch.distributed as dist
import torch.distributed.nn.functional as distF
import torch.nn.functional as F
from torch import Tensor
def _all_gather_int32(
world_size: int, value: Union[int, Tensor], device: Optional[torch.device] = No... | reference/61_gsplat_3d_gaussian_splatting.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
62 | 62_torchharmonics_spherical_convolution | from typing import List, Optional
import torch
import torch.distributed as dist
def _compute_split_shapes(size: int, num_chunks: int) -> List[int]:
if num_chunks == 1:
return [size]
chunk_size = (size + num_chunks - 1) // num_chunks
last_chunk_size = max(0, size - chunk_size * (num_chunks - 1))
... | reference/62_torchharmonics_spherical_convolution.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
63 | 63_deepmd_kalman_filter_optimizer | from typing import List, Tuple
import torch
import torch.distributed as dist
@torch.no_grad()
def solution(
H: List[torch.Tensor],
error: torch.Tensor,
weights: List[torch.Tensor],
P: List[torch.Tensor],
kalman_lambda: float,
kalman_nue: float = 0.9987,
) -> Tuple[List[torch.Tensor], List[tor... | reference/63_deepmd_kalman_filter_optimizer.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
64 | 64_gnn_neighbor_sampling | from typing import List, Optional, Tuple
import numpy as np
import torch
import torch.distributed as dist
def _sample_one_hop_csc_dist(
input_nodes: torch.Tensor,
k: int,
colptr: torch.Tensor,
row: torch.Tensor,
replace: bool = False,
) -> Tuple[torch.Tensor, torch.Tensor, List[int]]:
n = inp... | reference/64_gnn_neighbor_sampling.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
65 | 65_gnn_feature_exchange_all2all | from typing import List, Optional
import torch
import torch.distributed as dist
def _shift(chunks: List[torch.Tensor], group: dist.ProcessGroup) -> List[torch.Tensor]:
cutoff = len(chunks) - dist.get_rank(group)
return chunks[cutoff:] + chunks[:cutoff]
def _all_to_all(
outputs: List[torch.Tensor],
... | reference/65_gnn_feature_exchange_all2all.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
66 | 66_gnn_feature_exchange_all2all_backward | from typing import List, Optional
import torch
import torch.distributed as dist
def _shift(chunks: List[torch.Tensor], group: dist.ProcessGroup) -> List[torch.Tensor]:
cutoff = len(chunks) - dist.get_rank(group)
return chunks[cutoff:] + chunks[:cutoff]
def _all_to_all(
outputs: List[torch.Tensor],
... | reference/66_gnn_feature_exchange_all2all_backward.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
67 | 67_gnn_sparse_embedding_all2all | from typing import Optional, Tuple
import torch
import torch.distributed as dist
def _generate_permutation_remainder(
idx: torch.Tensor,
world_size: int,
) -> Tuple[torch.Tensor, torch.Tensor]:
owner = (idx % world_size).long()
send_splits = torch.bincount(owner, minlength=world_size)
perm = torc... | reference/67_gnn_sparse_embedding_all2all.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
68 | 68_gnn_sparse_feature_fetch_projection | from typing import Optional
import torch
import torch.distributed as dist
@torch.no_grad()
def solution(
local_embedding_shard: torch.Tensor,
input_node_ids: torch.Tensor,
proj_matrix: torch.Tensor,
num_total_nodes: int,
group: Optional[dist.ProcessGroup] = None,
) -> torch.Tensor:
group = gr... | reference/68_gnn_sparse_feature_fetch_projection.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
69 | 69_gnn_negative_scoring | from typing import Optional
import torch
import torch.distributed as dist
def _broadcast_data(
rank: int,
world_size: int,
data: torch.Tensor,
group: dist.ProcessGroup,
) -> torch.Tensor:
if world_size == 1:
return data
sizes = torch.zeros(world_size, dtype=torch.long, device=data.de... | reference/69_gnn_negative_scoring.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
70 | 70_torchrec_kjt_all2all | from typing import Dict, List, Optional, Tuple
import torch
import torch.distributed as dist
def _sum_by_splits(values: List[int], splits: List[int]) -> List[int]:
out: List[int] = []
offset = 0
for split in splits:
out.append(sum(values[offset : offset + split]))
offset += split
retu... | reference/70_torchrec_kjt_all2all.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
71 | 71_hyena_conv1d_boundary_exchange | from typing import Optional, Tuple
import torch
import torch.distributed as dist
import torch.nn.functional as F
def _zigzag_get_overlapping_patches(
data: torch.Tensor,
seq_dim: int,
overlap_size: int,
) -> Tuple[torch.Tensor, torch.Tensor]:
shape = list(data.shape)
shape[seq_dim : seq_dim + 1] ... | reference/71_hyena_conv1d_boundary_exchange.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
72 | 72_hyena_forward_cp | from typing import Optional
import torch
import torch.distributed as dist
def _zigzag_indices(num_chunks: int, device: torch.device) -> torch.Tensor:
half = (num_chunks + 1) // 2
left = torch.arange(half, device=device)
right = torch.arange(num_chunks - 1, half - 1, -1, device=device)
indices = torch... | reference/72_hyena_forward_cp.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
73 | 73_vocab_parallel_cross_entropy_loss | from typing import Optional, Tuple
import torch
import torch.distributed as dist
def _vocab_range(partition_vocab_size: int, rank: int) -> Tuple[int, int]:
start = rank * partition_vocab_size
return start, start + partition_vocab_size
@torch.no_grad()
def solution(
vocab_parallel_logits: torch.Tensor,
... | reference/73_vocab_parallel_cross_entropy_loss.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
74 | 74_fla_kimi_delta_attention_cp_tp | from typing import Optional
import torch
import torch.distributed as dist
import torch.nn.functional as F
def _all_gather_sequence(x: torch.Tensor, group: dist.ProcessGroup) -> torch.Tensor:
world_size = dist.get_world_size(group=group)
batch, local_seq = x.shape[:2]
out = torch.empty(
batch,
... | reference/74_fla_kimi_delta_attention_cp_tp.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
75 | 75_fla_gated_deltanet_cp | from typing import Optional
import torch
import torch.distributed as dist
import torch.nn.functional as F
def _a2a_sequence_to_heads(
x: torch.Tensor,
group: dist.ProcessGroup,
) -> torch.Tensor:
world_size = dist.get_world_size(group=group)
batch, local_seq, heads, dim = x.shape
local_heads = he... | reference/75_fla_gated_deltanet_cp.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
76 | 76_opensora_conv3d_allreduce | import math
from typing import List, Optional, Tuple, Union
import torch
import torch.distributed as dist
import torch.nn.functional as F
_CONV3D_NUMEL_LIMIT = 2**31
def _to_3tuple(value: Union[int, Tuple[int, int, int]]) -> Tuple[int, int, int]:
return (value, value, value) if isinstance(value, int) else value... | reference/76_opensora_conv3d_allreduce.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
77 | 77_magi1_cso_async_attention | from typing import List, Optional
import torch
import torch.distributed as dist
import torch.nn.functional as F
def _a2a_rows(
tensor: torch.Tensor,
split_sizes: List[int],
group: dist.ProcessGroup,
) -> torch.Tensor:
out = torch.empty_like(tensor)
dist.all_to_all_single(
out,
ten... | reference/77_magi1_cso_async_attention.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
78 | 78_magi1_tile_parallel_vae_decode | from typing import List, Optional, Tuple
import torch
import torch.distributed as dist
import torch.nn.functional as F
def _index_undot(index: int, loop_size: List[int]) -> List[int]:
out: List[int] = []
for size in reversed(loop_size):
out.append(index % size)
index //= size
return list(... | reference/78_magi1_tile_parallel_vae_decode.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
79 | 79_dinov2_distributed_knn | from typing import List, Optional, Tuple
import torch
import torch.distributed as dist
def _topk_with_labels(
similarity: torch.Tensor,
labels: torch.Tensor,
k: int,
) -> Tuple[torch.Tensor, torch.Tensor]:
topk_sims, indices = similarity.topk(k, dim=1, largest=True, sorted=True)
topk_labels = tor... | reference/79_dinov2_distributed_knn.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
80 | 80_dinov2_distributed_sinkhorn_knopp | from typing import Optional
import torch
import torch.distributed as dist
@torch.no_grad()
def solution(
teacher_output: torch.Tensor,
teacher_temp: float,
n_masked_patches_tensor: torch.Tensor,
n_iterations: int = 3,
group: Optional[dist.ProcessGroup] = None,
) -> torch.Tensor:
group = group... | reference/80_dinov2_distributed_sinkhorn_knopp.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
81 | 81_sam3_allgather_iou_suppression | from typing import List, Optional, Tuple
import torch
import torch.distributed as dist
_NO_OBJ_LOGIT = -10.0
def _mask_iou(lhs: torch.Tensor, rhs: torch.Tensor) -> torch.Tensor:
lhs_flat = lhs.flatten(1).float()
rhs_flat = rhs.flatten(1).float()
intersection = lhs_flat @ rhs_flat.T
lhs_area = lhs_fl... | reference/81_sam3_allgather_iou_suppression.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
82 | 82_vocab_parallel_log_prob_topk | from typing import Optional
import torch
import torch.distributed as dist
import torch.nn.functional as F
def _apply_top_k_top_p(
logits: torch.Tensor,
top_k: Optional[int],
top_p: float,
) -> torch.Tensor:
need_k = top_k is not None and top_k > 0
need_p = top_p is not None and top_p < 1.0
... | reference/82_vocab_parallel_log_prob_topk.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
83 | 83_vocab_parallel_log_prob_topk_chunked | from typing import Optional
import torch
import torch.distributed as dist
import torch.nn.functional as F
def _apply_top_k_top_p(
logits: torch.Tensor,
top_k: Optional[int],
top_p: float,
) -> torch.Tensor:
need_k = top_k is not None and top_k > 0
need_p = top_p is not None and top_p < 1.0
if... | reference/83_vocab_parallel_log_prob_topk_chunked.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
84 | 84_vocab_parallel_log_prob_topk_chunked_backward | from typing import Optional, Tuple
import torch
import torch.distributed as dist
import torch.nn.functional as F
def _apply_top_k_top_p(
logits: torch.Tensor,
top_k: Optional[int],
top_p: float,
) -> Tuple[torch.Tensor, Optional[torch.Tensor]]:
need_k = top_k is not None and top_k > 0
need_p = to... | reference/84_vocab_parallel_log_prob_topk_chunked_backward.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
85 | 85_distributed_sample_sort | from typing import List, Optional, Tuple
import torch
import torch.distributed as dist
def _local_sizes(group: dist.ProcessGroup, device: torch.device, local_n: int) -> List[int]:
world_size = dist.get_world_size(group=group)
size = torch.tensor([local_n], dtype=torch.long, device=device)
gathered = [tor... | reference/85_distributed_sample_sort.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
86 | 86_tp_muon_orthogonalization | from typing import Optional, Sequence
import torch
import torch.distributed as dist
_COEFFICIENTS: dict[str, Sequence[tuple[float, float, float]]] = {
"simple": ((3.4445, -4.7750, 2.0315),),
"quintic": (
(4.0848, -6.8946, 2.9270),
(3.9505, -6.3029, 2.6377),
(3.7418, -5.5913, 2.3037),
... | reference/86_tp_muon_orthogonalization.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
87 | 87_conv2d_boundary_exchange | from typing import Optional
import torch
import torch.distributed as dist
import torch.nn.functional as F
def _gather_boundaries(
x: torch.Tensor,
boundary: int,
group: dist.ProcessGroup,
) -> list[torch.Tensor]:
if boundary == 0:
empty = x[:, :, :0, :]
return [torch.stack([empty, emp... | reference/87_conv2d_boundary_exchange.py | utils/input_output_tensors.py | 4 | 1,024 | 1,024 | bfloat16 | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.