PyTorch eager
PyTorch · python · MIT
Use it
Vendorable · source mirrored · MITView source →
No package. Vendor the mirrored source: 43 lines, MIT.
40_Matmul_Scaling_ResidualAdd.py
curl "https://kernelindex.com/api/v1/implementations/kernelbench-l2-40-matmul-scaling-residualadd-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.
Operation / workload
Hardware
Latency
Rank
Observed
Reported · How evidence levels are derived →
Source and license
sourceavailable
revision digestsha256:37cf47a0092052ea27b137fc27f5ccdf46685c5a64abbfbab2686891bf45c6e0
license declaredMIT
license concludedMIT
imported2026-08-26
Kernel source
40_Matmul_Scaling_ResidualAdd.py43 lines
import torch
import torch.nn as nn
class Model(nn.Module):
"""
A model that performs a matrix multiplication, scaling, and residual addition.
Args:
in_features (int): Number of input features.
out_features (int): Number of output features.
scaling_factor (float): Scaling factor to apply after matrix multiplication.
"""
def __init__(self, in_features, out_features, scaling_factor):
super(Model, self).__init__()
self.matmul = nn.Linear(in_features, out_features)
self.scaling_factor = scaling_factor
def forward(self, x):
"""
Forward pass of the model.
Args:
x (torch.Tensor): Input tensor of shape (batch_size, in_features).
Returns:
torch.Tensor: Output tensor of shape (batch_size, out_features).
"""
x = self.matmul(x)
original_x = x.clone().detach()
x = x * self.scaling_factor
x = x + original_x
return x
batch_size = 16384
in_features = 4096
out_features = 4096
scaling_factor = 0.5
def get_inputs():
return [torch.rand(batch_size, in_features)]
def get_init_inputs():
return [in_features, out_features, scaling_factor]scrolls · 43 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