KernelZero
Collection
4 items • Updated
input stringlengths 14.7k 17.7k | output stringlengths 3.39k 39.3k | torch_module stringlengths 241 3.29k | cuda_code stringlengths 1.75k 34.3k | speedup float64 0 4.25k | operators listlengths 1 8 | source_stage stringclasses 2
values | source_index int64 1 80.9k |
|---|---|---|---|---|---|---|---|
You are an expert in PyTorch and CUDA programming. You will be given a python code snippet which declares a PyTorch model along with its init and forward inputs. The model is an instance of class Model. It will be created with arguments from get_init_inputs(). Then its forward function will be called with data from get... | <think>We need to write a custom CUDA extension to accelerate forward: first torch.triu(x, diagonal=self.diagonal) then torch.unbind(x, dim=2). Input shape: (64,128,1024). triu along last two dimensions? torch.triu works on 2D matrices; for batched, it applies to last two dims. Here x shape (64,128,1024): treat each 2D... | import torch
class Model(torch.nn.Module):
def __init__(self, input_size, diagonal):
super(Model, self).__init__()
self.diagonal = diagonal
def forward(self, x):
x = torch.triu(x, diagonal=self.diagonal)
x = torch.unbind(x, dim=2)
return x
def get_inputs():
retur... | import torch
import torch.nn as nn
from torch.utils.cpp_extension import load_inline
# ------------------- CUDA kernel source -------------------
cuda_source = r"""
#include <torch/extension.h>
#include <cuda_runtime.h>
#include <ATen/cuda/CUDAContext.h>
#ifndef CHECK_CUDA
#define CHECK_CUDA(x) TORCH_CHECK(x.is_cuda(... | 0.42 | [
"torch.triu",
"torch.unbind"
] | stage1 | 6 |
You are an expert in PyTorch and CUDA programming. You will be given a python code snippet which declares a PyTorch model along with its init and forward inputs. The model is an instance of class Model. It will be created with arguments from get_init_inputs(). Then its forward function will be called with data from get... | <think>We need to write a custom CUDA extension to replace forward: one-hot encoding then two minimum operations with constants. The model has no parameters (just constants). So we need to implement a kernel that takes input tensor of shape (input_size,) of integer indices, produces output tensor of shape (input_size, ... | import torch
import torch.nn as nn
import torch.nn.functional as F
class Model(nn.Module):
def __init__(self, num_classes, input_size, on_value, off_value):
super().__init__()
self.num_classes = num_classes
self.input_size = input_size
self.on_value = on_value
self.off_valu... | import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.cpp_extension import load_inline
# --------------------- CUDA kernel source ---------------------
cuda_source = r'''
#include <torch/extension.h>
#include <cuda_runtime.h>
#include <ATen/cuda/CUDAContext.h>
template <typename scalar_t... | 3.79 | [
"F.one_hot",
"torch.minimum"
] | stage1 | 1 |
You are an expert in PyTorch and CUDA programming. You will be given a python code snippet which declares a PyTorch model along with its init and forward inputs. The model is an instance of class Model. It will be created with arguments from get_init_inputs(). Then its forward function will be called with data from get... | <think>We need to write a custom CUDA extension to accelerate the forward of Model. Model forward: input = torch.repeat_interleave(input, self.repeats, self.dim); then return F.mse_loss(input, target). So we need to implement repeat_interleave and MSE loss (mean squared error) in CUDA kernel, without calling torch func... | import torch
import torch.nn as nn
import torch.nn.functional as F
class Model(nn.Module):
def __init__(self, repeats, dim):
super().__init__()
self.repeats = repeats
self.dim = dim
def forward(self, input, target):
input = torch.repeat_interleave(input, self.repeats, self.dim... | import torch
import torch.nn as nn
from torch.utils.cpp_extension import load_inline
# ------------------- CUDA kernel source -------------------
cuda_source = r"""
#include <torch/extension.h>
#include <cuda_runtime.h>
#include <ATen/cuda/CUDAContext.h>
#define WARP_SIZE 32
// Warp‑level reduction (sum)
__inline__ ... | 1.39 | [
"torch.repeat_interleave",
"F.mse_loss"
] | stage1 | 3 |
You are an expert in PyTorch and CUDA programming. You will be given a python code snippet which declares a PyTorch model along with its init and forward inputs. The model is an instance of class Model. It will be created with arguments from get_init_inputs(). Then its forward function will be called with data from get... | <think>We need to write a custom CUDA extension to accelerate forward of Model, which does two ConvTranspose1d operations with same weight/bias then logical_and of their boolean values and cast to float.
Constraints: No extra tensor parameters during init. Keep submodule names unchanged. So ModelNew should have same _... | import torch
import torch.nn as nn
import torch.nn.functional as F
class Model(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size, stride, padding, output_padding, bias):
super().__init__()
self.conv_transpose1d = nn.ConvTranspose1d(
in_channels,
out_chan... | import torch
import torch.nn as nn
from torch.utils.cpp_extension import load_inline
# ------------------- CUDA source -------------------
cuda_source = r'''
#include <torch/extension.h>
#include <cuda_runtime.h>
#include <ATen/cuda/CUDAContext.h>
#ifndef CHECK_CUDA
#define CHECK_CUDA(x) TORCH_CHECK(x.is_cuda(), #x "... | 5.34 | [
"torch.logical_and",
"F.conv_transpose1d"
] | stage1 | 10 |
You are an expert in PyTorch and CUDA programming. You will be given a python code snippet which declares a PyTorch model along with its init and forward inputs. The model is an instance of class Model. It will be created with arguments from get_init_inputs(). Then its forward function will be called with data from get... | <think>We need to write a custom CUDA extension to accelerate Model forward: apply SiLU activation then masked_select. Constraints: can't call torch functions except allocate/init tensors. Can't call torch.nn.functional. Must use parameters and attributes of submodule. Here submodule is nn.SiLU which has no parameters ... | import torch
import torch.nn as nn
class Model(nn.Module):
def __init__(self):
super().__init__()
self.silu = nn.SiLU()
def forward(self, x: torch.Tensor, mask: torch.Tensor) -> torch.Tensor:
x = self.silu(x)
x = torch.masked_select(x, mask)
return x
def get_inputs()... | import torch
import torch.nn as nn
from torch.utils.cpp_extension import load_inline
# ----------------------------------------------------------------------
# CUDA source: SiLU activation + masked_select (atomic‑based implementation)
# ----------------------------------------------------------------------
cuda_source... | 1.26 | [
"nn.SiLU",
"torch.masked_select"
] | stage1 | 22 |
"You are an expert in PyTorch and CUDA programming. You will be given a python code snippet which de(...TRUNCATED) | "<think>We need to write a custom CUDA extension to accelerate the forward function.\n\nModel forwar(...TRUNCATED) | "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\n\nclass Model(nn.Module):\n(...TRUNCATED) | "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\n\n# -------(...TRUNCATED) | 1.87 | [
"torch.addcmul",
"torch.count_nonzero"
] | stage1 | 9 |
"You are an expert in PyTorch and CUDA programming. You will be given a python code snippet which de(...TRUNCATED) | "<think>We need to write a custom CUDA extension to replace forward: clamp then tan. Must not call t(...TRUNCATED) | "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\n\nclass Model(nn.Module):\n(...TRUNCATED) | "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\n\n# -------(...TRUNCATED) | 1.36 | [
"torch.clamp",
"torch.tan"
] | stage1 | 57 |
"You are an expert in PyTorch and CUDA programming. You will be given a python code snippet which de(...TRUNCATED) | "<think>We need to write a custom CUDA extension that implements forward of Model: repeat_interleave(...TRUNCATED) | "import torch\n\n\nclass Model(torch.nn.Module):\n def __init__(self, repeats, dim, mask_value, a(...TRUNCATED) | "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\n\n# -------(...TRUNCATED) | 7.14 | [
"torch.repeat_interleave",
"torch.abs",
"torch.masked_fill"
] | stage1 | 30 |
"You are an expert in PyTorch and CUDA programming. You will be given a python code snippet which de(...TRUNCATED) | "<think>We need to write a custom CUDA extension to accelerate forward of Model. The forward does:\n(...TRUNCATED) | "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\n\n\nclass Model(nn.Module):\n(...TRUNCATED) | "import torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom torch.utils.cpp_extensio(...TRUNCATED) | 1.58 | [
"F.silu",
"torch.nansum",
"torch.all",
"torch.cos"
] | stage1 | 31 |
"You are an expert in PyTorch and CUDA programming. You will be given a python code snippet which de(...TRUNCATED) | "<think>We need to write a custom CUDA extension that replicates the forward of Model: batch_norm, h(...TRUNCATED) | "import torch\nimport torch.nn as nn\n\n\nclass Model(nn.Module):\n def __init__(self, num_featur(...TRUNCATED) | "import torch\nimport torch.nn as nn\nfrom torch.utils.cpp_extension import load_inline\n\n# -------(...TRUNCATED) | 2.68 | [
"nn.BatchNorm2d",
"nn.Hardswish",
"nn.ReflectionPad2d",
"nn.GELU"
] | stage1 | 18 |
KernelZero CUDA SFT contains the 43,302 examples used for the two-stage supervised cold start of the KernelZero CUDA Coder. The dataset accompanies KernelZero: Co-Evolving Proposer and Coder for Continuously Improved GPU Kernel Generation.
| Stage | Examples | Description |
|---|---|---|
| Stage 1 | 24,073 | Initial CUDA reasoning SFT |
| Stage 2 | 19,229 | Continued CUDA SFT with later validated generations |
| Total | 43,302 | Unique training examples |
Every released example passed response-format checking, CUDA compilation, and numerical validation against its PyTorch reference on the original evaluation infrastructure.
| Field | Type | Description |
|---|---|---|
input |
string | Exact SFT input prompt, including the target PyTorch module and CUDA optimization instructions |
output |
string | Exact SFT target response, including reasoning and the generated implementation |
torch_module |
string | Standalone reference PyTorch module |
cuda_code |
string | Generated CUDA/Python implementation with the outer Markdown code fence removed when present |
speedup |
float64 | Measured speedup over the PyTorch reference on an NVIDIA A100-80GB GPU |
operators |
list[string] | Torch operators represented by the example |
source_stage |
string | SFT stage from which the example originates |
source_index |
int64 | Original source index within the CudaLLM-derived corpus |
from datasets import load_dataset
dataset = load_dataset("kcxain/KernelZero-CUDA-SFT", split="train")
print(dataset[0])
The speedup field preserves the measurement stored with each accepted training example. Runtime measurements are hardware- and software-dependent. Reproduction should use the KernelZero validation environment and the same A100-80GB target.
@article{kernelzero2026,
title={KernelZero: Co-Evolving Proposer and Coder for Continuously Improved GPU Kernel Generation},
author={Ke, Changxin and Zhang, Rui and Fang, Zixiang and Li, Zhenghong and Wen, Yuanbo and Shen, Jiashuo and Wang, Shuo and Guo, Jiaming and Li, Ling and Guo, Qi and Chen, Yunji},
journal={arXiv preprint arXiv:2609.33074},
year={2026}
}