liangsu9988 commited on
Commit
84d71c4
·
verified ·
1 Parent(s): fa7ecd1

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

Browse files
build/torch211-cxx11-cu130-aarch64-linux/__init__.py ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """FlashRT transformer layout primitives."""
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("fill_neginf_bf16"))
13
+ def _fill_neginf_bf16_fake(dst: torch.Tensor) -> None:
14
+ return None
15
+
16
+
17
+ @torch.library.register_fake(add_op_namespace_prefix("add_bias_bf16_"))
18
+ def _add_bias_bf16_fake(data: torch.Tensor, bias: torch.Tensor) -> None:
19
+ if data.dim() != 2 or bias.shape != (data.shape[1],):
20
+ raise RuntimeError("add_bias_bf16_ expects data (rows, cols), bias (cols,)")
21
+ return None
22
+
23
+
24
+ @torch.library.register_fake(add_op_namespace_prefix("repeat_interleave_heads_bf16"))
25
+ def _repeat_interleave_heads_bf16_fake(src: torch.Tensor, repeat: int, dst: torch.Tensor) -> None:
26
+ if src.dim() != 3 or dst.shape != (src.shape[0], src.shape[1] * repeat, src.shape[2]):
27
+ raise RuntimeError("repeat_interleave_heads_bf16 expects src (seq, heads, dim), dst (seq, heads*repeat, dim)")
28
+ return None
29
+
30
+
31
+ @torch.library.register_fake(add_op_namespace_prefix("text_gather_bf16"))
32
+ def _text_gather_bf16_fake(src: torch.Tensor, batch: int, seq: int, dst: torch.Tensor) -> None:
33
+ if src.dim() != 2 or src.shape[0] != batch * seq or dst.shape != (2 * batch, src.shape[1]):
34
+ raise RuntimeError("text_gather_bf16 expects src (batch*seq, dim), dst (2*batch, dim)")
35
+ return None
36
+
37
+
38
+ @torch.library.register_fake(add_op_namespace_prefix("text_scatter_bf16"))
39
+ def _text_scatter_bf16_fake(dst: torch.Tensor, src: torch.Tensor, batch: int, seq: int) -> None:
40
+ if dst.dim() != 2 or dst.shape[0] != batch * seq or src.shape != (2 * batch, dst.shape[1]):
41
+ raise RuntimeError("text_scatter_bf16 expects dst (batch*seq, dim), src (2*batch, dim)")
42
+ return None
43
+
44
+
45
+ @torch.library.register_fake(add_op_namespace_prefix("rope_rotate_half_bf16_"))
46
+ def _rope_rotate_half_bf16_fake(x: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor) -> None:
47
+ if x.dim() != 3 or x.shape[2] % 2 != 0 or cos.shape != (x.shape[0], x.shape[2]) or sin.shape != cos.shape:
48
+ raise RuntimeError("rope_rotate_half_bf16_ expects x (seq, heads, even_dim), cos/sin (seq, dim)")
49
+ return None
50
+
51
+
52
+ @torch.library.register_fake(add_op_namespace_prefix("qk_rmsnorm_rope_bf16_"))
53
+ def _qk_rmsnorm_rope_bf16_fake(
54
+ qk: torch.Tensor,
55
+ weight: torch.Tensor,
56
+ cos: torch.Tensor,
57
+ sin: torch.Tensor,
58
+ eps: float = 1e-6,
59
+ ) -> None:
60
+ if qk.dim() != 3 or weight.shape != (qk.shape[2],) or cos.shape != (qk.shape[0], qk.shape[2]) or sin.shape != cos.shape:
61
+ raise RuntimeError("qk_rmsnorm_rope_bf16_ expects qk (rows, heads, dim), weight (dim,), cos/sin (rows, dim)")
62
+ return None
63
+
64
+
65
+ @torch.library.register_fake(add_op_namespace_prefix("qk_pair_rmsnorm_rope_bf16"))
66
+ def _qk_pair_rmsnorm_rope_bf16_fake(
67
+ q: torch.Tensor,
68
+ k: torch.Tensor,
69
+ q_weight: torch.Tensor,
70
+ k_weight: torch.Tensor,
71
+ cos: torch.Tensor,
72
+ sin: torch.Tensor,
73
+ eps: float,
74
+ q_out: torch.Tensor,
75
+ k_out: torch.Tensor,
76
+ ) -> None:
77
+ if (
78
+ q.dim() != 3
79
+ or k.dim() != 3
80
+ or q.shape[0] != k.shape[0]
81
+ or q.shape[2] != k.shape[2]
82
+ or q.shape[2] < 8
83
+ or q.shape[2] > 256
84
+ or q.shape[2] % 2 != 0
85
+ or q_weight.shape != (q.shape[2],)
86
+ or k_weight.shape != q_weight.shape
87
+ or cos.shape != (q.shape[0], q.shape[2])
88
+ or sin.shape != cos.shape
89
+ or q_out.shape != q.shape
90
+ or k_out.shape != k.shape
91
+ ):
92
+ raise RuntimeError(
93
+ "qk_pair_rmsnorm_rope_bf16 expects q/k (rows, heads, even_dim), "
94
+ "weights (dim,), cos/sin (rows, dim), and matching outputs"
95
+ )
96
+ return None
97
+
98
+
99
+ @torch.library.register_fake(add_op_namespace_prefix("gather_rows_bf16"))
100
+ def _gather_rows_bf16_fake(
101
+ src: torch.Tensor,
102
+ row_indices: torch.Tensor,
103
+ dst: torch.Tensor,
104
+ ) -> None:
105
+ if src.dim() != 2 or row_indices.dim() != 1 or dst.shape != (row_indices.numel(), src.shape[1]):
106
+ raise RuntimeError(
107
+ "gather_rows_bf16 expects src (source_rows, hidden), "
108
+ "row_indices (rows,), dst (rows, hidden)"
109
+ )
110
+ return None
111
+
112
+
113
+ @torch.library.register_fake(add_op_namespace_prefix("scatter_rows_bf16"))
114
+ def _scatter_rows_bf16_fake(
115
+ src: torch.Tensor,
116
+ row_indices: torch.Tensor,
117
+ dst: torch.Tensor,
118
+ ) -> None:
119
+ if src.dim() != 2 or row_indices.dim() != 1 or src.shape != (row_indices.numel(), dst.shape[1]):
120
+ raise RuntimeError(
121
+ "scatter_rows_bf16 expects src (rows, hidden), "
122
+ "row_indices (rows,), dst (destination_rows, hidden)"
123
+ )
124
+ return None
125
+
126
+
127
+ def fill_neginf_bf16(dst: torch.Tensor) -> torch.Tensor:
128
+ ops.fill_neginf_bf16(dst)
129
+ return dst
130
+
131
+
132
+ def add_bias_bf16_(data: torch.Tensor, bias: torch.Tensor) -> torch.Tensor:
133
+ ops.add_bias_bf16_(data, bias)
134
+ return data
135
+
136
+
137
+ def repeat_interleave_heads_bf16(
138
+ src: torch.Tensor,
139
+ repeat: int,
140
+ *,
141
+ out: Optional[torch.Tensor] = None,
142
+ ) -> torch.Tensor:
143
+ if out is None:
144
+ out = torch.empty((src.shape[0], src.shape[1] * repeat, src.shape[2]), device=src.device, dtype=src.dtype)
145
+ ops.repeat_interleave_heads_bf16(src, int(repeat), out)
146
+ return out
147
+
148
+
149
+ def text_gather_bf16(
150
+ src: torch.Tensor,
151
+ batch: int,
152
+ seq: int,
153
+ *,
154
+ out: Optional[torch.Tensor] = None,
155
+ ) -> torch.Tensor:
156
+ if out is None:
157
+ out = torch.empty((2 * batch, src.shape[1]), device=src.device, dtype=src.dtype)
158
+ ops.text_gather_bf16(src, int(batch), int(seq), out)
159
+ return out
160
+
161
+
162
+ def text_scatter_bf16(dst: torch.Tensor, src: torch.Tensor, batch: int, seq: int) -> torch.Tensor:
163
+ ops.text_scatter_bf16(dst, src, int(batch), int(seq))
164
+ return dst
165
+
166
+
167
+ def rope_rotate_half_bf16_(x: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor) -> torch.Tensor:
168
+ ops.rope_rotate_half_bf16_(x, cos, sin)
169
+ return x
170
+
171
+
172
+ def qk_rmsnorm_rope_bf16_(
173
+ qk: torch.Tensor,
174
+ weight: torch.Tensor,
175
+ cos: torch.Tensor,
176
+ sin: torch.Tensor,
177
+ eps: float = 1e-6,
178
+ ) -> torch.Tensor:
179
+ ops.qk_rmsnorm_rope_bf16_(qk, weight, cos, sin, float(eps))
180
+ return qk
181
+
182
+
183
+ def qk_pair_rmsnorm_rope_bf16(
184
+ q: torch.Tensor,
185
+ k: torch.Tensor,
186
+ q_weight: torch.Tensor,
187
+ k_weight: torch.Tensor,
188
+ cos: torch.Tensor,
189
+ sin: torch.Tensor,
190
+ eps: float = 1e-6,
191
+ *,
192
+ q_out: Optional[torch.Tensor] = None,
193
+ k_out: Optional[torch.Tensor] = None,
194
+ ) -> tuple[torch.Tensor, torch.Tensor]:
195
+ if q_out is None:
196
+ q_out = torch.empty_like(q)
197
+ if k_out is None:
198
+ k_out = torch.empty_like(k)
199
+ ops.qk_pair_rmsnorm_rope_bf16(
200
+ q, k, q_weight, k_weight, cos, sin, float(eps), q_out, k_out
201
+ )
202
+ return q_out, k_out
203
+
204
+
205
+ def gather_rows_bf16(
206
+ src: torch.Tensor,
207
+ row_indices: torch.Tensor,
208
+ *,
209
+ out: Optional[torch.Tensor] = None,
210
+ ) -> torch.Tensor:
211
+ """Gather rows using in-range CUDA int64 indices without host synchronization."""
212
+
213
+ if out is None:
214
+ out = torch.empty(
215
+ (row_indices.numel(), src.shape[1]), device=src.device, dtype=src.dtype
216
+ )
217
+ ops.gather_rows_bf16(src, row_indices, out)
218
+ return out
219
+
220
+
221
+ def scatter_rows_bf16(
222
+ src: torch.Tensor,
223
+ row_indices: torch.Tensor,
224
+ destination_rows: int,
225
+ *,
226
+ out: Optional[torch.Tensor] = None,
227
+ ) -> torch.Tensor:
228
+ """Scatter rows to unique, in-range CUDA int64 indices."""
229
+
230
+ if out is None:
231
+ out = torch.zeros(
232
+ (destination_rows, src.shape[1]), device=src.device, dtype=src.dtype
233
+ )
234
+ ops.scatter_rows_bf16(src, row_indices, out)
235
+ return out
236
+
237
+
238
+ __all__ = [
239
+ "fill_neginf_bf16",
240
+ "add_bias_bf16_",
241
+ "repeat_interleave_heads_bf16",
242
+ "text_gather_bf16",
243
+ "text_scatter_bf16",
244
+ "rope_rotate_half_bf16_",
245
+ "qk_rmsnorm_rope_bf16_",
246
+ "qk_pair_rmsnorm_rope_bf16",
247
+ "gather_rows_bf16",
248
+ "scatter_rows_bf16",
249
+ ]
build/torch211-cxx11-cu130-aarch64-linux/_ops.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _transformer_layout_primitives_cuda_916f685
3
+ ops = torch.ops._transformer_layout_primitives_cuda_916f685
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ return f"_transformer_layout_primitives_cuda_916f685::{op_name}"
build/torch211-cxx11-cu130-aarch64-linux/_transformer_layout_primitives_cuda_916f685.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c8756d718dd2b2d6ebb87618d7db67c81f18b842e7f6e4368b17e2bf60a1c9dc
3
+ size 328480
build/torch211-cxx11-cu130-aarch64-linux/metadata.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "transformer-layout-primitives",
3
+ "id": "_transformer_layout_primitives_cuda_916f685",
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": "Le2NlMbv2iPKF5/hg87FKZwzjsVjK1dras7vbnPWYx8=",
17
+ "_transformer_layout_primitives_cuda_916f685.abi3.so": "yHVtcY3SstbruHYY19tnyB8YuELn9uQ2ixfiv2Chydw=",
18
+ "_ops.py": "YTOtZXEGILlA33lBYiZozOFNN4oQApx6STt61PAHcUc=",
19
+ "transformer_layout_primitives/__init__.py": "v6p5XMfQzddhi1fLSAw4HX9CyS0rQsidvu9VsT01xi4="
20
+ }
21
+ }
22
+ }
build/torch211-cxx11-cu130-aarch64-linux/transformer_layout_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')))