torch.compile (inductor)
PyTorch · python · MIT
Kernel source · 73 lines ↓holds 2 records
Use it
Vendorable · source mirrored · MITView source →
No package. Vendor the mirrored source: 73 lines, MIT.
27_RegNet.py
curl "https://kernelindex.com/api/v1/implementations/kernelbench-l3-27-regnet-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:8bc8273ac778cf7c900fb08a31ed0aa1b64d125af4f24dea85a8e22927e8574d
license declaredMIT
license concludedMIT
imported2026-08-26
Kernel source
27_RegNet.py73 lines
import torch
import torch.nn as nn
import torch.nn.functional as F
class Model(nn.Module):
def __init__(self, input_channels, stages, block_widths, output_classes):
"""
:param input_channels: int, Number of input channels for the first layer
:param stages: int, Number of stages in the RegNet architecture
:param block_widths: List[int], Width (number of channels) for each block in the stages
:param output_classes: int, Number of output classes for classification
"""
super(Model, self).__init__()
self.stages = stages
self.block_widths = block_widths
layers = []
current_channels = input_channels
# Construct the stages with their respective blocks
for i in range(stages):
layers.append(self._make_stage(current_channels, block_widths[i]))
current_channels = block_widths[i]
self.feature_extractor = nn.Sequential(*layers)
# Final fully connected layer for classification
self.fc = nn.Linear(block_widths[-1], output_classes)
def _make_stage(self, in_channels, out_channels):
"""
Creates a simple block for each stage.
:param in_channels: int, number of input channels
:param out_channels: int, number of output channels
:return: nn.Sequential block with convolutional layers
"""
return nn.Sequential(
nn.Conv2d(in_channels, out_channels, kernel_size=3, padding=1),
nn.BatchNorm2d(out_channels),
nn.ReLU(),
nn.Conv2d(out_channels, out_channels, kernel_size=3, padding=1),
nn.BatchNorm2d(out_channels),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2)
)
def forward(self, x):
"""
Forward pass through the RegNet model.
:param x: torch.Tensor of shape (batch_size, input_channels, height, width)
:return: torch.Tensor of shape (batch_size, output_classes)
"""
x = self.feature_extractor(x)
x = torch.mean(x, dim=[2, 3]) # Global Average Pooling
x = self.fc(x)
return x
# Test code for the RegNet model
batch_size = 8
input_channels = 3
image_height, image_width = 224, 224
stages = 3
block_widths = [64, 128, 256]
output_classes = 10
def get_inputs():
""" Generates random input tensor of shape (batch_size, input_channels, height, width) """
return [torch.rand(batch_size, input_channels, image_height, image_width)]
def get_init_inputs():
""" Initializes model parameters """
return [input_channels, stages, block_widths, output_classes]scrolls · 73 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