kernels-bot commited on
Commit
8a449d4
·
verified ·
1 Parent(s): 468341e

Uploaded using `kernel-builder`.

Browse files
Files changed (34) hide show
  1. .gitattributes +9 -0
  2. build/torch210-cxx11-cu126-x86_64-linux/_ops.py +3 -3
  3. build/torch210-cxx11-cu126-x86_64-linux/{_tinygrad_rms_cuda_86f75d9.abi3.so → _tinygrad_rms_cuda_1917536.abi3.so} +1 -1
  4. build/torch210-cxx11-cu126-x86_64-linux/metadata.json +1 -1
  5. build/torch210-cxx11-cu128-x86_64-linux/_ops.py +3 -3
  6. build/torch210-cxx11-cu128-x86_64-linux/{_tinygrad_rms_cuda_86f75d9.abi3.so → _tinygrad_rms_cuda_1917536.abi3.so} +1 -1
  7. build/torch210-cxx11-cu128-x86_64-linux/metadata.json +1 -1
  8. build/torch210-cxx11-cu130-x86_64-linux/_ops.py +3 -3
  9. build/torch210-cxx11-cu130-x86_64-linux/{_tinygrad_rms_cuda_86f75d9.abi3.so → _tinygrad_rms_cuda_1917536.abi3.so} +1 -1
  10. build/torch210-cxx11-cu130-x86_64-linux/metadata.json +1 -1
  11. build/torch211-cxx11-cu126-x86_64-linux/_ops.py +3 -3
  12. build/torch211-cxx11-cu126-x86_64-linux/{_tinygrad_rms_cuda_86f75d9.abi3.so → _tinygrad_rms_cuda_1917536.abi3.so} +1 -1
  13. build/torch211-cxx11-cu126-x86_64-linux/metadata.json +1 -1
  14. build/torch211-cxx11-cu128-x86_64-linux/_ops.py +3 -3
  15. build/torch211-cxx11-cu128-x86_64-linux/{_tinygrad_rms_cuda_86f75d9.abi3.so → _tinygrad_rms_cuda_1917536.abi3.so} +1 -1
  16. build/torch211-cxx11-cu128-x86_64-linux/metadata.json +1 -1
  17. build/torch211-cxx11-cu130-x86_64-linux/_ops.py +3 -3
  18. build/torch211-cxx11-cu130-x86_64-linux/{_tinygrad_rms_cuda_86f75d9.abi3.so → _tinygrad_rms_cuda_1917536.abi3.so} +1 -1
  19. build/torch211-cxx11-cu130-x86_64-linux/metadata.json +1 -1
  20. build/torch212-cxx11-cu126-x86_64-linux/__init__.py +63 -0
  21. build/torch212-cxx11-cu126-x86_64-linux/_ops.py +9 -0
  22. build/torch212-cxx11-cu126-x86_64-linux/_tinygrad_rms_cuda_1917536.abi3.so +3 -0
  23. build/torch212-cxx11-cu126-x86_64-linux/metadata.json +20 -0
  24. build/torch212-cxx11-cu126-x86_64-linux/tinygrad_rms/__init__.py +26 -0
  25. build/torch212-cxx11-cu130-x86_64-linux/__init__.py +63 -0
  26. build/torch212-cxx11-cu130-x86_64-linux/_ops.py +9 -0
  27. build/torch212-cxx11-cu130-x86_64-linux/_tinygrad_rms_cuda_1917536.abi3.so +3 -0
  28. build/torch212-cxx11-cu130-x86_64-linux/metadata.json +21 -0
  29. build/torch212-cxx11-cu130-x86_64-linux/tinygrad_rms/__init__.py +26 -0
  30. build/torch212-cxx11-cu132-x86_64-linux/__init__.py +63 -0
  31. build/torch212-cxx11-cu132-x86_64-linux/_ops.py +9 -0
  32. build/torch212-cxx11-cu132-x86_64-linux/_tinygrad_rms_cuda_1917536.abi3.so +3 -0
  33. build/torch212-cxx11-cu132-x86_64-linux/metadata.json +21 -0
  34. build/torch212-cxx11-cu132-x86_64-linux/tinygrad_rms/__init__.py +26 -0
.gitattributes CHANGED
@@ -144,3 +144,12 @@ build/torch210-cxx11-cu130-x86_64-linux/_tinygrad_rms_cuda_86f75d9.abi3.so filte
144
  build/torch211-cxx11-cu126-x86_64-linux/_tinygrad_rms_cuda_86f75d9.abi3.so filter=lfs diff=lfs merge=lfs -text
145
  build/torch211-cxx11-cu128-x86_64-linux/_tinygrad_rms_cuda_86f75d9.abi3.so filter=lfs diff=lfs merge=lfs -text
146
  build/torch211-cxx11-cu130-x86_64-linux/_tinygrad_rms_cuda_86f75d9.abi3.so filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
144
  build/torch211-cxx11-cu126-x86_64-linux/_tinygrad_rms_cuda_86f75d9.abi3.so filter=lfs diff=lfs merge=lfs -text
145
  build/torch211-cxx11-cu128-x86_64-linux/_tinygrad_rms_cuda_86f75d9.abi3.so filter=lfs diff=lfs merge=lfs -text
146
  build/torch211-cxx11-cu130-x86_64-linux/_tinygrad_rms_cuda_86f75d9.abi3.so filter=lfs diff=lfs merge=lfs -text
147
+ build/torch210-cxx11-cu126-x86_64-linux/_tinygrad_rms_cuda_1917536.abi3.so filter=lfs diff=lfs merge=lfs -text
148
+ build/torch210-cxx11-cu128-x86_64-linux/_tinygrad_rms_cuda_1917536.abi3.so filter=lfs diff=lfs merge=lfs -text
149
+ build/torch210-cxx11-cu130-x86_64-linux/_tinygrad_rms_cuda_1917536.abi3.so filter=lfs diff=lfs merge=lfs -text
150
+ build/torch211-cxx11-cu126-x86_64-linux/_tinygrad_rms_cuda_1917536.abi3.so filter=lfs diff=lfs merge=lfs -text
151
+ build/torch211-cxx11-cu128-x86_64-linux/_tinygrad_rms_cuda_1917536.abi3.so filter=lfs diff=lfs merge=lfs -text
152
+ build/torch211-cxx11-cu130-x86_64-linux/_tinygrad_rms_cuda_1917536.abi3.so filter=lfs diff=lfs merge=lfs -text
153
+ build/torch212-cxx11-cu126-x86_64-linux/_tinygrad_rms_cuda_1917536.abi3.so filter=lfs diff=lfs merge=lfs -text
154
+ build/torch212-cxx11-cu130-x86_64-linux/_tinygrad_rms_cuda_1917536.abi3.so filter=lfs diff=lfs merge=lfs -text
155
+ build/torch212-cxx11-cu132-x86_64-linux/_tinygrad_rms_cuda_1917536.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_86f75d9
3
- ops = torch.ops._tinygrad_rms_cuda_86f75d9
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_tinygrad_rms_cuda_86f75d9::{op_name}"
 
1
  import torch
2
+ from . import _tinygrad_rms_cuda_1917536
3
+ ops = torch.ops._tinygrad_rms_cuda_1917536
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_tinygrad_rms_cuda_1917536::{op_name}"
build/torch210-cxx11-cu126-x86_64-linux/{_tinygrad_rms_cuda_86f75d9.abi3.so → _tinygrad_rms_cuda_1917536.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:9edb15d0fa7507a7f988060c8fe849a11fb4a892f4e36220a4c45dfe10799a28
3
  size 2123424
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3080b93ffdc50607ab3f3539799840bc756275be5e94a69d3ffaa950d516d797
3
  size 2123424
build/torch210-cxx11-cu126-x86_64-linux/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "tinygrad-rms",
3
- "id": "_tinygrad_rms_cuda_86f75d9",
4
  "version": 1,
5
  "license": "MIT",
6
  "python-depends": [],
 
1
  {
2
  "name": "tinygrad-rms",
3
+ "id": "_tinygrad_rms_cuda_1917536",
4
  "version": 1,
5
  "license": "MIT",
6
  "python-depends": [],
build/torch210-cxx11-cu128-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _tinygrad_rms_cuda_86f75d9
3
- ops = torch.ops._tinygrad_rms_cuda_86f75d9
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_tinygrad_rms_cuda_86f75d9::{op_name}"
 
1
  import torch
2
+ from . import _tinygrad_rms_cuda_1917536
3
+ ops = torch.ops._tinygrad_rms_cuda_1917536
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_tinygrad_rms_cuda_1917536::{op_name}"
build/torch210-cxx11-cu128-x86_64-linux/{_tinygrad_rms_cuda_86f75d9.abi3.so → _tinygrad_rms_cuda_1917536.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:cca0d5853e8d274e8bdcd84f48e8bb1fa67e2132026a23d2bcbf3145bc10f500
3
  size 2244040
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:87e8724ff26b4efacab3f751eaee25ec70857d3dfca4e2f61022fc5cde8faa9d
3
  size 2244040
build/torch210-cxx11-cu128-x86_64-linux/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "tinygrad-rms",
3
- "id": "_tinygrad_rms_cuda_86f75d9",
4
  "version": 1,
5
  "license": "MIT",
6
  "python-depends": [],
 
1
  {
2
  "name": "tinygrad-rms",
3
+ "id": "_tinygrad_rms_cuda_1917536",
4
  "version": 1,
5
  "license": "MIT",
6
  "python-depends": [],
build/torch210-cxx11-cu130-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _tinygrad_rms_cuda_86f75d9
3
- ops = torch.ops._tinygrad_rms_cuda_86f75d9
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_tinygrad_rms_cuda_86f75d9::{op_name}"
 
1
  import torch
2
+ from . import _tinygrad_rms_cuda_1917536
3
+ ops = torch.ops._tinygrad_rms_cuda_1917536
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_tinygrad_rms_cuda_1917536::{op_name}"
build/torch210-cxx11-cu130-x86_64-linux/{_tinygrad_rms_cuda_86f75d9.abi3.so → _tinygrad_rms_cuda_1917536.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1c5b9cbd98034f9303dad29addca97fd8dde5bcee74e9bcc5f5cfb87cb5590e9
3
  size 2238016
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1abc4fbd62072c1fb6219ef99f4c5e058eda6cf45862e4b02388e29fe1bc94db
3
  size 2238016
build/torch210-cxx11-cu130-x86_64-linux/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "tinygrad-rms",
3
- "id": "_tinygrad_rms_cuda_86f75d9",
4
  "version": 1,
5
  "license": "MIT",
6
  "python-depends": [],
 
1
  {
2
  "name": "tinygrad-rms",
3
+ "id": "_tinygrad_rms_cuda_1917536",
4
  "version": 1,
5
  "license": "MIT",
6
  "python-depends": [],
build/torch211-cxx11-cu126-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _tinygrad_rms_cuda_86f75d9
3
- ops = torch.ops._tinygrad_rms_cuda_86f75d9
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_tinygrad_rms_cuda_86f75d9::{op_name}"
 
1
  import torch
2
+ from . import _tinygrad_rms_cuda_1917536
3
+ ops = torch.ops._tinygrad_rms_cuda_1917536
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_tinygrad_rms_cuda_1917536::{op_name}"
build/torch211-cxx11-cu126-x86_64-linux/{_tinygrad_rms_cuda_86f75d9.abi3.so → _tinygrad_rms_cuda_1917536.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:721ee26a9f60bad3068a37ae257576fee4584495727c7992fe29c3e520abd739
3
  size 2112256
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:161dd9c9edc0e157296d3d69eb92b105d14174f5bc2af7e9d194a0e922c614b2
3
  size 2112256
build/torch211-cxx11-cu126-x86_64-linux/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "tinygrad-rms",
3
- "id": "_tinygrad_rms_cuda_86f75d9",
4
  "version": 1,
5
  "license": "MIT",
6
  "python-depends": [],
 
1
  {
2
  "name": "tinygrad-rms",
3
+ "id": "_tinygrad_rms_cuda_1917536",
4
  "version": 1,
5
  "license": "MIT",
6
  "python-depends": [],
build/torch211-cxx11-cu128-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _tinygrad_rms_cuda_86f75d9
3
- ops = torch.ops._tinygrad_rms_cuda_86f75d9
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_tinygrad_rms_cuda_86f75d9::{op_name}"
 
1
  import torch
2
+ from . import _tinygrad_rms_cuda_1917536
3
+ ops = torch.ops._tinygrad_rms_cuda_1917536
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_tinygrad_rms_cuda_1917536::{op_name}"
build/torch211-cxx11-cu128-x86_64-linux/{_tinygrad_rms_cuda_86f75d9.abi3.so → _tinygrad_rms_cuda_1917536.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:50c37e69a4dea91ea16dbd0230d180b9a0434bff894bfdd614f9c0f2358efd92
3
  size 2232880
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7f78b8b95c674d06e24367eceb342c36f7f4fc8f6a8746473421780ff04f4a5e
3
  size 2232880
build/torch211-cxx11-cu128-x86_64-linux/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "tinygrad-rms",
3
- "id": "_tinygrad_rms_cuda_86f75d9",
4
  "version": 1,
5
  "license": "MIT",
6
  "python-depends": [],
 
1
  {
2
  "name": "tinygrad-rms",
3
+ "id": "_tinygrad_rms_cuda_1917536",
4
  "version": 1,
5
  "license": "MIT",
6
  "python-depends": [],
build/torch211-cxx11-cu130-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _tinygrad_rms_cuda_86f75d9
3
- ops = torch.ops._tinygrad_rms_cuda_86f75d9
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_tinygrad_rms_cuda_86f75d9::{op_name}"
 
1
  import torch
2
+ from . import _tinygrad_rms_cuda_1917536
3
+ ops = torch.ops._tinygrad_rms_cuda_1917536
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_tinygrad_rms_cuda_1917536::{op_name}"
build/torch211-cxx11-cu130-x86_64-linux/{_tinygrad_rms_cuda_86f75d9.abi3.so → _tinygrad_rms_cuda_1917536.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:926f0afea6a970cbaa46e7bc417908bf419e030976a03f3a4462f7d51d2a868c
3
  size 2230952
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b2b41b8dbb85a370e627d021a8fc198e8b0d357a5e2a054929b54088f6f913f4
3
  size 2230952
build/torch211-cxx11-cu130-x86_64-linux/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "tinygrad-rms",
3
- "id": "_tinygrad_rms_cuda_86f75d9",
4
  "version": 1,
5
  "license": "MIT",
6
  "python-depends": [],
 
1
  {
2
  "name": "tinygrad-rms",
3
+ "id": "_tinygrad_rms_cuda_1917536",
4
  "version": 1,
5
  "license": "MIT",
6
  "python-depends": [],
build/torch212-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/torch212-cxx11-cu126-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _tinygrad_rms_cuda_1917536
3
+ ops = torch.ops._tinygrad_rms_cuda_1917536
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_tinygrad_rms_cuda_1917536::{op_name}"
build/torch212-cxx11-cu126-x86_64-linux/_tinygrad_rms_cuda_1917536.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:40b198b0696a1dc1998c570fe04473b8bab587d60c822c82c0741d7356c27fe6
3
+ size 2117808
build/torch212-cxx11-cu126-x86_64-linux/metadata.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "tinygrad-rms",
3
+ "id": "_tinygrad_rms_cuda_1917536",
4
+ "version": 1,
5
+ "license": "MIT",
6
+ "python-depends": [],
7
+ "backend": {
8
+ "type": "cuda",
9
+ "archs": [
10
+ "7.0",
11
+ "7.2",
12
+ "7.5",
13
+ "8.0",
14
+ "8.6",
15
+ "8.7",
16
+ "8.9",
17
+ "9.0+PTX"
18
+ ]
19
+ }
20
+ }
build/torch212-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/torch212-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/torch212-cxx11-cu130-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _tinygrad_rms_cuda_1917536
3
+ ops = torch.ops._tinygrad_rms_cuda_1917536
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_tinygrad_rms_cuda_1917536::{op_name}"
build/torch212-cxx11-cu130-x86_64-linux/_tinygrad_rms_cuda_1917536.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c545bbef2b47b7fddc5416c86bbe60edaccd7fd2d34b9f80c009f8e311ec9886
3
+ size 2232352
build/torch212-cxx11-cu130-x86_64-linux/metadata.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "tinygrad-rms",
3
+ "id": "_tinygrad_rms_cuda_1917536",
4
+ "version": 1,
5
+ "license": "MIT",
6
+ "python-depends": [],
7
+ "backend": {
8
+ "type": "cuda",
9
+ "archs": [
10
+ "10.0",
11
+ "11.0",
12
+ "12.0+PTX",
13
+ "7.5",
14
+ "8.0",
15
+ "8.6",
16
+ "8.7",
17
+ "8.9",
18
+ "9.0"
19
+ ]
20
+ }
21
+ }
build/torch212-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/torch212-cxx11-cu132-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/torch212-cxx11-cu132-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _tinygrad_rms_cuda_1917536
3
+ ops = torch.ops._tinygrad_rms_cuda_1917536
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_tinygrad_rms_cuda_1917536::{op_name}"
build/torch212-cxx11-cu132-x86_64-linux/_tinygrad_rms_cuda_1917536.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:84572d82898e0bbff7e6796614efc63d73f332732a6de471037466b9a2c990dc
3
+ size 2291952
build/torch212-cxx11-cu132-x86_64-linux/metadata.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "tinygrad-rms",
3
+ "id": "_tinygrad_rms_cuda_1917536",
4
+ "version": 1,
5
+ "license": "MIT",
6
+ "python-depends": [],
7
+ "backend": {
8
+ "type": "cuda",
9
+ "archs": [
10
+ "10.0",
11
+ "11.0",
12
+ "12.0+PTX",
13
+ "7.5",
14
+ "8.0",
15
+ "8.6",
16
+ "8.7",
17
+ "8.9",
18
+ "9.0"
19
+ ]
20
+ }
21
+ }
build/torch212-cxx11-cu132-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")))