torch.compile (inductor)
PyTorch · python · MIT
Kernel source · 60 lines ↓holds 2 records
Use it
Vendorable · source mirrored · MITView source →
No package. Vendor the mirrored source: 60 lines, MIT.
4_LeNet5.py
curl "https://kernelindex.com/api/v1/implementations/kernelbench-l3-4-lenet5-torch-compile-inductor?include=source"interfacepython · torch_compile_inductor
symbolModel.forward
Compatibility
measured onNVIDIA H100
declared hardwaredeclared only
architectures—
dtypes
Benchmark evidence
2 measurements across 1 GPU, fastest first.
Reported · How evidence levels are derived →
Source and license
sourceavailable
revision digestsha256:35897f9dd8956675fe47a52795219dfa5f145952caef67c271c15214cb708b33
license declaredMIT
license concludedMIT
imported2026-08-26
Kernel source
4_LeNet5.py60 lines
import torch
import torch.nn as nn
import torch.nn.functional as F
class Model(nn.Module):
def __init__(self, num_classes):
"""
LeNet-5 architecture implementation in PyTorch.
:param num_classes: The number of output classes.
"""
super(Model, self).__init__()
# Convolutional layers
self.conv1 = nn.Conv2d(in_channels=1, out_channels=6, kernel_size=5, stride=1)
self.conv2 = nn.Conv2d(in_channels=6, out_channels=16, kernel_size=5, stride=1)
# Fully connected layers
self.fc1 = nn.Linear(in_features=16*5*5, out_features=120)
self.fc2 = nn.Linear(in_features=120, out_features=84)
self.fc3 = nn.Linear(in_features=84, out_features=num_classes)
def forward(self, x):
"""
Forward pass of the LeNet-5 model.
:param x: The input tensor, shape (batch_size, 1, 32, 32)
:return: The output tensor, shape (batch_size, num_classes)
"""
# First convolutional layer with ReLU activation and max pooling
x = F.relu(self.conv1(x))
x = F.max_pool2d(x, kernel_size=2, stride=2)
# Second convolutional layer with ReLU activation and max pooling
x = F.relu(self.conv2(x))
x = F.max_pool2d(x, kernel_size=2, stride=2)
# Flatten the output for the fully connected layers
x = x.view(-1, 16*5*5)
# First fully connected layer with ReLU activation
x = F.relu(self.fc1(x))
# Second fully connected layer with ReLU activation
x = F.relu(self.fc2(x))
# Final fully connected layer
x = self.fc3(x)
return x
# Test code for the LeNet-5 model (larger batch & image)
batch_size = 4096
num_classes = 20
def get_inputs():
return [torch.rand(batch_size, 1, 32, 32)]
def get_init_inputs():
return [num_classes]scrolls · 60 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