PyTorch eager
PyTorch · python · MIT
Use it
Vendorable · source mirrored · MITView source →
No package. Vendor the mirrored source: 40 lines, MIT.
40_LayerNorm.py
curl "https://kernelindex.com/api/v1/implementations/kernelbench-l1-40-layernorm-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:864e49c805e09ecb9616eb7d1223e8fb34c71793de1d989884964a05ac0efbbd
license declaredMIT
license concludedMIT
imported2026-08-26
Kernel source
40_LayerNorm.py40 lines
import torch
import torch.nn as nn
class Model(nn.Module):
"""
Simple model that performs Layer Normalization.
"""
def __init__(self, normalized_shape: tuple):
"""
Initializes the LayerNorm layer.
Args:
normalized_shape (tuple): Shape of the input tensor to be normalized.
"""
super(Model, self).__init__()
self.ln = nn.LayerNorm(normalized_shape=normalized_shape)
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""
Applies Layer Normalization to the input tensor.
Args:
x (torch.Tensor): Input tensor of shape (*, normalized_shape).
Returns:
torch.Tensor: Output tensor with Layer Normalization applied, same shape as input.
"""
return self.ln(x)
batch_size = 16
features = 64
dim1 = 256
dim2 = 256
def get_inputs():
x = torch.rand(batch_size, features, dim1, dim2)
return [x]
def get_init_inputs():
return [(features, dim1, dim2)]scrolls · 40 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