Add Metal (Apple Silicon) build variants

#1
.gitattributes CHANGED
@@ -90,3 +90,5 @@ build/torch210-cxx11-cpu-x86_64-linux/_rmsnorm_cpu_b3d66c6.abi3.so filter=lfs di
90
  build/torch210-cxx11-xpu20253-x86_64-linux/_rmsnorm_xpu_b3d66c6.abi3.so filter=lfs diff=lfs merge=lfs -text
91
  build/torch29-cxx11-cpu-x86_64-linux/_rmsnorm_cpu_b3d66c6.abi3.so filter=lfs diff=lfs merge=lfs -text
92
  build/torch29-cxx11-xpu20252-x86_64-linux/_rmsnorm_xpu_b3d66c6.abi3.so filter=lfs diff=lfs merge=lfs -text
 
 
 
90
  build/torch210-cxx11-xpu20253-x86_64-linux/_rmsnorm_xpu_b3d66c6.abi3.so filter=lfs diff=lfs merge=lfs -text
91
  build/torch29-cxx11-cpu-x86_64-linux/_rmsnorm_cpu_b3d66c6.abi3.so filter=lfs diff=lfs merge=lfs -text
92
  build/torch29-cxx11-xpu20252-x86_64-linux/_rmsnorm_xpu_b3d66c6.abi3.so filter=lfs diff=lfs merge=lfs -text
93
+ build/torch210-metal-aarch64-darwin/_fused_rms_norm_metal_feea0b8_dirty.abi3.so filter=lfs diff=lfs merge=lfs -text
94
+ build/torch29-metal-aarch64-darwin/_fused_rms_norm_metal_feea0b8_dirty.abi3.so filter=lfs diff=lfs merge=lfs -text
build/torch210-metal-aarch64-darwin/__init__.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from ._custom_ops import fused_add_rms_norm, rms_norm
2
+ from ._ops import ops
3
+
4
+ __all__ = [
5
+ "fused_add_rms_norm",
6
+ "ops",
7
+ "rms_norm",
8
+ ]
build/torch210-metal-aarch64-darwin/_custom_ops.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+
3
+ from ._ops import ops
4
+
5
+
6
+ def rms_norm(
7
+ out: torch.Tensor,
8
+ input: torch.Tensor,
9
+ weight: torch.Tensor,
10
+ epsilon: float,
11
+ ) -> None:
12
+ ops.rms_norm(out, input, weight, epsilon)
13
+
14
+
15
+ def fused_add_rms_norm(
16
+ input: torch.Tensor,
17
+ residual: torch.Tensor,
18
+ weight: torch.Tensor,
19
+ epsilon: float,
20
+ ) -> None:
21
+ ops.fused_add_rms_norm(input, residual, weight, epsilon)
build/torch210-metal-aarch64-darwin/_fused_rms_norm_metal_feea0b8_dirty.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4d5345b64749f1f73168207650def55ba33d51a79a0a8f7b623278b66de97a9a
3
+ size 118520
build/torch210-metal-aarch64-darwin/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _fused_rms_norm_metal_feea0b8_dirty
3
+ ops = torch.ops._fused_rms_norm_metal_feea0b8_dirty
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_fused_rms_norm_metal_feea0b8_dirty::{op_name}"
build/torch210-metal-aarch64-darwin/fused_rms_norm/__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")))
build/torch210-metal-aarch64-darwin/metadata.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "python-depends": []
3
+ }
build/torch29-metal-aarch64-darwin/__init__.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from ._custom_ops import fused_add_rms_norm, rms_norm
2
+ from ._ops import ops
3
+
4
+ __all__ = [
5
+ "fused_add_rms_norm",
6
+ "ops",
7
+ "rms_norm",
8
+ ]
build/torch29-metal-aarch64-darwin/_custom_ops.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+
3
+ from ._ops import ops
4
+
5
+
6
+ def rms_norm(
7
+ out: torch.Tensor,
8
+ input: torch.Tensor,
9
+ weight: torch.Tensor,
10
+ epsilon: float,
11
+ ) -> None:
12
+ ops.rms_norm(out, input, weight, epsilon)
13
+
14
+
15
+ def fused_add_rms_norm(
16
+ input: torch.Tensor,
17
+ residual: torch.Tensor,
18
+ weight: torch.Tensor,
19
+ epsilon: float,
20
+ ) -> None:
21
+ ops.fused_add_rms_norm(input, residual, weight, epsilon)
build/torch29-metal-aarch64-darwin/_fused_rms_norm_metal_feea0b8_dirty.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d19e27f2032ab9c814ec64815688ff5d7101aab790b8a2e4a70c99d99a2d7919
3
+ size 117800
build/torch29-metal-aarch64-darwin/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _fused_rms_norm_metal_feea0b8_dirty
3
+ ops = torch.ops._fused_rms_norm_metal_feea0b8_dirty
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_fused_rms_norm_metal_feea0b8_dirty::{op_name}"
build/torch29-metal-aarch64-darwin/fused_rms_norm/__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")))
build/torch29-metal-aarch64-darwin/metadata.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "python-depends": []
3
+ }