Skip to content
KernelIndex
Search⌘K

PyTorch eager

PyTorch · python · MIT

Use it

Vendorable · source mirrored · MITView source →

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

97_ScaledDotProductAttention.py
curl "https://kernelindex.com/api/v1/implementations/kernelbench-l1-97-scaleddotproductattention-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
ScaledDotProductAttentionfp32 · [32, 32, 512, 1024]
NVIDIA H100
8.45ms±0.07
#2 of 2
2026-03-05
ScaledDotProductAttentionfp32 · [32, 32, 512, 1024]
NVIDIA H100
13.3ms±0.12
#2 of 2
2026-03-05

Reported · How evidence levels are derived →

Source and license

sourceavailable
revision digestsha256:ac42fea4be49f0f5330f1ddf18aac4530509bdd9f7cb3f642943d0e60c3aa6bf
license declaredMIT
license concludedMIT
imported2026-08-26

Kernel source

97_ScaledDotProductAttention.py25 lines
import torch
import torch.nn as nn

class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()

    def forward(self, Q: torch.Tensor, K: torch.Tensor, V: torch.Tensor) -> torch.Tensor:
        out = torch.nn.functional.scaled_dot_product_attention(Q, K, V)
        return out

batch_size = 32
num_heads = 32
sequence_length = 512
embedding_dimension = 1024

def get_inputs():
    Q = torch.rand(batch_size, num_heads, sequence_length, embedding_dimension)
    K = torch.rand(batch_size, num_heads, sequence_length, embedding_dimension)
    V = torch.rand(batch_size, num_heads, sequence_length, embedding_dimension)
    return [Q, K, V]

def get_init_inputs():
    return []

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