PyTorch eager
PyTorch · python · MIT
Use it
Vendorable · source mirrored · MITView source →
No package. Vendor the mirrored source: 41 lines, MIT.
82_Conv2d_Tanh_Scaling_BiasAdd_Max.py
curl "https://kernelindex.com/api/v1/implementations/kernelbench-l2-82-conv2d-tanh-scaling-biasadd-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:efecbca5c5a2da94e157433ceb233c45d1ff90b3f8b2c8e5df6060ddd2385708
license declaredMIT
license concludedMIT
imported2026-08-26
Kernel source
82_Conv2d_Tanh_Scaling_BiasAdd_Max.py41 lines
import torch
import torch.nn as nn
class Model(nn.Module):
"""
A model that performs a convolution, applies tanh, scaling, adds a bias term, and then max-pools.
"""
def __init__(self, in_channels, out_channels, kernel_size, scaling_factor, bias_shape, pool_kernel_size):
super(Model, self).__init__()
self.conv = nn.Conv2d(in_channels, out_channels, kernel_size)
self.scaling_factor = scaling_factor
self.bias = nn.Parameter(torch.randn(bias_shape))
self.max_pool = nn.MaxPool2d(pool_kernel_size)
def forward(self, x):
# Convolution
x = self.conv(x)
# Tanh activation
x = torch.tanh(x)
# Scaling
x = x * self.scaling_factor
# Bias addition
x = x + self.bias
# Max-pooling
x = self.max_pool(x)
return x
batch_size = 128
in_channels = 8
out_channels = 64
height, width = 256, 256
kernel_size = 3
scaling_factor = 2.0
bias_shape = (out_channels, 1, 1)
pool_kernel_size = 4
def get_inputs():
return [torch.rand(batch_size, in_channels, height, width)]
def get_init_inputs():
return [in_channels, out_channels, kernel_size, scaling_factor, bias_shape, pool_kernel_size]scrolls · 41 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