PyTorch eager
PyTorch · python · MIT
Use it
Vendorable · source mirrored · MITView source →
No package. Vendor the mirrored source: 85 lines, MIT.
18_SqueezeNet.py
curl "https://kernelindex.com/api/v1/implementations/kernelbench-l3-18-squeezenet-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:1498c60f39760f0b120e9b903ba676848b63154bfc4b4779f791601b0a694d91
license declaredMIT
license concludedMIT
imported2026-08-26
Kernel source
18_SqueezeNet.py85 lines
import torch
import torch.nn as nn
import torch.nn.functional as F
class FireModule(nn.Module):
def __init__(self, in_channels, squeeze_channels, expand1x1_channels, expand3x3_channels):
"""
:param in_channels: Number of input channels
:param squeeze_channels: Number of output channels for the squeeze layer
:param expand1x1_channels: Number of output channels for the 1x1 expand layer
:param expand3x3_channels: Number of output channels for the 3x3 expand layer
"""
super(FireModule, self).__init__()
self.squeeze = nn.Conv2d(in_channels, squeeze_channels, kernel_size=1)
self.squeeze_activation = nn.ReLU(inplace=True)
self.expand1x1 = nn.Conv2d(squeeze_channels, expand1x1_channels, kernel_size=1)
self.expand1x1_activation = nn.ReLU(inplace=True)
self.expand3x3 = nn.Conv2d(squeeze_channels, expand3x3_channels, kernel_size=3, padding=1)
self.expand3x3_activation = nn.ReLU(inplace=True)
def forward(self, x):
"""
:param x: Input tensor, shape (batch_size, in_channels, height, width)
:return: Output tensor, shape (batch_size, expand1x1_channels + expand3x3_channels, height, width)
"""
x = self.squeeze_activation(self.squeeze(x))
return torch.cat([
self.expand1x1_activation(self.expand1x1(x)),
self.expand3x3_activation(self.expand3x3(x))
], 1)
class Model(nn.Module):
def __init__(self, num_classes=1000):
"""
:param num_classes: Number of output classes
"""
super(Model, self).__init__()
self.features = nn.Sequential(
nn.Conv2d(3, 96, kernel_size=7, stride=2),
nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
FireModule(96, 16, 64, 64),
FireModule(128, 16, 64, 64),
FireModule(128, 32, 128, 128),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
FireModule(256, 32, 128, 128),
FireModule(256, 48, 192, 192),
FireModule(384, 48, 192, 192),
FireModule(384, 64, 256, 256),
nn.MaxPool2d(kernel_size=3, stride=2, ceil_mode=True),
FireModule(512, 64, 256, 256),
)
self.classifier = nn.Sequential(
nn.Dropout(p=0.0),
nn.Conv2d(512, num_classes, kernel_size=1),
nn.ReLU(inplace=True),
nn.AdaptiveAvgPool2d((1, 1))
)
def forward(self, x):
"""
:param x: Input tensor, shape (batch_size, 3, height, width)
:return: Output tensor, shape (batch_size, num_classes)
"""
x = self.features(x)
x = self.classifier(x)
return torch.flatten(x, 1)
# Test code
batch_size = 64
input_channels = 3
height = 512
width = 512
num_classes = 1000
def get_inputs():
return [torch.rand(batch_size, input_channels, height, width)]
def get_init_inputs():
return [num_classes]scrolls · 85 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