Download problems/kb1_028_hardsigmoid.py from K1ta141k/kernel-train-problems: direct link, hf CLI and curl.
- Browser
- Download file 1.41 kB
-
https://huggingface.co/datasets/K1ta141k/kernel-train-problems/resolve/main/problems/kb1_028_hardsigmoid.py
- Command line
-
hf download hf://datasets/K1ta141k/kernel-train-problems/problems/kb1_028_hardsigmoid.py
-
curl -L -o kb1_028_hardsigmoid.py https://huggingface.co/datasets/K1ta141k/kernel-train-problems/resolve/main/problems/kb1_028_hardsigmoid.py
1.41 kB
| """Task kb1_028_hardsigmoid (KernelBench Level 1 #28, split=train, category=activation, dtype=fp32, variant=base).""" | |
| PROBLEM_ID = "kb1_028_hardsigmoid" | |
| SOURCE_KB_ID = 28 | |
| CATEGORY = "activation" | |
| SPLIT = "train" | |
| DTYPE = "fp32" | |
| VARIANT = "base" | |
| import torch | |
| import torch.nn as nn | |
| class Model(nn.Module): | |
| """ | |
| Simple model that performs a HardSigmoid activation. | |
| """ | |
| def __init__(self): | |
| super(Model, self).__init__() | |
| def forward(self, x: torch.Tensor) -> torch.Tensor: | |
| """ | |
| Applies HardSigmoid activation to the input tensor. | |
| Args: | |
| x (torch.Tensor): Input tensor of any shape. | |
| Returns: | |
| torch.Tensor: Output tensor with HardSigmoid applied, same shape as input. | |
| """ | |
| return torch.nn.functional.hardsigmoid(x) | |
| batch_size = 4096 | |
| dim = 393216 | |
| # --- Task shape configuration (4GB-safe laptop envelope) --- | |
| batch_size = 2048 | |
| dim = 4096 | |
| def get_inputs(): | |
| x = torch.randn(batch_size, dim) | |
| return [x] | |
| def get_init_inputs(): | |
| return [] # No special initialization inputs needed | |
| if __name__ == "__main__": | |
| import sys | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[2])) | |
| from verifier import verify_kernel, format_result | |
| res = verify_kernel(None, __file__, self_check=True) | |
| print(format_result(res)) | |
| sys.exit(0 if res["status"] == "PASS" else 1) | |