Kernels
danieldk HF Staff commited on
Commit
a628562
·
verified ·
1 Parent(s): a2a93fd

Build uploaded using `kernels`.

Browse files
Files changed (30) hide show
  1. .gitattributes +7 -0
  2. build/torch210-cxx11-cu126-x86_64-linux/_ops.py +3 -3
  3. build/torch210-cxx11-cu126-x86_64-linux/{_tinygrad_rms_cuda_9a0d032.abi3.so → _tinygrad_rms_cuda_6eb00dc.abi3.so} +1 -1
  4. build/torch210-cxx11-cu126-x86_64-linux/tinygrad_rms/__init__.py +2 -2
  5. build/torch210-cxx11-cu128-x86_64-linux/_ops.py +3 -3
  6. build/torch210-cxx11-cu128-x86_64-linux/{_tinygrad_rms_cuda_9a0d032.abi3.so → _tinygrad_rms_cuda_6eb00dc.abi3.so} +1 -1
  7. build/torch210-cxx11-cu128-x86_64-linux/tinygrad_rms/__init__.py +2 -2
  8. build/torch210-cxx11-cu130-x86_64-linux/_ops.py +3 -3
  9. build/torch210-cxx11-cu130-x86_64-linux/{_tinygrad_rms_cuda_9a0d032.abi3.so → _tinygrad_rms_cuda_6eb00dc.abi3.so} +1 -1
  10. build/torch210-cxx11-cu130-x86_64-linux/tinygrad_rms/__init__.py +2 -2
  11. build/torch211-cxx11-cu126-x86_64-linux/__init__.py +63 -0
  12. build/torch211-cxx11-cu126-x86_64-linux/_ops.py +9 -0
  13. build/torch211-cxx11-cu126-x86_64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so +3 -0
  14. build/torch211-cxx11-cu126-x86_64-linux/metadata.json +18 -0
  15. build/torch211-cxx11-cu126-x86_64-linux/tinygrad_rms/__init__.py +26 -0
  16. build/torch211-cxx11-cu128-x86_64-linux/__init__.py +63 -0
  17. build/torch211-cxx11-cu128-x86_64-linux/_ops.py +9 -0
  18. build/torch211-cxx11-cu128-x86_64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so +3 -0
  19. build/torch211-cxx11-cu128-x86_64-linux/metadata.json +21 -0
  20. build/torch211-cxx11-cu128-x86_64-linux/tinygrad_rms/__init__.py +26 -0
  21. build/torch211-cxx11-cu130-x86_64-linux/__init__.py +63 -0
  22. build/torch211-cxx11-cu130-x86_64-linux/_ops.py +9 -0
  23. build/torch211-cxx11-cu130-x86_64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so +3 -0
  24. build/torch211-cxx11-cu130-x86_64-linux/metadata.json +19 -0
  25. build/torch211-cxx11-cu130-x86_64-linux/tinygrad_rms/__init__.py +26 -0
  26. build/torch29-cxx11-cu129-x86_64-linux/__init__.py +63 -0
  27. build/torch29-cxx11-cu129-x86_64-linux/_ops.py +9 -0
  28. build/torch29-cxx11-cu129-x86_64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so +3 -0
  29. build/torch29-cxx11-cu129-x86_64-linux/metadata.json +21 -0
  30. build/torch29-cxx11-cu129-x86_64-linux/tinygrad_rms/__init__.py +26 -0
.gitattributes CHANGED
@@ -95,3 +95,10 @@ build/torch211-cxx11-cu126-aarch64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so filt
95
  build/torch211-cxx11-cu128-aarch64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so filter=lfs diff=lfs merge=lfs -text
96
  build/torch211-cxx11-cu130-aarch64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so filter=lfs diff=lfs merge=lfs -text
97
  build/torch29-cxx11-cu129-aarch64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
95
  build/torch211-cxx11-cu128-aarch64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so filter=lfs diff=lfs merge=lfs -text
96
  build/torch211-cxx11-cu130-aarch64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so filter=lfs diff=lfs merge=lfs -text
97
  build/torch29-cxx11-cu129-aarch64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so filter=lfs diff=lfs merge=lfs -text
98
+ build/torch210-cxx11-cu126-x86_64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so filter=lfs diff=lfs merge=lfs -text
99
+ build/torch210-cxx11-cu128-x86_64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so filter=lfs diff=lfs merge=lfs -text
100
+ build/torch210-cxx11-cu130-x86_64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so filter=lfs diff=lfs merge=lfs -text
101
+ build/torch211-cxx11-cu126-x86_64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so filter=lfs diff=lfs merge=lfs -text
102
+ build/torch211-cxx11-cu128-x86_64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so filter=lfs diff=lfs merge=lfs -text
103
+ build/torch211-cxx11-cu130-x86_64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so filter=lfs diff=lfs merge=lfs -text
104
+ build/torch29-cxx11-cu129-x86_64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so filter=lfs diff=lfs merge=lfs -text
build/torch210-cxx11-cu126-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _tinygrad_rms_cuda_9a0d032
3
- ops = torch.ops._tinygrad_rms_cuda_9a0d032
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_tinygrad_rms_cuda_9a0d032::{op_name}"
 
1
  import torch
2
+ from . import _tinygrad_rms_cuda_6eb00dc
3
+ ops = torch.ops._tinygrad_rms_cuda_6eb00dc
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_tinygrad_rms_cuda_6eb00dc::{op_name}"
build/torch210-cxx11-cu126-x86_64-linux/{_tinygrad_rms_cuda_9a0d032.abi3.so → _tinygrad_rms_cuda_6eb00dc.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:cc0991e99b3bc0752fb673d4f8a402d567115cf7b81298cf34d554c8b7613922
3
  size 2123424
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b6dc5ab336157c3e6c577ecc8dca3790d4ac9273ae4b38ebd45e7dee0c6c20a5
3
  size 2123424
build/torch210-cxx11-cu126-x86_64-linux/tinygrad_rms/__init__.py CHANGED
@@ -1,10 +1,10 @@
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
 
1
  import ctypes
2
+ import importlib.util
3
  import sys
 
 
4
  from pathlib import Path
5
  from types import ModuleType
6
 
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
build/torch210-cxx11-cu128-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _tinygrad_rms_cuda_9a0d032
3
- ops = torch.ops._tinygrad_rms_cuda_9a0d032
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_tinygrad_rms_cuda_9a0d032::{op_name}"
 
1
  import torch
2
+ from . import _tinygrad_rms_cuda_6eb00dc
3
+ ops = torch.ops._tinygrad_rms_cuda_6eb00dc
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_tinygrad_rms_cuda_6eb00dc::{op_name}"
build/torch210-cxx11-cu128-x86_64-linux/{_tinygrad_rms_cuda_9a0d032.abi3.so → _tinygrad_rms_cuda_6eb00dc.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:8180078f139f93c7de5a02d7f26b1d545f32d1def25dfbba8e77d38c37a727cf
3
  size 2244040
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:645b392a5deadd70a5405bbceeb2161c9b852cb0a303b826e8ee633ee4443883
3
  size 2244040
build/torch210-cxx11-cu128-x86_64-linux/tinygrad_rms/__init__.py CHANGED
@@ -1,10 +1,10 @@
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
 
1
  import ctypes
2
+ import importlib.util
3
  import sys
 
 
4
  from pathlib import Path
5
  from types import ModuleType
6
 
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
build/torch210-cxx11-cu130-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _tinygrad_rms_cuda_9a0d032
3
- ops = torch.ops._tinygrad_rms_cuda_9a0d032
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_tinygrad_rms_cuda_9a0d032::{op_name}"
 
1
  import torch
2
+ from . import _tinygrad_rms_cuda_6eb00dc
3
+ ops = torch.ops._tinygrad_rms_cuda_6eb00dc
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_tinygrad_rms_cuda_6eb00dc::{op_name}"
build/torch210-cxx11-cu130-x86_64-linux/{_tinygrad_rms_cuda_9a0d032.abi3.so → _tinygrad_rms_cuda_6eb00dc.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:613b67088db70e70b9b629dd61276368b3a7d8b871a6870116fc98b897ac3425
3
  size 2245848
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3bd783d80e077f2983793e5fdc8a0f5478836851435a8b77f00b186fea64c8f4
3
  size 2245848
build/torch210-cxx11-cu130-x86_64-linux/tinygrad_rms/__init__.py CHANGED
@@ -1,10 +1,10 @@
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
 
1
  import ctypes
2
+ import importlib.util
3
  import sys
 
 
4
  from pathlib import Path
5
  from types import ModuleType
6
 
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
build/torch211-cxx11-cu126-x86_64-linux/__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/torch211-cxx11-cu126-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _tinygrad_rms_cuda_6eb00dc
3
+ ops = torch.ops._tinygrad_rms_cuda_6eb00dc
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_tinygrad_rms_cuda_6eb00dc::{op_name}"
build/torch211-cxx11-cu126-x86_64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f6394aee38bd05dd68b98ab6e87ff95748c1662dad1b85178c475cd76de7cbf4
3
+ size 2112256
build/torch211-cxx11-cu126-x86_64-linux/metadata.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": 1,
3
+ "license": "MIT",
4
+ "python-depends": [],
5
+ "backend": {
6
+ "type": "cuda",
7
+ "archs": [
8
+ "7.0",
9
+ "7.2",
10
+ "7.5",
11
+ "8.0",
12
+ "8.6",
13
+ "8.7",
14
+ "8.9",
15
+ "9.0+PTX"
16
+ ]
17
+ }
18
+ }
build/torch211-cxx11-cu126-x86_64-linux/tinygrad_rms/__init__.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ctypes
2
+ import importlib.util
3
+ import sys
4
+ from pathlib import Path
5
+ from types import ModuleType
6
+
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")))
build/torch211-cxx11-cu128-x86_64-linux/__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/torch211-cxx11-cu128-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _tinygrad_rms_cuda_6eb00dc
3
+ ops = torch.ops._tinygrad_rms_cuda_6eb00dc
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_tinygrad_rms_cuda_6eb00dc::{op_name}"
build/torch211-cxx11-cu128-x86_64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2528a713f5fddd2d8ec0ab7dad1b08e59a693bcc5ea3d4c060a6c25760bc4956
3
+ size 2232880
build/torch211-cxx11-cu128-x86_64-linux/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/torch211-cxx11-cu128-x86_64-linux/tinygrad_rms/__init__.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ctypes
2
+ import importlib.util
3
+ import sys
4
+ from pathlib import Path
5
+ from types import ModuleType
6
+
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")))
build/torch211-cxx11-cu130-x86_64-linux/__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/torch211-cxx11-cu130-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _tinygrad_rms_cuda_6eb00dc
3
+ ops = torch.ops._tinygrad_rms_cuda_6eb00dc
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_tinygrad_rms_cuda_6eb00dc::{op_name}"
build/torch211-cxx11-cu130-x86_64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1987caa31a62d13612871c2554f23facb2727ff58e5d274fc98ec39a105d24aa
3
+ size 2234688
build/torch211-cxx11-cu130-x86_64-linux/metadata.json ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": 1,
3
+ "license": "MIT",
4
+ "python-depends": [],
5
+ "backend": {
6
+ "type": "cuda",
7
+ "archs": [
8
+ "10.0",
9
+ "11.0",
10
+ "12.0+PTX",
11
+ "7.5",
12
+ "8.0",
13
+ "8.6",
14
+ "8.7",
15
+ "8.9",
16
+ "9.0"
17
+ ]
18
+ }
19
+ }
build/torch211-cxx11-cu130-x86_64-linux/tinygrad_rms/__init__.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ctypes
2
+ import importlib.util
3
+ import sys
4
+ from pathlib import Path
5
+ from types import ModuleType
6
+
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")))
build/torch29-cxx11-cu129-x86_64-linux/__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/torch29-cxx11-cu129-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _tinygrad_rms_cuda_6eb00dc
3
+ ops = torch.ops._tinygrad_rms_cuda_6eb00dc
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_tinygrad_rms_cuda_6eb00dc::{op_name}"
build/torch29-cxx11-cu129-x86_64-linux/_tinygrad_rms_cuda_6eb00dc.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d7bdd7d0c61c7df6af0a414d49acfc4d61c5c23fc4bc8e9b0d9a5e633ac6a88b
3
+ size 2262864
build/torch29-cxx11-cu129-x86_64-linux/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/torch29-cxx11-cu129-x86_64-linux/tinygrad_rms/__init__.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ctypes
2
+ import importlib.util
3
+ import sys
4
+ from pathlib import Path
5
+ from types import ModuleType
6
+
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")))