# NEGATIVE (null solution): torch replica plus a launched no-op custom kernel; speedup ~1 must not pass fast_1. import torch import torch.nn as nn import torch.nn.functional as F from torch.utils.cpp_extension import load_inline cuda_src = r""" #include #include __global__ void noop_kernel(float* y) { if (threadIdx.x == 1024) y[0] = 0.f; } torch::Tensor noop(torch::Tensor y) { noop_kernel<<<1, 32, 0, at::cuda::getCurrentCUDAStream()>>>(y.data_ptr()); return y; } """ cpp_src = "torch::Tensor noop(torch::Tensor y);" ext = load_inline(name="eval_neg_noop", cpp_sources=cpp_src, cuda_sources=cuda_src, functions=["noop"]) class ModelNew(nn.Module): def __init__(self, in_features, out_features, multiplier, negative_slope): super().__init__() self.gemm = nn.Linear(in_features, out_features) self.multiplier = multiplier self.negative_slope = negative_slope def forward(self, x): return ext.noop(F.leaky_relu(F.linear(x, self.gemm.weight, self.gemm.bias) * self.multiplier, self.negative_slope))