torch.compile (inductor)
PyTorch · python · MIT
Use it
Vendorable · source mirrored · MITView source →
No package. Vendor the mirrored source: 36 lines, MIT.
12_Matmul_with_diagonal_matrices_.py
curl "https://kernelindex.com/api/v1/implementations/kernelbench-l1-12-matmul-with-diagonal-matrices-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.
Operation / workload
Hardware
Latency
Rank
Observed
Reported · How evidence levels are derived →
Source and license
sourceavailable
revision digestsha256:862bce0e6cc2030d7ad4b68b23f8d61d09d76eaf582313de68207dc5db3d3926
license declaredMIT
license concludedMIT
imported2026-08-26
Kernel source
12_Matmul_with_diagonal_matrices_.py36 lines
import torch
import torch.nn as nn
class Model(nn.Module):
"""
Simple model that performs a matrix multiplication of a diagonal matrix with another matrix.
C = diag(A) * B
"""
def __init__(self):
super(Model, self).__init__()
def forward(self, A, B):
"""
Performs the matrix multiplication.
Args:
A (torch.Tensor): A 1D tensor representing the diagonal of the diagonal matrix. Shape: (N,).
B (torch.Tensor): A 2D tensor representing the second matrix. Shape: (N, M).
Returns:
torch.Tensor: The result of the matrix multiplication. Shape: (N, M).
"""
# Logically equivalent to torch.diag(A) @ B
# more efficient as no need to materialize a full N×N matrix
return A.unsqueeze(1) * B
M = 4096
N = 4096
def get_inputs():
A = torch.rand(N)
B = torch.rand(N, M)
return [A, B]
def get_init_inputs():
return [] # No special initialization inputs neededscrolls · 36 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