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