Kernels
danieldk HF Staff commited on
Commit
50d8add
·
1 Parent(s): 6e83b79

Revert "Build uploaded using `kernels`."

Browse files

This reverts commit 6e83b79991c5b9693ecd7e1e5231b59b75cd742c.

This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. build/torch210-cxx11-cu126-x86_64-linux/__init__.py +53 -0
  2. build/torch210-cxx11-cu126-x86_64-linux/_ops.py +9 -0
  3. build/torch210-cxx11-cu126-x86_64-linux/_rotary_90e4f0f.abi3.so +3 -0
  4. build/torch210-cxx11-cu126-x86_64-linux/metadata.json +1 -0
  5. build/torch210-cxx11-cu126-x86_64-linux/rotary/__init__.py +26 -0
  6. build/torch210-cxx11-cu128-x86_64-linux/__init__.py +53 -0
  7. build/torch210-cxx11-cu128-x86_64-linux/_ops.py +9 -0
  8. build/torch210-cxx11-cu128-x86_64-linux/_rotary_90e4f0f.abi3.so +3 -0
  9. build/torch210-cxx11-cu128-x86_64-linux/metadata.json +1 -0
  10. build/torch210-cxx11-cu128-x86_64-linux/rotary/__init__.py +26 -0
  11. build/torch210-cxx11-cu130-x86_64-linux/__init__.py +53 -0
  12. build/torch210-cxx11-cu130-x86_64-linux/_ops.py +9 -0
  13. build/torch210-cxx11-cu130-x86_64-linux/_rotary_90e4f0f.abi3.so +3 -0
  14. build/torch210-cxx11-cu130-x86_64-linux/metadata.json +1 -0
  15. build/torch210-cxx11-cu130-x86_64-linux/rotary/__init__.py +26 -0
  16. build/torch210-cxx11-xpu20253-x86_64-linux/__init__.py +53 -0
  17. build/torch210-cxx11-xpu20253-x86_64-linux/_ops.py +9 -0
  18. build/torch210-cxx11-xpu20253-x86_64-linux/_rotary_90e4f0f.abi3.so +3 -0
  19. build/torch210-cxx11-xpu20253-x86_64-linux/metadata.json +1 -0
  20. build/torch210-cxx11-xpu20253-x86_64-linux/rotary/__init__.py +26 -0
  21. build/torch28-cxx11-cu126-x86_64-linux/__init__.py +53 -0
  22. build/torch28-cxx11-cu126-x86_64-linux/_ops.py +9 -0
  23. build/torch28-cxx11-cu126-x86_64-linux/_rotary_90e4f0f.abi3.so +3 -0
  24. build/torch28-cxx11-cu126-x86_64-linux/metadata.json +1 -0
  25. build/torch28-cxx11-cu126-x86_64-linux/rotary/__init__.py +26 -0
  26. build/torch28-cxx11-cu128-x86_64-linux/__init__.py +53 -0
  27. build/torch28-cxx11-cu128-x86_64-linux/_ops.py +9 -0
  28. build/torch28-cxx11-cu128-x86_64-linux/_rotary_90e4f0f.abi3.so +3 -0
  29. build/torch28-cxx11-cu128-x86_64-linux/metadata.json +1 -0
  30. build/torch28-cxx11-cu128-x86_64-linux/rotary/__init__.py +26 -0
  31. build/torch28-cxx11-cu129-x86_64-linux/__init__.py +53 -0
  32. build/torch28-cxx11-cu129-x86_64-linux/_ops.py +9 -0
  33. build/torch28-cxx11-cu129-x86_64-linux/_rotary_90e4f0f.abi3.so +3 -0
  34. build/torch28-cxx11-cu129-x86_64-linux/metadata.json +1 -0
  35. build/torch28-cxx11-cu129-x86_64-linux/rotary/__init__.py +26 -0
  36. build/torch28-cxx11-xpu20251-x86_64-linux/__init__.py +53 -0
  37. build/torch28-cxx11-xpu20251-x86_64-linux/_ops.py +9 -0
  38. build/torch28-cxx11-xpu20251-x86_64-linux/_rotary_90e4f0f.abi3.so +3 -0
  39. build/torch28-cxx11-xpu20251-x86_64-linux/metadata.json +1 -0
  40. build/torch28-cxx11-xpu20251-x86_64-linux/rotary/__init__.py +26 -0
  41. build/torch29-cxx11-cu126-x86_64-linux/__init__.py +53 -0
  42. build/torch29-cxx11-cu126-x86_64-linux/_ops.py +9 -0
  43. build/torch29-cxx11-cu126-x86_64-linux/_rotary_90e4f0f.abi3.so +3 -0
  44. build/torch29-cxx11-cu126-x86_64-linux/metadata.json +1 -0
  45. build/torch29-cxx11-cu126-x86_64-linux/rotary/__init__.py +26 -0
  46. build/torch29-cxx11-cu128-x86_64-linux/__init__.py +53 -0
  47. build/torch29-cxx11-cu128-x86_64-linux/_ops.py +9 -0
  48. build/torch29-cxx11-cu128-x86_64-linux/_rotary_90e4f0f.abi3.so +3 -0
  49. build/torch29-cxx11-cu128-x86_64-linux/metadata.json +1 -0
  50. build/torch29-cxx11-cu128-x86_64-linux/rotary/__init__.py +26 -0
build/torch210-cxx11-cu126-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional, Tuple
2
+ import torch
3
+
4
+ from ._ops import ops
5
+
6
+
7
+ def apply_rotary(
8
+ x1: torch.Tensor,
9
+ x2: torch.Tensor,
10
+ cos: torch.Tensor,
11
+ sin: torch.Tensor,
12
+ out1: torch.Tensor,
13
+ out2: torch.Tensor,
14
+ conj: bool,
15
+ ) -> None:
16
+ ops.apply_rotary(x1, x2, cos, sin, out1, out2, conj)
17
+
18
+
19
+ def apply_rotary_transformers(
20
+ q: torch.Tensor,
21
+ k: torch.Tensor,
22
+ cos: torch.Tensor,
23
+ sin: torch.Tensor,
24
+ position_ids: Optional[torch.Tensor] = None,
25
+ unsqueeze_dim: int = 1,
26
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
27
+ """
28
+ Rotary kernel implementation wrapper
29
+ Adapts rotary kernels implementation to match transformers apply_rotary_pos_emb signature
30
+ """
31
+ cos = cos.unsqueeze(unsqueeze_dim)
32
+ sin = sin.unsqueeze(unsqueeze_dim)
33
+
34
+ q_rotated = q.clone()
35
+ k_rotated = k.clone()
36
+
37
+ # Get half dimension for rotation
38
+ half_dim = q.shape[-1] // 2
39
+ q1 = q_rotated[..., :half_dim]
40
+ q2 = q_rotated[..., half_dim:]
41
+ k1 = k_rotated[..., :half_dim]
42
+ k2 = k_rotated[..., half_dim:]
43
+ if cos.shape[-1] != half_dim:
44
+ # Trim cos/sin to match half_dim
45
+ cos = cos[..., :half_dim]
46
+ sin = sin[..., :half_dim]
47
+
48
+ apply_rotary(q1, q2, cos, sin, q1, q2, False)
49
+ apply_rotary(k1, k2, cos, sin, k1, k2, False)
50
+ return q_rotated, k_rotated
51
+
52
+
53
+ __all__ = ["apply_rotary", "apply_rotary_transformers"]
build/torch210-cxx11-cu126-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _rotary_90e4f0f
3
+ ops = torch.ops._rotary_90e4f0f
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_rotary_90e4f0f::{op_name}"
build/torch210-cxx11-cu126-x86_64-linux/_rotary_90e4f0f.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:51027ec42e88d98547fac8145714f9ef08cde6c28d8723d2bbc4d4a653ed6643
3
+ size 8200552
build/torch210-cxx11-cu126-x86_64-linux/metadata.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"python-depends":[]}
build/torch210-cxx11-cu126-x86_64-linux/rotary/__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-cxx11-cu128-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional, Tuple
2
+ import torch
3
+
4
+ from ._ops import ops
5
+
6
+
7
+ def apply_rotary(
8
+ x1: torch.Tensor,
9
+ x2: torch.Tensor,
10
+ cos: torch.Tensor,
11
+ sin: torch.Tensor,
12
+ out1: torch.Tensor,
13
+ out2: torch.Tensor,
14
+ conj: bool,
15
+ ) -> None:
16
+ ops.apply_rotary(x1, x2, cos, sin, out1, out2, conj)
17
+
18
+
19
+ def apply_rotary_transformers(
20
+ q: torch.Tensor,
21
+ k: torch.Tensor,
22
+ cos: torch.Tensor,
23
+ sin: torch.Tensor,
24
+ position_ids: Optional[torch.Tensor] = None,
25
+ unsqueeze_dim: int = 1,
26
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
27
+ """
28
+ Rotary kernel implementation wrapper
29
+ Adapts rotary kernels implementation to match transformers apply_rotary_pos_emb signature
30
+ """
31
+ cos = cos.unsqueeze(unsqueeze_dim)
32
+ sin = sin.unsqueeze(unsqueeze_dim)
33
+
34
+ q_rotated = q.clone()
35
+ k_rotated = k.clone()
36
+
37
+ # Get half dimension for rotation
38
+ half_dim = q.shape[-1] // 2
39
+ q1 = q_rotated[..., :half_dim]
40
+ q2 = q_rotated[..., half_dim:]
41
+ k1 = k_rotated[..., :half_dim]
42
+ k2 = k_rotated[..., half_dim:]
43
+ if cos.shape[-1] != half_dim:
44
+ # Trim cos/sin to match half_dim
45
+ cos = cos[..., :half_dim]
46
+ sin = sin[..., :half_dim]
47
+
48
+ apply_rotary(q1, q2, cos, sin, q1, q2, False)
49
+ apply_rotary(k1, k2, cos, sin, k1, k2, False)
50
+ return q_rotated, k_rotated
51
+
52
+
53
+ __all__ = ["apply_rotary", "apply_rotary_transformers"]
build/torch210-cxx11-cu128-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _rotary_90e4f0f
3
+ ops = torch.ops._rotary_90e4f0f
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_rotary_90e4f0f::{op_name}"
build/torch210-cxx11-cu128-x86_64-linux/_rotary_90e4f0f.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:39cc33889c406562d97b3a4db53d9464c88acc2410d8a6980f0afe0bc9c29e5a
3
+ size 11905888
build/torch210-cxx11-cu128-x86_64-linux/metadata.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"python-depends":[]}
build/torch210-cxx11-cu128-x86_64-linux/rotary/__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-cxx11-cu130-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional, Tuple
2
+ import torch
3
+
4
+ from ._ops import ops
5
+
6
+
7
+ def apply_rotary(
8
+ x1: torch.Tensor,
9
+ x2: torch.Tensor,
10
+ cos: torch.Tensor,
11
+ sin: torch.Tensor,
12
+ out1: torch.Tensor,
13
+ out2: torch.Tensor,
14
+ conj: bool,
15
+ ) -> None:
16
+ ops.apply_rotary(x1, x2, cos, sin, out1, out2, conj)
17
+
18
+
19
+ def apply_rotary_transformers(
20
+ q: torch.Tensor,
21
+ k: torch.Tensor,
22
+ cos: torch.Tensor,
23
+ sin: torch.Tensor,
24
+ position_ids: Optional[torch.Tensor] = None,
25
+ unsqueeze_dim: int = 1,
26
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
27
+ """
28
+ Rotary kernel implementation wrapper
29
+ Adapts rotary kernels implementation to match transformers apply_rotary_pos_emb signature
30
+ """
31
+ cos = cos.unsqueeze(unsqueeze_dim)
32
+ sin = sin.unsqueeze(unsqueeze_dim)
33
+
34
+ q_rotated = q.clone()
35
+ k_rotated = k.clone()
36
+
37
+ # Get half dimension for rotation
38
+ half_dim = q.shape[-1] // 2
39
+ q1 = q_rotated[..., :half_dim]
40
+ q2 = q_rotated[..., half_dim:]
41
+ k1 = k_rotated[..., :half_dim]
42
+ k2 = k_rotated[..., half_dim:]
43
+ if cos.shape[-1] != half_dim:
44
+ # Trim cos/sin to match half_dim
45
+ cos = cos[..., :half_dim]
46
+ sin = sin[..., :half_dim]
47
+
48
+ apply_rotary(q1, q2, cos, sin, q1, q2, False)
49
+ apply_rotary(k1, k2, cos, sin, k1, k2, False)
50
+ return q_rotated, k_rotated
51
+
52
+
53
+ __all__ = ["apply_rotary", "apply_rotary_transformers"]
build/torch210-cxx11-cu130-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _rotary_90e4f0f
3
+ ops = torch.ops._rotary_90e4f0f
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_rotary_90e4f0f::{op_name}"
build/torch210-cxx11-cu130-x86_64-linux/_rotary_90e4f0f.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3c4468ae96a6f8677482061f25d20d4dc5f06bd8110fabf27d1d07c72cc13b3e
3
+ size 10310736
build/torch210-cxx11-cu130-x86_64-linux/metadata.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"python-depends":[]}
build/torch210-cxx11-cu130-x86_64-linux/rotary/__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-cxx11-xpu20253-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional, Tuple
2
+ import torch
3
+
4
+ from ._ops import ops
5
+
6
+
7
+ def apply_rotary(
8
+ x1: torch.Tensor,
9
+ x2: torch.Tensor,
10
+ cos: torch.Tensor,
11
+ sin: torch.Tensor,
12
+ out1: torch.Tensor,
13
+ out2: torch.Tensor,
14
+ conj: bool,
15
+ ) -> None:
16
+ ops.apply_rotary(x1, x2, cos, sin, out1, out2, conj)
17
+
18
+
19
+ def apply_rotary_transformers(
20
+ q: torch.Tensor,
21
+ k: torch.Tensor,
22
+ cos: torch.Tensor,
23
+ sin: torch.Tensor,
24
+ position_ids: Optional[torch.Tensor] = None,
25
+ unsqueeze_dim: int = 1,
26
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
27
+ """
28
+ Rotary kernel implementation wrapper
29
+ Adapts rotary kernels implementation to match transformers apply_rotary_pos_emb signature
30
+ """
31
+ cos = cos.unsqueeze(unsqueeze_dim)
32
+ sin = sin.unsqueeze(unsqueeze_dim)
33
+
34
+ q_rotated = q.clone()
35
+ k_rotated = k.clone()
36
+
37
+ # Get half dimension for rotation
38
+ half_dim = q.shape[-1] // 2
39
+ q1 = q_rotated[..., :half_dim]
40
+ q2 = q_rotated[..., half_dim:]
41
+ k1 = k_rotated[..., :half_dim]
42
+ k2 = k_rotated[..., half_dim:]
43
+ if cos.shape[-1] != half_dim:
44
+ # Trim cos/sin to match half_dim
45
+ cos = cos[..., :half_dim]
46
+ sin = sin[..., :half_dim]
47
+
48
+ apply_rotary(q1, q2, cos, sin, q1, q2, False)
49
+ apply_rotary(k1, k2, cos, sin, k1, k2, False)
50
+ return q_rotated, k_rotated
51
+
52
+
53
+ __all__ = ["apply_rotary", "apply_rotary_transformers"]
build/torch210-cxx11-xpu20253-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _rotary_90e4f0f
3
+ ops = torch.ops._rotary_90e4f0f
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_rotary_90e4f0f::{op_name}"
build/torch210-cxx11-xpu20253-x86_64-linux/_rotary_90e4f0f.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a7bc816c9085ff4756d87484127679dd39968bfc943ecc49eea40947caf2a310
3
+ size 2301488
build/torch210-cxx11-xpu20253-x86_64-linux/metadata.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"python-depends":[]}
build/torch210-cxx11-xpu20253-x86_64-linux/rotary/__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/torch28-cxx11-cu126-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional, Tuple
2
+ import torch
3
+
4
+ from ._ops import ops
5
+
6
+
7
+ def apply_rotary(
8
+ x1: torch.Tensor,
9
+ x2: torch.Tensor,
10
+ cos: torch.Tensor,
11
+ sin: torch.Tensor,
12
+ out1: torch.Tensor,
13
+ out2: torch.Tensor,
14
+ conj: bool,
15
+ ) -> None:
16
+ ops.apply_rotary(x1, x2, cos, sin, out1, out2, conj)
17
+
18
+
19
+ def apply_rotary_transformers(
20
+ q: torch.Tensor,
21
+ k: torch.Tensor,
22
+ cos: torch.Tensor,
23
+ sin: torch.Tensor,
24
+ position_ids: Optional[torch.Tensor] = None,
25
+ unsqueeze_dim: int = 1,
26
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
27
+ """
28
+ Rotary kernel implementation wrapper
29
+ Adapts rotary kernels implementation to match transformers apply_rotary_pos_emb signature
30
+ """
31
+ cos = cos.unsqueeze(unsqueeze_dim)
32
+ sin = sin.unsqueeze(unsqueeze_dim)
33
+
34
+ q_rotated = q.clone()
35
+ k_rotated = k.clone()
36
+
37
+ # Get half dimension for rotation
38
+ half_dim = q.shape[-1] // 2
39
+ q1 = q_rotated[..., :half_dim]
40
+ q2 = q_rotated[..., half_dim:]
41
+ k1 = k_rotated[..., :half_dim]
42
+ k2 = k_rotated[..., half_dim:]
43
+ if cos.shape[-1] != half_dim:
44
+ # Trim cos/sin to match half_dim
45
+ cos = cos[..., :half_dim]
46
+ sin = sin[..., :half_dim]
47
+
48
+ apply_rotary(q1, q2, cos, sin, q1, q2, False)
49
+ apply_rotary(k1, k2, cos, sin, k1, k2, False)
50
+ return q_rotated, k_rotated
51
+
52
+
53
+ __all__ = ["apply_rotary", "apply_rotary_transformers"]
build/torch28-cxx11-cu126-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _rotary_90e4f0f
3
+ ops = torch.ops._rotary_90e4f0f
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_rotary_90e4f0f::{op_name}"
build/torch28-cxx11-cu126-x86_64-linux/_rotary_90e4f0f.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a040bbb8748df983d6c6e07c94bdd24477116ce9792ed785485d073038010d66
3
+ size 8190648
build/torch28-cxx11-cu126-x86_64-linux/metadata.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"python-depends":[]}
build/torch28-cxx11-cu126-x86_64-linux/rotary/__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/torch28-cxx11-cu128-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional, Tuple
2
+ import torch
3
+
4
+ from ._ops import ops
5
+
6
+
7
+ def apply_rotary(
8
+ x1: torch.Tensor,
9
+ x2: torch.Tensor,
10
+ cos: torch.Tensor,
11
+ sin: torch.Tensor,
12
+ out1: torch.Tensor,
13
+ out2: torch.Tensor,
14
+ conj: bool,
15
+ ) -> None:
16
+ ops.apply_rotary(x1, x2, cos, sin, out1, out2, conj)
17
+
18
+
19
+ def apply_rotary_transformers(
20
+ q: torch.Tensor,
21
+ k: torch.Tensor,
22
+ cos: torch.Tensor,
23
+ sin: torch.Tensor,
24
+ position_ids: Optional[torch.Tensor] = None,
25
+ unsqueeze_dim: int = 1,
26
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
27
+ """
28
+ Rotary kernel implementation wrapper
29
+ Adapts rotary kernels implementation to match transformers apply_rotary_pos_emb signature
30
+ """
31
+ cos = cos.unsqueeze(unsqueeze_dim)
32
+ sin = sin.unsqueeze(unsqueeze_dim)
33
+
34
+ q_rotated = q.clone()
35
+ k_rotated = k.clone()
36
+
37
+ # Get half dimension for rotation
38
+ half_dim = q.shape[-1] // 2
39
+ q1 = q_rotated[..., :half_dim]
40
+ q2 = q_rotated[..., half_dim:]
41
+ k1 = k_rotated[..., :half_dim]
42
+ k2 = k_rotated[..., half_dim:]
43
+ if cos.shape[-1] != half_dim:
44
+ # Trim cos/sin to match half_dim
45
+ cos = cos[..., :half_dim]
46
+ sin = sin[..., :half_dim]
47
+
48
+ apply_rotary(q1, q2, cos, sin, q1, q2, False)
49
+ apply_rotary(k1, k2, cos, sin, k1, k2, False)
50
+ return q_rotated, k_rotated
51
+
52
+
53
+ __all__ = ["apply_rotary", "apply_rotary_transformers"]
build/torch28-cxx11-cu128-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _rotary_90e4f0f
3
+ ops = torch.ops._rotary_90e4f0f
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_rotary_90e4f0f::{op_name}"
build/torch28-cxx11-cu128-x86_64-linux/_rotary_90e4f0f.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:98c0ac8bc3419520fc5cd00658273b71611e2fe0bef3d63e5cd9c256b28540ac
3
+ size 11895768
build/torch28-cxx11-cu128-x86_64-linux/metadata.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"python-depends":[]}
build/torch28-cxx11-cu128-x86_64-linux/rotary/__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/torch28-cxx11-cu129-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional, Tuple
2
+ import torch
3
+
4
+ from ._ops import ops
5
+
6
+
7
+ def apply_rotary(
8
+ x1: torch.Tensor,
9
+ x2: torch.Tensor,
10
+ cos: torch.Tensor,
11
+ sin: torch.Tensor,
12
+ out1: torch.Tensor,
13
+ out2: torch.Tensor,
14
+ conj: bool,
15
+ ) -> None:
16
+ ops.apply_rotary(x1, x2, cos, sin, out1, out2, conj)
17
+
18
+
19
+ def apply_rotary_transformers(
20
+ q: torch.Tensor,
21
+ k: torch.Tensor,
22
+ cos: torch.Tensor,
23
+ sin: torch.Tensor,
24
+ position_ids: Optional[torch.Tensor] = None,
25
+ unsqueeze_dim: int = 1,
26
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
27
+ """
28
+ Rotary kernel implementation wrapper
29
+ Adapts rotary kernels implementation to match transformers apply_rotary_pos_emb signature
30
+ """
31
+ cos = cos.unsqueeze(unsqueeze_dim)
32
+ sin = sin.unsqueeze(unsqueeze_dim)
33
+
34
+ q_rotated = q.clone()
35
+ k_rotated = k.clone()
36
+
37
+ # Get half dimension for rotation
38
+ half_dim = q.shape[-1] // 2
39
+ q1 = q_rotated[..., :half_dim]
40
+ q2 = q_rotated[..., half_dim:]
41
+ k1 = k_rotated[..., :half_dim]
42
+ k2 = k_rotated[..., half_dim:]
43
+ if cos.shape[-1] != half_dim:
44
+ # Trim cos/sin to match half_dim
45
+ cos = cos[..., :half_dim]
46
+ sin = sin[..., :half_dim]
47
+
48
+ apply_rotary(q1, q2, cos, sin, q1, q2, False)
49
+ apply_rotary(k1, k2, cos, sin, k1, k2, False)
50
+ return q_rotated, k_rotated
51
+
52
+
53
+ __all__ = ["apply_rotary", "apply_rotary_transformers"]
build/torch28-cxx11-cu129-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _rotary_90e4f0f
3
+ ops = torch.ops._rotary_90e4f0f
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_rotary_90e4f0f::{op_name}"
build/torch28-cxx11-cu129-x86_64-linux/_rotary_90e4f0f.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8e5aeb4ea26bf0cc26423ed103edbbbaa7a0329086a723c259daaa2e458b0a5f
3
+ size 11964056
build/torch28-cxx11-cu129-x86_64-linux/metadata.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"python-depends":[]}
build/torch28-cxx11-cu129-x86_64-linux/rotary/__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/torch28-cxx11-xpu20251-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional, Tuple
2
+ import torch
3
+
4
+ from ._ops import ops
5
+
6
+
7
+ def apply_rotary(
8
+ x1: torch.Tensor,
9
+ x2: torch.Tensor,
10
+ cos: torch.Tensor,
11
+ sin: torch.Tensor,
12
+ out1: torch.Tensor,
13
+ out2: torch.Tensor,
14
+ conj: bool,
15
+ ) -> None:
16
+ ops.apply_rotary(x1, x2, cos, sin, out1, out2, conj)
17
+
18
+
19
+ def apply_rotary_transformers(
20
+ q: torch.Tensor,
21
+ k: torch.Tensor,
22
+ cos: torch.Tensor,
23
+ sin: torch.Tensor,
24
+ position_ids: Optional[torch.Tensor] = None,
25
+ unsqueeze_dim: int = 1,
26
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
27
+ """
28
+ Rotary kernel implementation wrapper
29
+ Adapts rotary kernels implementation to match transformers apply_rotary_pos_emb signature
30
+ """
31
+ cos = cos.unsqueeze(unsqueeze_dim)
32
+ sin = sin.unsqueeze(unsqueeze_dim)
33
+
34
+ q_rotated = q.clone()
35
+ k_rotated = k.clone()
36
+
37
+ # Get half dimension for rotation
38
+ half_dim = q.shape[-1] // 2
39
+ q1 = q_rotated[..., :half_dim]
40
+ q2 = q_rotated[..., half_dim:]
41
+ k1 = k_rotated[..., :half_dim]
42
+ k2 = k_rotated[..., half_dim:]
43
+ if cos.shape[-1] != half_dim:
44
+ # Trim cos/sin to match half_dim
45
+ cos = cos[..., :half_dim]
46
+ sin = sin[..., :half_dim]
47
+
48
+ apply_rotary(q1, q2, cos, sin, q1, q2, False)
49
+ apply_rotary(k1, k2, cos, sin, k1, k2, False)
50
+ return q_rotated, k_rotated
51
+
52
+
53
+ __all__ = ["apply_rotary", "apply_rotary_transformers"]
build/torch28-cxx11-xpu20251-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _rotary_90e4f0f
3
+ ops = torch.ops._rotary_90e4f0f
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_rotary_90e4f0f::{op_name}"
build/torch28-cxx11-xpu20251-x86_64-linux/_rotary_90e4f0f.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bbdc8e24aa6917d5c44abdd37f7b0dfd6e42420d66999a71fffca4db2feeab73
3
+ size 2338640
build/torch28-cxx11-xpu20251-x86_64-linux/metadata.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"python-depends":[]}
build/torch28-cxx11-xpu20251-x86_64-linux/rotary/__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-cxx11-cu126-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional, Tuple
2
+ import torch
3
+
4
+ from ._ops import ops
5
+
6
+
7
+ def apply_rotary(
8
+ x1: torch.Tensor,
9
+ x2: torch.Tensor,
10
+ cos: torch.Tensor,
11
+ sin: torch.Tensor,
12
+ out1: torch.Tensor,
13
+ out2: torch.Tensor,
14
+ conj: bool,
15
+ ) -> None:
16
+ ops.apply_rotary(x1, x2, cos, sin, out1, out2, conj)
17
+
18
+
19
+ def apply_rotary_transformers(
20
+ q: torch.Tensor,
21
+ k: torch.Tensor,
22
+ cos: torch.Tensor,
23
+ sin: torch.Tensor,
24
+ position_ids: Optional[torch.Tensor] = None,
25
+ unsqueeze_dim: int = 1,
26
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
27
+ """
28
+ Rotary kernel implementation wrapper
29
+ Adapts rotary kernels implementation to match transformers apply_rotary_pos_emb signature
30
+ """
31
+ cos = cos.unsqueeze(unsqueeze_dim)
32
+ sin = sin.unsqueeze(unsqueeze_dim)
33
+
34
+ q_rotated = q.clone()
35
+ k_rotated = k.clone()
36
+
37
+ # Get half dimension for rotation
38
+ half_dim = q.shape[-1] // 2
39
+ q1 = q_rotated[..., :half_dim]
40
+ q2 = q_rotated[..., half_dim:]
41
+ k1 = k_rotated[..., :half_dim]
42
+ k2 = k_rotated[..., half_dim:]
43
+ if cos.shape[-1] != half_dim:
44
+ # Trim cos/sin to match half_dim
45
+ cos = cos[..., :half_dim]
46
+ sin = sin[..., :half_dim]
47
+
48
+ apply_rotary(q1, q2, cos, sin, q1, q2, False)
49
+ apply_rotary(k1, k2, cos, sin, k1, k2, False)
50
+ return q_rotated, k_rotated
51
+
52
+
53
+ __all__ = ["apply_rotary", "apply_rotary_transformers"]
build/torch29-cxx11-cu126-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _rotary_90e4f0f
3
+ ops = torch.ops._rotary_90e4f0f
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_rotary_90e4f0f::{op_name}"
build/torch29-cxx11-cu126-x86_64-linux/_rotary_90e4f0f.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dd3327462b2c2aa0ee26f7a8e39655e9453cf2544c809c2fb2b25dae13256296
3
+ size 8190536
build/torch29-cxx11-cu126-x86_64-linux/metadata.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"python-depends":[]}
build/torch29-cxx11-cu126-x86_64-linux/rotary/__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-cxx11-cu128-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional, Tuple
2
+ import torch
3
+
4
+ from ._ops import ops
5
+
6
+
7
+ def apply_rotary(
8
+ x1: torch.Tensor,
9
+ x2: torch.Tensor,
10
+ cos: torch.Tensor,
11
+ sin: torch.Tensor,
12
+ out1: torch.Tensor,
13
+ out2: torch.Tensor,
14
+ conj: bool,
15
+ ) -> None:
16
+ ops.apply_rotary(x1, x2, cos, sin, out1, out2, conj)
17
+
18
+
19
+ def apply_rotary_transformers(
20
+ q: torch.Tensor,
21
+ k: torch.Tensor,
22
+ cos: torch.Tensor,
23
+ sin: torch.Tensor,
24
+ position_ids: Optional[torch.Tensor] = None,
25
+ unsqueeze_dim: int = 1,
26
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
27
+ """
28
+ Rotary kernel implementation wrapper
29
+ Adapts rotary kernels implementation to match transformers apply_rotary_pos_emb signature
30
+ """
31
+ cos = cos.unsqueeze(unsqueeze_dim)
32
+ sin = sin.unsqueeze(unsqueeze_dim)
33
+
34
+ q_rotated = q.clone()
35
+ k_rotated = k.clone()
36
+
37
+ # Get half dimension for rotation
38
+ half_dim = q.shape[-1] // 2
39
+ q1 = q_rotated[..., :half_dim]
40
+ q2 = q_rotated[..., half_dim:]
41
+ k1 = k_rotated[..., :half_dim]
42
+ k2 = k_rotated[..., half_dim:]
43
+ if cos.shape[-1] != half_dim:
44
+ # Trim cos/sin to match half_dim
45
+ cos = cos[..., :half_dim]
46
+ sin = sin[..., :half_dim]
47
+
48
+ apply_rotary(q1, q2, cos, sin, q1, q2, False)
49
+ apply_rotary(k1, k2, cos, sin, k1, k2, False)
50
+ return q_rotated, k_rotated
51
+
52
+
53
+ __all__ = ["apply_rotary", "apply_rotary_transformers"]
build/torch29-cxx11-cu128-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _rotary_90e4f0f
3
+ ops = torch.ops._rotary_90e4f0f
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_rotary_90e4f0f::{op_name}"
build/torch29-cxx11-cu128-x86_64-linux/_rotary_90e4f0f.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8f434031167709f70d404eb67234655fdb3ec9a5a1a65976e98607230deb07f3
3
+ size 11899968
build/torch29-cxx11-cu128-x86_64-linux/metadata.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"python-depends":[]}
build/torch29-cxx11-cu128-x86_64-linux/rotary/__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")))