kernel-train-problems / problems /kb1_024_logsoftmax__bf16.py
K1ta141k's picture
Upload 140 train problems and 140 Verifier-v2-verified clean teacher traces
3e697eb verified
Raw History Blame Contribute Delete
1.47 kB
"""Task kb1_024_logsoftmax__bf16 (KernelBench Level 1 #24, split=train, category=activation, dtype=bf16, variant=bf16)."""
PROBLEM_ID = "kb1_024_logsoftmax__bf16"
SOURCE_KB_ID = 24
CATEGORY = "activation"
SPLIT = "train"
DTYPE = "bf16"
VARIANT = "bf16"
import torch
import torch.nn as nn
class Model(nn.Module):
"""
Simple model that performs a LogSoftmax activation.
"""
def __init__(self, dim: int = 1):
super(Model, self).__init__()
self.dim = dim
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""
Applies LogSoftmax activation to the input tensor.
Args:
x (torch.Tensor): Input tensor of shape (batch_size, dim).
Returns:
torch.Tensor: Output tensor with LogSoftmax applied, same shape as input.
"""
return torch.log_softmax(x, dim=self.dim)
batch_size = 4096
dim = 393216
# --- Task shape configuration (4GB-safe laptop envelope) ---
batch_size = 2048
dim = 4096
def get_inputs():
x = torch.randn(batch_size, dim)
return [x]
def get_init_inputs():
return [] # No special initialization inputs needed
if __name__ == "__main__":
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
from verifier import verify_kernel, format_result
res = verify_kernel(None, __file__, self_check=True)
print(format_result(res))
sys.exit(0 if res["status"] == "PASS" else 1)