danieldk HF Staff commited on
Commit
1018e71
·
verified ·
1 Parent(s): e0702de

Build uploaded using `kernels`.

Browse files
.gitattributes CHANGED
@@ -81,3 +81,4 @@ build/torch210-cxx11-cu130-aarch64-linux/_tinygrad_rms_cuda_9a0d032.abi3.so filt
81
  build/torch29-cxx11-cu126-aarch64-linux/_tinygrad_rms_cuda_9a0d032.abi3.so filter=lfs diff=lfs merge=lfs -text
82
  build/torch29-cxx11-cu128-aarch64-linux/_tinygrad_rms_cuda_9a0d032.abi3.so filter=lfs diff=lfs merge=lfs -text
83
  build/torch29-cxx11-cu130-aarch64-linux/_tinygrad_rms_cuda_9a0d032.abi3.so filter=lfs diff=lfs merge=lfs -text
 
 
81
  build/torch29-cxx11-cu126-aarch64-linux/_tinygrad_rms_cuda_9a0d032.abi3.so filter=lfs diff=lfs merge=lfs -text
82
  build/torch29-cxx11-cu128-aarch64-linux/_tinygrad_rms_cuda_9a0d032.abi3.so filter=lfs diff=lfs merge=lfs -text
83
  build/torch29-cxx11-cu130-aarch64-linux/_tinygrad_rms_cuda_9a0d032.abi3.so filter=lfs diff=lfs merge=lfs -text
84
+ build/torch210-cu128-x86_64-windows/_tinygrad_rms_cuda_6e9aef6.pyd filter=lfs diff=lfs merge=lfs -text
build/torch210-cu128-x86_64-windows/__init__.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional, Tuple
2
+
3
+ import torch
4
+
5
+ from ._ops import ops
6
+
7
+
8
+ def tinygrad_rms_norm(
9
+ x: torch.Tensor,
10
+ epsilon: float = 1e-6,
11
+ out: Optional[torch.Tensor] = None,
12
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
13
+ """
14
+ Compute RMSNorm using tinygrad-style CUDA kernels.
15
+
16
+ RMSNorm(x) = x * (1 / sqrt(mean(x^2) + epsilon))
17
+
18
+ This implementation uses a two-kernel approach:
19
+ 1. Compute 1/sqrt(mean(x^2) + epsilon) for each row
20
+ 2. Multiply input by the computed factor
21
+
22
+ Args:
23
+ x: Input tensor of shape (..., hidden_size)
24
+ epsilon: Small constant for numerical stability
25
+ out: Optional pre-allocated output tensor
26
+
27
+ Returns:
28
+ Tuple of (output tensor, rms_inv tensor)
29
+ """
30
+ if out is None:
31
+ out = torch.empty_like(x)
32
+
33
+ hidden_size = x.size(-1)
34
+ num_rows = x.numel() // hidden_size
35
+ rms_inv = torch.empty(num_rows, dtype=x.dtype, device=x.device)
36
+
37
+ ops.tinygrad_rms_norm(out, rms_inv, x, epsilon)
38
+ return out, rms_inv
39
+
40
+
41
+ def tinygrad_rms_norm_simple(
42
+ x: torch.Tensor,
43
+ epsilon: float = 1e-6,
44
+ out: Optional[torch.Tensor] = None,
45
+ ) -> torch.Tensor:
46
+ """
47
+ Compute RMSNorm using tinygrad-style CUDA kernels.
48
+
49
+ This is a simpler interface that only returns the normalized output.
50
+
51
+ Args:
52
+ x: Input tensor of shape (..., hidden_size)
53
+ epsilon: Small constant for numerical stability
54
+ out: Optional pre-allocated output tensor
55
+
56
+ Returns:
57
+ Normalized output tensor
58
+ """
59
+ if out is None:
60
+ out = torch.empty_like(x)
61
+
62
+ ops.tinygrad_rms_norm_inplace(out, x, epsilon)
63
+ return out
build/torch210-cu128-x86_64-windows/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _tinygrad_rms_cuda_6e9aef6
3
+ ops = torch.ops._tinygrad_rms_cuda_6e9aef6
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_tinygrad_rms_cuda_6e9aef6::{op_name}"
build/torch210-cu128-x86_64-windows/_tinygrad_rms_cuda_6e9aef6.pyd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ebb4b0bd73ae5c954fc25a1fce249af4ac184a1bf3fb537e77ca36d21b3044ef
3
+ size 320000
build/torch210-cu128-x86_64-windows/metadata.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": 1,
3
+ "license": "MIT",
4
+ "python-depends": [],
5
+ "backend": {
6
+ "type": "cuda",
7
+ "archs": [
8
+ "10.0",
9
+ "10.1",
10
+ "12.0+PTX",
11
+ "7.0",
12
+ "7.2",
13
+ "7.5",
14
+ "8.0",
15
+ "8.6",
16
+ "8.7",
17
+ "8.9",
18
+ "9.0"
19
+ ]
20
+ }
21
+ }
build/torch210-cu128-x86_64-windows/tinygrad_rms/__init__.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ctypes
2
+ import sys
3
+
4
+ import importlib
5
+ from pathlib import Path
6
+ from types import ModuleType
7
+
8
+ def _import_from_path(file_path: Path) -> ModuleType:
9
+ # We cannot use the module name as-is, after adding it to `sys.modules`,
10
+ # it would also be used for other imports. So, we make a module name that
11
+ # depends on the path for it to be unique using the hex-encoded hash of
12
+ # the path.
13
+ path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
14
+ module_name = path_hash
15
+ spec = importlib.util.spec_from_file_location(module_name, file_path)
16
+ if spec is None:
17
+ raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
18
+ module = importlib.util.module_from_spec(spec)
19
+ if module is None:
20
+ raise ImportError(f"Cannot load module {module_name} from spec")
21
+ sys.modules[module_name] = module
22
+ spec.loader.exec_module(module) # type: ignore
23
+ return module
24
+
25
+
26
+ globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))