Datasets:
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 |
End of preview. Expand in Data Studio
ParallelKernelBench (benchmark)
Reference problems for ParallelKernelBench: a benchmark for LLM-generated multi-GPU CUDA kernels.
This dataset contains 87 reference implementations in reference/ and the input tensor specification in utils/input_output_tensors.py.
Files
| Path | Description |
|---|---|
data/problems.parquet |
One row per problem (tabular access) |
reference/*.py |
Reference solution() implementations |
utils/input_output_tensors.py |
Input/output tensor generation for every problem |
Columns (data/problems.parquet)
problem_id,stem— problem identityreference_code— full Python sourcereference_path— path to the same file in this repoinput_tensor_spec_path— path toutils/input_output_tensors.py(same on every row)world_size,default_m,default_n,default_dtype,default_trials— default eval settings (8× H100, 1024×1024, bfloat16, 5 trials)
Usage
from datasets import load_dataset
from huggingface_hub import hf_hub_download
ds = load_dataset("willychan21/ParallelKernelBench_Problems", split="train")
print(ds[0]["stem"], ds[0]["reference_code"][:200])
# Fetch the input tensor spec (same file on disk in this dataset repo)
spec_path = hf_hub_download("willychan21/ParallelKernelBench_Problems", "utils/input_output_tensors.py", repo_type="dataset")
Reproduce inputs locally (add the downloaded utils/ folder to PYTHONPATH, or clone this repo):
from utils.input_output_tensors import create_input_tensor
import torch
x = create_input_tensor(
rank=0, world_size=8, problem_id=17,
base_shape=(1024, 1024), dtype=torch.bfloat16,
)
Related
Net-new LLM-generated kernels live in a separate dataset repo (ParallelKernelBench_Kernels) containing only solutions/<run_id>/*.py.
Eval
python run_local.py --mode eval --problem 17 --solution cuda \
--solutions-root path/to/solutions_dir --dtype bfloat16 --trials 5
- Downloads last month
- 19