PyTorch eager
PyTorch · python · MIT
Kernel source · 39 lines ↓holds 1 record
Use it
Vendorable · source mirrored · MITView source →
No package. Vendor the mirrored source: 39 lines, MIT.
98_Matmul_AvgPool_GELU_Scale_Max.py
curl "https://kernelindex.com/api/v1/implementations/kernelbench-l2-98-matmul-avgpool-gelu-scale-max-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:7e9a462e0696b1232fea7c49bc531970607685fb344e86bee9c6de6dc0b501fd
license declaredMIT
license concludedMIT
imported2026-08-26
Kernel source
98_Matmul_AvgPool_GELU_Scale_Max.py39 lines
import torch
import torch.nn as nn
class Model(nn.Module):
"""
A model implementing the pattern "Matmul_AvgPool_GELU_Scale_Max".
"""
def __init__(self, in_features, out_features, pool_kernel_size, scale_factor):
super(Model, self).__init__()
self.matmul = nn.Linear(in_features, out_features)
self.avg_pool = nn.AvgPool1d(kernel_size=pool_kernel_size)
self.scale_factor = scale_factor
def forward(self, x):
"""
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)
x = self.avg_pool(x.unsqueeze(1)).squeeze(1)
x = torch.nn.functional.gelu(x)
x = x * self.scale_factor
x = torch.max(x, dim=1).values
return x
batch_size = 1024
in_features = 8192
out_features = 8192
pool_kernel_size = 16
scale_factor = 2.0
def get_inputs():
return [torch.rand(batch_size, in_features)]
def get_init_inputs():
return [in_features, out_features, pool_kernel_size, scale_factor]scrolls · 39 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