Download tests/test_first_kernel.py from drbh/first-kernel: direct link, hf CLI and curl.
- Browser
- Download file 590 Bytes
-
https://huggingface.co/kernels/drbh/first-kernel/resolve/main/tests/test_first_kernel.py
- Command line
-
hf download hf://drbh/first-kernel/tests/test_first_kernel.py
-
curl -L -o test_first_kernel.py https://huggingface.co/kernels/drbh/first-kernel/resolve/main/tests/test_first_kernel.py
590 Bytes
| import platform | |
| import torch | |
| import first_kernel | |
| def test_first_kernel(): | |
| if platform.system() == "Darwin": | |
| device = torch.device("mps") | |
| elif hasattr(torch, "xpu") and torch.xpu.is_available(): | |
| device = torch.device("xpu") | |
| elif torch.version.cuda is not None and torch.cuda.is_available(): | |
| device = torch.device("cuda") | |
| else: | |
| device = torch.device("cpu") | |
| x = torch.randn(1024, 1024, dtype=torch.float32, device=device) | |
| expected = x + 1.0 | |
| result = first_kernel.first_kernel(x) | |
| torch.testing.assert_close(result, expected) | |