Skip to content
KernelIndex
Search⌘K

PyTorch eager

PyTorch · python · MIT

Use it

Vendorable · source mirrored · MITView source →

No package. Vendor the mirrored source: 36 lines, MIT.

46_Conv2d_Subtract_Tanh_Subtract_AvgPool.py
curl "https://kernelindex.com/api/v1/implementations/kernelbench-l2-46-conv2d-subtract-tanh-subtract-avgpool-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
Conv2d Subtract Tanh Subtract AvgPoolfp32 · [128, 64, 128, 128]
NVIDIA H100
5.65ms±0.00
#2 of 2
2026-03-05
Conv2d Subtract Tanh Subtract AvgPoolfp32 · [128, 64, 128, 128]
NVIDIA H100
9.32ms±0.02
#2 of 2
2026-03-05

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:5e2707a8c4002bb649fa7887968e6e5a15ead61534f624b7fd5c2d77fada9d66
license declaredMIT
license concludedMIT
imported2026-08-26

Kernel source

46_Conv2d_Subtract_Tanh_Subtract_AvgPool.py36 lines
import torch
import torch.nn as nn

class Model(nn.Module):
    """
    Model that performs a convolution, subtraction, tanh activation, subtraction and average pooling.
    """
    def __init__(self, in_channels, out_channels, kernel_size, subtract1_value, subtract2_value, kernel_size_pool):
        super(Model, self).__init__()
        self.conv = nn.Conv2d(in_channels, out_channels, kernel_size)
        self.subtract1_value = subtract1_value
        self.subtract2_value = subtract2_value
        self.avgpool = nn.AvgPool2d(kernel_size_pool)

    def forward(self, x):
        x = self.conv(x)
        x = x - self.subtract1_value
        x = torch.tanh(x)
        x = x - self.subtract2_value
        x = self.avgpool(x)
        return x

batch_size = 128
in_channels = 64
out_channels = 128
height, width = 128, 128
kernel_size = 3
subtract1_value = 0.5
subtract2_value = 0.2
kernel_size_pool = 2

def get_inputs():
    return [torch.rand(batch_size, in_channels, height, width)]

def get_init_inputs():
    return [in_channels, out_channels, kernel_size, subtract1_value, subtract2_value, kernel_size_pool]
scrolls · 36 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