danieldk HF Staff commited on
Commit
8bcd2ee
·
verified ·
1 Parent(s): b43d520

Build uploaded using `kernels`.

Browse files
.gitattributes CHANGED
@@ -79,3 +79,4 @@ build/torch210-cxx11-cpu-x86_64-linux/_rmsnorm_ce2b5cc.abi3.so filter=lfs diff=l
79
  build/torch210-cxx11-xpu20253-x86_64-linux/_rmsnorm_ce2b5cc.abi3.so filter=lfs diff=lfs merge=lfs -text
80
  build/torch29-cxx11-cpu-x86_64-linux/_rmsnorm_ce2b5cc.abi3.so filter=lfs diff=lfs merge=lfs -text
81
  build/torch29-cxx11-xpu20252-x86_64-linux/_rmsnorm_ce2b5cc.abi3.so filter=lfs diff=lfs merge=lfs -text
 
 
79
  build/torch210-cxx11-xpu20253-x86_64-linux/_rmsnorm_ce2b5cc.abi3.so filter=lfs diff=lfs merge=lfs -text
80
  build/torch29-cxx11-cpu-x86_64-linux/_rmsnorm_ce2b5cc.abi3.so filter=lfs diff=lfs merge=lfs -text
81
  build/torch29-cxx11-xpu20252-x86_64-linux/_rmsnorm_ce2b5cc.abi3.so filter=lfs diff=lfs merge=lfs -text
82
+ build/torch210-xpu20253-x86_64-windows/rmsnorm/_rmsnorm_4cd2f5b.pyd filter=lfs diff=lfs merge=lfs -text
build/torch210-xpu20253-x86_64-windows/metadata.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "version": 1,
3
+ "python-depends": []
4
+ }
build/torch210-xpu20253-x86_64-windows/rmsnorm/__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/torch210-xpu20253-x86_64-windows/rmsnorm/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _rmsnorm_4cd2f5b
3
+ ops = torch.ops._rmsnorm_4cd2f5b
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_rmsnorm_4cd2f5b::{op_name}"
build/torch210-xpu20253-x86_64-windows/rmsnorm/_rmsnorm_4cd2f5b.pyd ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:13c739cbd5b54166522364d80f8565fddb2ec3bbb77ac3348b35077f70802bfd
3
+ size 2363904
build/torch210-xpu20253-x86_64-windows/rmsnorm/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"]