error
32_argmax_tiebreak_smallest_rank.py
started
2026-05-02T10:28:32Z
reference PyTorch source (the prompt the agent sees)
"""
Over virtual ranks R, for each (B, C) position take the maximum value; on ties choose the smallest rank index.
Output (B, C, 2): [:,:,0] = best value, [:,:,1] = winning rank as float32.
"""
import torch
import torch.nn as nn
from kernelbench.distributed_collectives import default_device
R = 4
B = 8
C = 28
class Model(nn.Module):
def __init__(self):
super().__init__()
def forward(self, x: torch.Tensor) -> torch.Tensor:
# x: (R, B, C)
best_val = x[0].clone()
best_idx = torch.zeros(B, C, dtype=torch.long, device=x.device)
for r in range(1, R):
xv = x[r]
improved = xv > best_val
tied = (xv == best_val) & ~improved
best_idx = torch.where(
improved,
torch.full_like(best_idx, r),
torch.where(
tied,
torch.minimum(best_idx, torch.full_like(best_idx, r)),
best_idx,
),
)
best_val = torch.where(improved, xv, best_val)
stacked = torch.stack([best_val, best_idx.to(best_val.dtype)], dim=-1)
return stacked
def get_inputs():
dev = default_device()
p = popcorn_pri
return [torch.randn(R, p.jitter_int(B), p.jitter_int(C), device=dev)]
def get_init_inputs():
return []
turn 0385.1s turn · 385.1s LLM · 0.0s tools
feedbackLLM call failed: Empty: