PyTorch eager
PyTorch · python · MIT
Kernel source · 32 lines ↓holds 1 record
Use it
Vendorable · source mirrored · MITView source →
No package. Vendor the mirrored source: 32 lines, MIT.
32_HardTanh.py
curl "https://kernelindex.com/api/v1/implementations/kernelbench-l1-32-hardtanh-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.
Reported · How evidence levels are derived →
Source and license
sourceavailable
revision digestsha256:c9119e0254e0135d5c83ca04f30e22082a1ebf27766c552f8a693c8e444b069e
license declaredMIT
license concludedMIT
imported2026-08-26
Kernel source
32_HardTanh.py32 lines
import torch
import torch.nn as nn
import torch.nn.functional as F
class Model(nn.Module):
"""
Simple model that performs a HardTanh activation.
"""
def __init__(self):
super(Model, self).__init__()
def forward(self, x: torch.Tensor) -> torch.Tensor:
"""
Applies HardTanh activation to the input tensor.
Args:
x (torch.Tensor): Input tensor of any shape.
Returns:
torch.Tensor: Output tensor with HardTanh applied, same shape as input.
"""
return F.hardtanh(x, min_val=-1., max_val=1.)
batch_size = 4096
dim = 393216
def get_inputs():
x = torch.rand(batch_size, dim)
return [x]
def get_init_inputs():
return [] # No special initialization inputs neededscrolls · 32 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