Download problems/kb1_002_standard_matrix_multiplication.py from K1ta141k/kernel-train-problems: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/datasets/K1ta141k/kernel-train-problems/resolve/main/problems/kb1_002_standard_matrix_multiplication.py
- Command line
-
hf download hf://datasets/K1ta141k/kernel-train-problems/problems/kb1_002_standard_matrix_multiplication.py
-
curl -L -o kb1_002_standard_matrix_multiplication.py https://huggingface.co/datasets/K1ta141k/kernel-train-problems/resolve/main/problems/kb1_002_standard_matrix_multiplication.py
1.45 kB
| """Task kb1_002_standard_matrix_multiplication (KernelBench Level 1 #2, split=train, category=matmul, dtype=fp32, variant=base).""" | |
| PROBLEM_ID = "kb1_002_standard_matrix_multiplication" | |
| SOURCE_KB_ID = 2 | |
| CATEGORY = "matmul" | |
| SPLIT = "train" | |
| DTYPE = "fp32" | |
| VARIANT = "base" | |
| import torch | |
| import torch.nn as nn | |
| class Model(nn.Module): | |
| """ | |
| Simple model that performs a single matrix multiplication (C = A * B) | |
| """ | |
| def __init__(self): | |
| super(Model, self).__init__() | |
| def forward(self, A: torch.Tensor, B: torch.Tensor) -> torch.Tensor: | |
| """ | |
| Performs matrix multiplication. | |
| Args: | |
| A: Input tensor of shape (M, K). | |
| B: Input tensor of shape (K, N). | |
| Returns: | |
| Output tensor of shape (M, N). | |
| """ | |
| return torch.matmul(A, B) | |
| M = 1024 * 2 | |
| K = 4096 * 2 | |
| N = 2048 * 2 | |
| # --- Task shape configuration (4GB-safe laptop envelope) --- | |
| M = 1024 | |
| K = 2048 | |
| N = 1024 | |
| def get_inputs(): | |
| A = torch.rand(M, K) | |
| B = torch.rand(K, N) | |
| return [A, B] | |
| 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) | |