Kernels
danieldk HF Staff commited on
Commit
132a235
·
verified ·
1 Parent(s): e96514c

Build uploaded using `kernels`.

Browse files
.gitattributes CHANGED
@@ -94,3 +94,7 @@ build/torch210-cxx11-cpu-x86_64-linux/_rmsnorm_cpu_cec90b8.abi3.so filter=lfs di
94
  build/torch210-cxx11-xpu20253-x86_64-linux/_rmsnorm_xpu_cec90b8.abi3.so filter=lfs diff=lfs merge=lfs -text
95
  build/torch211-cxx11-cpu-x86_64-linux/_rmsnorm_cpu_cec90b8.abi3.so filter=lfs diff=lfs merge=lfs -text
96
  build/torch29-cxx11-xpu20252-x86_64-linux/_rmsnorm_xpu_cec90b8.abi3.so filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
94
  build/torch210-cxx11-xpu20253-x86_64-linux/_rmsnorm_xpu_cec90b8.abi3.so filter=lfs diff=lfs merge=lfs -text
95
  build/torch211-cxx11-cpu-x86_64-linux/_rmsnorm_cpu_cec90b8.abi3.so filter=lfs diff=lfs merge=lfs -text
96
  build/torch29-cxx11-xpu20252-x86_64-linux/_rmsnorm_xpu_cec90b8.abi3.so filter=lfs diff=lfs merge=lfs -text
97
+ build/torch210-cxx11-cpu-x86_64-linux/_rmsnorm_cpu_1a02f6f.abi3.so filter=lfs diff=lfs merge=lfs -text
98
+ build/torch210-cxx11-xpu20253-x86_64-linux/_rmsnorm_xpu_1a02f6f.abi3.so filter=lfs diff=lfs merge=lfs -text
99
+ build/torch211-cxx11-cpu-x86_64-linux/_rmsnorm_cpu_1a02f6f.abi3.so filter=lfs diff=lfs merge=lfs -text
100
+ build/torch211-cxx11-xpu20253-x86_64-linux/_rmsnorm_xpu_1a02f6f.abi3.so filter=lfs diff=lfs merge=lfs -text
build/torch210-cxx11-cpu-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _rmsnorm_cpu_cec90b8
3
- ops = torch.ops._rmsnorm_cpu_cec90b8
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_rmsnorm_cpu_cec90b8::{op_name}"
 
1
  import torch
2
+ from . import _rmsnorm_cpu_1a02f6f
3
+ ops = torch.ops._rmsnorm_cpu_1a02f6f
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_rmsnorm_cpu_1a02f6f::{op_name}"
build/torch210-cxx11-cpu-x86_64-linux/{_rmsnorm_cpu_cec90b8.abi3.so → _rmsnorm_cpu_1a02f6f.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:707454a1958381abde25f844df3a461c933df1c0f72a7f85916950df2d9efe77
3
  size 2006072
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c102259696d99bbe9d4c686b4293195548faa4856123a358d44aab3d90148620
3
  size 2006072
build/torch210-cxx11-xpu20253-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _rmsnorm_xpu_cec90b8
3
- ops = torch.ops._rmsnorm_xpu_cec90b8
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_rmsnorm_xpu_cec90b8::{op_name}"
 
1
  import torch
2
+ from . import _rmsnorm_xpu_1a02f6f
3
+ ops = torch.ops._rmsnorm_xpu_1a02f6f
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_rmsnorm_xpu_1a02f6f::{op_name}"
build/torch210-cxx11-xpu20253-x86_64-linux/{_rmsnorm_xpu_cec90b8.abi3.so → _rmsnorm_xpu_1a02f6f.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f189d83a1f1245edd0a35839df2686bc806d33a2a1f4c30fbeefe2dd58de55df
3
  size 104793360
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9a87f0910ab215646183ecd9f4b2cbc5be6c72c3eee20d167f42f71c14629e65
3
  size 104793360
build/torch211-cxx11-cpu-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _rmsnorm_cpu_cec90b8
3
- ops = torch.ops._rmsnorm_cpu_cec90b8
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_rmsnorm_cpu_cec90b8::{op_name}"
 
1
  import torch
2
+ from . import _rmsnorm_cpu_1a02f6f
3
+ ops = torch.ops._rmsnorm_cpu_1a02f6f
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_rmsnorm_cpu_1a02f6f::{op_name}"
build/torch211-cxx11-cpu-x86_64-linux/{_rmsnorm_cpu_cec90b8.abi3.so → _rmsnorm_cpu_1a02f6f.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:931baff3800b3e5bdfa223f3bc1149eb10013914437acc1ca88eec255f552c83
3
  size 2001976
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:439ac1a1bc4a6095844795cbccd7f2137c101bce3e3415bcebb3fd2b0dfcb97b
3
  size 2001976
build/torch211-cxx11-xpu20253-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from . import layers
2
+
3
+ from ._ops import ops
4
+
5
+
6
+ def apply_rms_norm(input, weight, eps):
7
+ # ops.apply_rms_norm returns [output, rstd]
8
+ return ops.apply_rms_norm(
9
+ input,
10
+ weight,
11
+ eps,
12
+ )[0]
13
+
14
+ def apply_rms_norm_backward(grad_output, input, weight, output, rstd, eps, input_requires_grad=True, weight_requires_grad=True):
15
+ return ops.apply_rms_norm_backward(
16
+ grad_output,
17
+ input,
18
+ weight,
19
+ output,
20
+ rstd,
21
+ eps,
22
+ input_requires_grad,
23
+ weight_requires_grad
24
+ )
25
+
26
+ __all__ = ["layers", "apply_rms_norm_forward", "apply_rms_norm_backward"]
27
+
build/torch211-cxx11-xpu20253-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _rmsnorm_xpu_1a02f6f
3
+ ops = torch.ops._rmsnorm_xpu_1a02f6f
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_rmsnorm_xpu_1a02f6f::{op_name}"
build/torch211-cxx11-xpu20253-x86_64-linux/_rmsnorm_xpu_1a02f6f.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:153aa232ee4f342e92075140aa796e86ccd2f55f07d27bcad90890ed2fac57bf
3
+ size 104793120
build/torch211-cxx11-xpu20253-x86_64-linux/layers.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from ._ops import ops
3
+
4
+ class RMSNormFunction(torch.autograd.Function):
5
+ @staticmethod
6
+ def forward(ctx, hidden_states, weight, variance_epsilon):
7
+ ctx.variance_epsilon = variance_epsilon
8
+ output, rstd = ops.apply_rms_norm(hidden_states, weight, variance_epsilon)
9
+ ctx.save_for_backward(hidden_states, weight, output, rstd)
10
+ return output
11
+
12
+ @staticmethod
13
+ def backward(ctx, grad_output):
14
+ hidden_states, weight, output, rstd = ctx.saved_tensors
15
+ grads = ops.apply_rms_norm_backward(
16
+ grad_output,
17
+ hidden_states,
18
+ weight,
19
+ output,
20
+ rstd,
21
+ ctx.variance_epsilon,
22
+ ctx.needs_input_grad[0],
23
+ ctx.needs_input_grad[1]
24
+ )
25
+ return grads[0], grads[1], None
26
+
27
+ class RMSNorm(torch.nn.Module):
28
+ """
29
+ RMSNorm module that uses the optimized LigerRMSNormFunction.
30
+
31
+ Args:
32
+ hidden_size (int): The size of the hidden dimension.
33
+ eps (float, optional): The epsilon value for numerical stability. Defaults to 1e-6.
34
+ offset (float, optional): Offset value to shift the weight tensor. Defaults to 0.0.
35
+ casting_mode (str, optional): The casting mode to use. Defaults to "llama".
36
+ in_place (bool, optional): Whether to modify dY in-place to store dX during backward. Defaults to True.
37
+ """
38
+
39
+
40
+ weight: torch.Tensor
41
+ variance_epsilon: float
42
+
43
+ def forward(self, hidden_states):
44
+ """
45
+ Apply RMS normalization to the input tensor.
46
+
47
+ Args:
48
+ hidden_states (torch.Tensor): Input tensor of shape (B, T, H) or (BxT, H)
49
+
50
+ Returns:
51
+ torch.Tensor: Normalized tensor of the same shape as input
52
+ """
53
+ return RMSNormFunction.apply(
54
+ hidden_states,
55
+ self.weight,
56
+ self.variance_epsilon,
57
+ )
58
+
59
+ __all__ = ["RMSNorm"]
build/torch211-cxx11-xpu20253-x86_64-linux/metadata.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": 1,
3
+ "license": "Apache-2.0",
4
+ "python-depends": [],
5
+ "backend": {
6
+ "type": "xpu"
7
+ }
8
+ }
build/torch211-cxx11-xpu20253-x86_64-linux/rmsnorm/__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")))