liangsu9988 commited on
Commit
a5c8bb9
·
verified ·
1 Parent(s): fdd3833

Add torch211-cxx11-cu130-aarch64-linux SM110 artifact

Browse files
build/torch211-cxx11-cu130-aarch64-linux/__init__.py ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """FlashRT linear-attention helper kernels."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Optional
6
+
7
+ import torch
8
+
9
+ from ._ops import add_op_namespace_prefix, ops
10
+
11
+
12
+ @torch.library.register_fake(add_op_namespace_prefix("bf16_matvec"))
13
+ def _bf16_matvec_fake(x: torch.Tensor, w: torch.Tensor, out: torch.Tensor) -> None:
14
+ if x.dim() != 1 or w.dim() != 2 or w.shape[1] != x.shape[0] or out.shape != (w.shape[0],):
15
+ raise RuntimeError("bf16_matvec expects x (K,), w (N,K), out (N,)")
16
+ if w.shape[0] < 256:
17
+ raise RuntimeError("bf16_matvec supports N >= 256")
18
+ return None
19
+
20
+
21
+ @torch.library.register_fake(add_op_namespace_prefix("bf16_smallm_matmul"))
22
+ def _bf16_smallm_matmul_fake(x: torch.Tensor, w: torch.Tensor, out: torch.Tensor) -> None:
23
+ if x.dim() != 2 or w.dim() != 2 or w.shape[1] != x.shape[1] or out.shape != (x.shape[0], w.shape[0]):
24
+ raise RuntimeError("bf16_smallm_matmul expects x (M,K), w (N,K), out (M,N)")
25
+ if w.shape != (96, 5120):
26
+ raise RuntimeError("bf16_smallm_matmul supports tuned AB96 shape N=96,K=5120")
27
+ if x.shape[0] < 2 or x.shape[0] > 4:
28
+ raise RuntimeError("bf16_smallm_matmul supports 2 <= M <= 4")
29
+ return None
30
+
31
+
32
+ @torch.library.register_fake(add_op_namespace_prefix("split_qkv_broadcast_bf16"))
33
+ def _split_qkv_broadcast_fake(
34
+ packed: torch.Tensor,
35
+ q: torch.Tensor,
36
+ k: torch.Tensor,
37
+ v: torch.Tensor,
38
+ q_heads: int,
39
+ kv_heads: int,
40
+ v_heads: int,
41
+ head_dim: int,
42
+ ) -> None:
43
+ rows = packed.shape[0]
44
+ if packed.shape != (rows, (q_heads + kv_heads + v_heads) * head_dim):
45
+ raise RuntimeError("packed shape mismatch")
46
+ if q.shape != (rows, v_heads, head_dim) or k.shape != (rows, v_heads, head_dim) or v.shape != (rows, v_heads, head_dim):
47
+ raise RuntimeError("q/k/v output shape mismatch")
48
+ return None
49
+
50
+
51
+ @torch.library.register_fake(add_op_namespace_prefix("partial_rope_qk_bf16"))
52
+ def _partial_rope_qk_fake(
53
+ q_in: torch.Tensor,
54
+ k_in: torch.Tensor,
55
+ cos: torch.Tensor,
56
+ sin: torch.Tensor,
57
+ q_out: torch.Tensor,
58
+ k_out: torch.Tensor,
59
+ rope_dim: int,
60
+ ) -> None:
61
+ if q_in.dim() != 3 or k_in.dim() != 3 or q_in.shape[0] != k_in.shape[0] or q_in.shape[2] != k_in.shape[2]:
62
+ raise RuntimeError("q_in/k_in shape mismatch")
63
+ rows, _, head_dim = q_in.shape
64
+ if rope_dim <= 0 or rope_dim > head_dim or rope_dim % 2 != 0:
65
+ raise RuntimeError("invalid rope_dim")
66
+ if cos.shape != (rows, rope_dim) or sin.shape != (rows, rope_dim):
67
+ raise RuntimeError("cos/sin shape mismatch")
68
+ if q_out.shape != q_in.shape or k_out.shape != k_in.shape:
69
+ raise RuntimeError("q_out/k_out shape mismatch")
70
+ return None
71
+
72
+
73
+ @torch.library.register_fake(add_op_namespace_prefix("gated_delta_prepare_bf16"))
74
+ def _gated_delta_prepare_fake(
75
+ a: torch.Tensor,
76
+ b: torch.Tensor,
77
+ neg_exp_a_log: torch.Tensor,
78
+ dt_bias: torch.Tensor,
79
+ g_out: torch.Tensor,
80
+ beta_out: torch.Tensor,
81
+ a_stride: int,
82
+ b_stride: int,
83
+ ) -> None:
84
+ if g_out.dim() != 2 or beta_out.shape != g_out.shape:
85
+ raise RuntimeError("g_out/beta_out must have shape (rows, heads)")
86
+ heads = g_out.shape[1]
87
+ if neg_exp_a_log.shape != (heads,) or dt_bias.shape != (heads,):
88
+ raise RuntimeError("per-head parameter shape mismatch")
89
+ return None
90
+
91
+
92
+ def bf16_matvec(x: torch.Tensor, w: torch.Tensor, *, out: Optional[torch.Tensor] = None) -> torch.Tensor:
93
+ """Compute `out = x @ w.T` for BF16 `x (K,)` and `w (N, K)`."""
94
+ if out is None:
95
+ out = torch.empty((w.shape[0],), device=x.device, dtype=torch.bfloat16)
96
+ ops.bf16_matvec(x, w, out)
97
+ return out
98
+
99
+
100
+ def bf16_smallm_matmul(x: torch.Tensor, w: torch.Tensor, *, out: Optional[torch.Tensor] = None) -> torch.Tensor:
101
+ """Compute `out = x @ w.T` for BF16 `x (M,K)` and small `M`."""
102
+ if out is None:
103
+ out = torch.empty((x.shape[0], w.shape[0]), device=x.device, dtype=torch.bfloat16)
104
+ ops.bf16_smallm_matmul(x, w, out)
105
+ return out
106
+
107
+
108
+ def split_qkv_broadcast_bf16(
109
+ packed: torch.Tensor,
110
+ q_heads: int,
111
+ kv_heads: int,
112
+ v_heads: int,
113
+ head_dim: int,
114
+ *,
115
+ q: Optional[torch.Tensor] = None,
116
+ k: Optional[torch.Tensor] = None,
117
+ v: Optional[torch.Tensor] = None,
118
+ ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
119
+ """Split packed Q/K/V and broadcast Q/K groups to `v_heads`."""
120
+ rows = packed.shape[0]
121
+ shape = (rows, v_heads, head_dim)
122
+ if q is None:
123
+ q = torch.empty(shape, device=packed.device, dtype=torch.bfloat16)
124
+ if k is None:
125
+ k = torch.empty(shape, device=packed.device, dtype=torch.bfloat16)
126
+ if v is None:
127
+ v = torch.empty(shape, device=packed.device, dtype=torch.bfloat16)
128
+ ops.split_qkv_broadcast_bf16(
129
+ packed, q, k, v, int(q_heads), int(kv_heads), int(v_heads), int(head_dim)
130
+ )
131
+ return q, k, v
132
+
133
+
134
+ def partial_rope_qk_bf16(
135
+ q_in: torch.Tensor,
136
+ k_in: torch.Tensor,
137
+ cos: torch.Tensor,
138
+ sin: torch.Tensor,
139
+ rope_dim: int,
140
+ *,
141
+ q_out: Optional[torch.Tensor] = None,
142
+ k_out: Optional[torch.Tensor] = None,
143
+ ) -> tuple[torch.Tensor, torch.Tensor]:
144
+ """Apply split-half RoPE to the first `rope_dim` channels of Q and K."""
145
+ if q_out is None:
146
+ q_out = torch.empty_like(q_in)
147
+ if k_out is None:
148
+ k_out = torch.empty_like(k_in)
149
+ ops.partial_rope_qk_bf16(q_in, k_in, cos, sin, q_out, k_out, int(rope_dim))
150
+ return q_out, k_out
151
+
152
+
153
+ def gated_delta_prepare_bf16(
154
+ a: torch.Tensor,
155
+ b: torch.Tensor,
156
+ neg_exp_a_log: torch.Tensor,
157
+ dt_bias: torch.Tensor,
158
+ *,
159
+ heads: Optional[int] = None,
160
+ a_stride: Optional[int] = None,
161
+ b_stride: Optional[int] = None,
162
+ g_out: Optional[torch.Tensor] = None,
163
+ beta_out: Optional[torch.Tensor] = None,
164
+ ) -> tuple[torch.Tensor, torch.Tensor]:
165
+ """Prepare BF16 Gated DeltaNet `g` and `beta` tensors from projected a/b."""
166
+ if heads is None:
167
+ heads = neg_exp_a_log.shape[0]
168
+ if a_stride is None:
169
+ a_stride = a.shape[1]
170
+ if b_stride is None:
171
+ b_stride = b.shape[1]
172
+ rows = a.shape[0]
173
+ if g_out is None:
174
+ g_out = torch.empty((rows, heads), device=a.device, dtype=torch.bfloat16)
175
+ if beta_out is None:
176
+ beta_out = torch.empty_like(g_out)
177
+ ops.gated_delta_prepare_bf16(
178
+ a, b, neg_exp_a_log, dt_bias, g_out, beta_out, int(a_stride), int(b_stride)
179
+ )
180
+ return g_out, beta_out
181
+
182
+
183
+ __all__ = [
184
+ "bf16_matvec",
185
+ "bf16_smallm_matmul",
186
+ "gated_delta_prepare_bf16",
187
+ "partial_rope_qk_bf16",
188
+ "split_qkv_broadcast_bf16",
189
+ ]
build/torch211-cxx11-cu130-aarch64-linux/_linear_attention_primitives_cuda_f14c443.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:195d4332fce26301ae9711da41bf193775c8ca052d946c91ea239e6c45f6fe29
3
+ size 318984
build/torch211-cxx11-cu130-aarch64-linux/_ops.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _linear_attention_primitives_cuda_f14c443
3
+ ops = torch.ops._linear_attention_primitives_cuda_f14c443
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ return f"_linear_attention_primitives_cuda_f14c443::{op_name}"
build/torch211-cxx11-cu130-aarch64-linux/linear_attention_primitives/__init__.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ctypes
2
+ import importlib.util
3
+ import sys
4
+ from pathlib import Path
5
+
6
+ def _import_from_path(file_path: Path):
7
+ path_hash = '{:x}'.format(ctypes.c_size_t(hash(file_path.absolute())).value)
8
+ spec = importlib.util.spec_from_file_location(path_hash, file_path)
9
+ module = importlib.util.module_from_spec(spec)
10
+ sys.modules[path_hash] = module
11
+ spec.loader.exec_module(module)
12
+ return module
13
+
14
+ globals().update(vars(_import_from_path(Path(__file__).parent.parent / '__init__.py')))
build/torch211-cxx11-cu130-aarch64-linux/metadata.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "linear-attention-primitives",
3
+ "id": "_linear_attention_primitives_cuda_f14c443",
4
+ "version": 1,
5
+ "license": "Apache-2.0",
6
+ "python-depends": [],
7
+ "backend": {
8
+ "type": "cuda",
9
+ "archs": [
10
+ "11.0"
11
+ ]
12
+ },
13
+ "digest": {
14
+ "algorithm": "sha256",
15
+ "files": {
16
+ "__init__.py": "El7Tb3cAe8Z4OrJw+QiYDfx6njxz5VWIUhESiLRUV/I=",
17
+ "_linear_attention_primitives_cuda_f14c443.abi3.so": "GV1DMvziYwGulxHaQb8ZN3XIygUtlGyR6iOebEX2/ik=",
18
+ "_ops.py": "XfTGXfk43LdLBLPNSNJtmSG2qysx+pmUkv66RgwCtkI=",
19
+ "linear_attention_primitives/__init__.py": "v6p5XMfQzddhi1fLSAw4HX9CyS0rQsidvu9VsT01xi4="
20
+ }
21
+ }
22
+ }