PyTorch eager
PyTorch · python · MIT
Kernel source · 57 lines ↓holds 1 record
Use it
Vendorable · source mirrored · MITView source →
No package. Vendor the mirrored source: 57 lines, MIT.
89_cumsum.py
curl "https://kernelindex.com/api/v1/implementations/kernelbench-l1-89-cumsum-torch?include=source"interfacepython · torch_eager
symbolModel.forward
Compatibility
measured onNVIDIA H100
declared hardwaredeclared only
architectures—
dtypes
Benchmark evidence
2 measurements across 1 GPU, fastest first.
Reported · How evidence levels are derived →
Source and license
sourceavailable
revision digestsha256:9dd35635047ad5d876fc89c598ba8d4f3c21784adb6773e414bfc0422a6fc1df
license declaredMIT
license concludedMIT
imported2026-08-26
Kernel source
89_cumsum.py57 lines
import torch
import torch.nn as nn
class Model(nn.Module):
"""
A simple model that performs a cumulative sum (prefix sum) operation along a specified dimension.
Parameters:
dim (int): The dimension along which to perform the scan operation.
"""
def __init__(self, dim):
"""
Initialize the Scan model.
Args:
dim (int): The dimension along which to perform the cumulative sum.
"""
super(Model, self).__init__()
self.dim = dim
def forward(self, x):
"""
Forward pass for the Scan model, computing the cumulative sum along the specified dimension.
Args:
x (torch.Tensor): Input tensor of shape (batch_size, *input_shape), where `*input_shape`
can vary depending on the use case.
Returns:
torch.Tensor: Tensor of the same shape as `x` after applying cumulative sum along `dim`.
"""
return torch.cumsum(x, dim=self.dim)
# Define input dimensions and parameters
batch_size = 32768
input_shape = (32768,)
dim = 1
def get_inputs():
"""
Generates random inputs for testing the Scan model.
Returns:
list: A list containing a single randomly generated tensor with shape
(batch_size, *input_shape).
"""
return [torch.rand(batch_size, *input_shape)]
def get_init_inputs():
"""
Returns the initialization parameters for the Scan model.
Returns:
list: A list containing the `dim` parameter for model initialization.
"""
return [dim]scrolls · 57 lines total
Source code from KernelBench, © 2023 Anne Ouyang, Simon Guo, Azalia Mirhoseini (Scaling Intelligence Lab, Stanford University), MIT License · MIT
Best evidence level for this revision: reported
JSON