liangsu9988 commited on
Commit
a10587e
·
verified ·
1 Parent(s): 9533966

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

Browse files
build/torch211-cxx11-cu130-aarch64-linux/__init__.py ADDED
@@ -0,0 +1,297 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Blockwise FP8 producers for transformer and world-model regions."""
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
+ def _check_matrix(input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor) -> None:
13
+ if (
14
+ input.dim() != 2
15
+ or input.shape[0] <= 0
16
+ or input.shape[1] <= 0
17
+ or input.shape[1] % 128 != 0
18
+ or output.shape != input.shape
19
+ or scale.shape != (input.shape[0], input.shape[1] // 128)
20
+ ):
21
+ raise RuntimeError(
22
+ "expected input/output (rows, dim) with dim a positive multiple "
23
+ "of 128 and scale (rows, dim / 128)"
24
+ )
25
+
26
+
27
+ @torch.library.register_fake(add_op_namespace_prefix("quantize_fp8_block128_bf16"))
28
+ def _quantize_fake(
29
+ input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
30
+ ) -> None:
31
+ _check_matrix(input, output, scale)
32
+ return None
33
+
34
+
35
+ @torch.library.register_fake(add_op_namespace_prefix("layer_norm_fp8_block128_bf16"))
36
+ def _layer_norm_fake(
37
+ input: torch.Tensor,
38
+ weight: torch.Tensor,
39
+ bias: torch.Tensor,
40
+ eps: float,
41
+ output: torch.Tensor,
42
+ scale: torch.Tensor,
43
+ ) -> None:
44
+ _check_matrix(input, output, scale)
45
+ if weight.shape != (input.shape[1],) or bias.shape != weight.shape:
46
+ raise RuntimeError("weight and bias must have shape (dim,)")
47
+ return None
48
+
49
+
50
+ @torch.library.register_fake(add_op_namespace_prefix("rms_norm_fp8_block128_bf16"))
51
+ def _rms_norm_fake(
52
+ input: torch.Tensor,
53
+ weight: torch.Tensor,
54
+ eps: float,
55
+ output: torch.Tensor,
56
+ scale: torch.Tensor,
57
+ ) -> None:
58
+ _check_matrix(input, output, scale)
59
+ if weight.shape != (input.shape[1],):
60
+ raise RuntimeError("weight must have shape (dim,)")
61
+ return None
62
+
63
+
64
+ @torch.library.register_fake(
65
+ add_op_namespace_prefix("residual_add_rms_norm_fp8_block128_bf16")
66
+ )
67
+ def _residual_rms_norm_fake(
68
+ residual: torch.Tensor,
69
+ input: torch.Tensor,
70
+ weight: torch.Tensor,
71
+ eps: float,
72
+ residual_out: torch.Tensor,
73
+ output: torch.Tensor,
74
+ scale: torch.Tensor,
75
+ ) -> None:
76
+ _check_matrix(input, output, scale)
77
+ if (
78
+ residual.shape != input.shape
79
+ or residual_out.shape != input.shape
80
+ or weight.shape != (input.shape[1],)
81
+ ):
82
+ raise RuntimeError("residual/output must match input and weight must be (dim,)")
83
+ return None
84
+
85
+
86
+ @torch.library.register_fake(add_op_namespace_prefix("gelu_tanh_fp8_block128_bf16"))
87
+ def _gelu_fake(
88
+ input: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
89
+ ) -> None:
90
+ _check_matrix(input, output, scale)
91
+ return None
92
+
93
+
94
+ @torch.library.register_fake(
95
+ add_op_namespace_prefix("gelu_tanh_bias_fp8_block128_bf16")
96
+ )
97
+ def _gelu_bias_fake(
98
+ input: torch.Tensor,
99
+ bias: torch.Tensor,
100
+ output: torch.Tensor,
101
+ scale: torch.Tensor,
102
+ ) -> None:
103
+ _check_matrix(input, output, scale)
104
+ if bias.shape != (input.shape[1],):
105
+ raise RuntimeError("bias must have shape (dim,)")
106
+ return None
107
+
108
+
109
+ @torch.library.register_fake(add_op_namespace_prefix("silu_mul_fp8_block128_bf16"))
110
+ def _silu_mul_fake(
111
+ gate: torch.Tensor,
112
+ up: torch.Tensor,
113
+ output: torch.Tensor,
114
+ scale: torch.Tensor,
115
+ ) -> None:
116
+ _check_matrix(gate, output, scale)
117
+ if up.shape != gate.shape:
118
+ raise RuntimeError("up must match gate")
119
+ return None
120
+
121
+
122
+ @torch.library.register_fake(
123
+ add_op_namespace_prefix("silu_mul_merged_fp8_block128_bf16")
124
+ )
125
+ def _silu_merged_fake(
126
+ gate_up: torch.Tensor, output: torch.Tensor, scale: torch.Tensor
127
+ ) -> None:
128
+ if (
129
+ gate_up.dim() != 2
130
+ or gate_up.shape[0] <= 0
131
+ or gate_up.shape[1] <= 0
132
+ or gate_up.shape[1] % 256 != 0
133
+ or output.shape != (gate_up.shape[0], gate_up.shape[1] // 2)
134
+ or scale.shape != (gate_up.shape[0], gate_up.shape[1] // 256)
135
+ ):
136
+ raise RuntimeError(
137
+ "gate_up must be (rows, 2 * dim), dim multiple of 128"
138
+ )
139
+ return None
140
+
141
+
142
+ def _allocate(input: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
143
+ return (
144
+ torch.empty_like(input, dtype=torch.float8_e4m3fn),
145
+ torch.empty(
146
+ (input.shape[0], input.shape[1] // 128),
147
+ device=input.device,
148
+ dtype=torch.float32,
149
+ ),
150
+ )
151
+
152
+
153
+ def quantize_fp8_block128_bf16(
154
+ input: torch.Tensor,
155
+ *,
156
+ output: Optional[torch.Tensor] = None,
157
+ scale: Optional[torch.Tensor] = None,
158
+ ) -> tuple[torch.Tensor, torch.Tensor]:
159
+ if output is None or scale is None:
160
+ allocated_output, allocated_scale = _allocate(input)
161
+ output = allocated_output if output is None else output
162
+ scale = allocated_scale if scale is None else scale
163
+ ops.quantize_fp8_block128_bf16(input, output, scale)
164
+ return output, scale
165
+
166
+
167
+ def layer_norm_fp8_block128_bf16(
168
+ input: torch.Tensor,
169
+ weight: torch.Tensor,
170
+ bias: torch.Tensor,
171
+ eps: float = 1e-6,
172
+ *,
173
+ output: Optional[torch.Tensor] = None,
174
+ scale: Optional[torch.Tensor] = None,
175
+ ) -> tuple[torch.Tensor, torch.Tensor]:
176
+ if output is None or scale is None:
177
+ allocated_output, allocated_scale = _allocate(input)
178
+ output = allocated_output if output is None else output
179
+ scale = allocated_scale if scale is None else scale
180
+ ops.layer_norm_fp8_block128_bf16(
181
+ input, weight, bias, float(eps), output, scale
182
+ )
183
+ return output, scale
184
+
185
+
186
+ def rms_norm_fp8_block128_bf16(
187
+ input: torch.Tensor,
188
+ weight: torch.Tensor,
189
+ eps: float = 1e-6,
190
+ *,
191
+ output: Optional[torch.Tensor] = None,
192
+ scale: Optional[torch.Tensor] = None,
193
+ ) -> tuple[torch.Tensor, torch.Tensor]:
194
+ if output is None or scale is None:
195
+ allocated_output, allocated_scale = _allocate(input)
196
+ output = allocated_output if output is None else output
197
+ scale = allocated_scale if scale is None else scale
198
+ ops.rms_norm_fp8_block128_bf16(input, weight, float(eps), output, scale)
199
+ return output, scale
200
+
201
+
202
+ def residual_add_rms_norm_fp8_block128_bf16(
203
+ residual: torch.Tensor,
204
+ input: torch.Tensor,
205
+ weight: torch.Tensor,
206
+ eps: float = 1e-6,
207
+ *,
208
+ residual_out: Optional[torch.Tensor] = None,
209
+ output: Optional[torch.Tensor] = None,
210
+ scale: Optional[torch.Tensor] = None,
211
+ ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
212
+ if residual_out is None:
213
+ residual_out = torch.empty_like(input)
214
+ if output is None or scale is None:
215
+ allocated_output, allocated_scale = _allocate(input)
216
+ output = allocated_output if output is None else output
217
+ scale = allocated_scale if scale is None else scale
218
+ ops.residual_add_rms_norm_fp8_block128_bf16(
219
+ residual, input, weight, float(eps), residual_out, output, scale
220
+ )
221
+ return residual_out, output, scale
222
+
223
+
224
+ def gelu_tanh_fp8_block128_bf16(
225
+ input: torch.Tensor,
226
+ *,
227
+ output: Optional[torch.Tensor] = None,
228
+ scale: Optional[torch.Tensor] = None,
229
+ ) -> tuple[torch.Tensor, torch.Tensor]:
230
+ if output is None or scale is None:
231
+ allocated_output, allocated_scale = _allocate(input)
232
+ output = allocated_output if output is None else output
233
+ scale = allocated_scale if scale is None else scale
234
+ ops.gelu_tanh_fp8_block128_bf16(input, output, scale)
235
+ return output, scale
236
+
237
+
238
+ def gelu_tanh_bias_fp8_block128_bf16(
239
+ input: torch.Tensor,
240
+ bias: torch.Tensor,
241
+ *,
242
+ output: Optional[torch.Tensor] = None,
243
+ scale: Optional[torch.Tensor] = None,
244
+ ) -> tuple[torch.Tensor, torch.Tensor]:
245
+ if output is None or scale is None:
246
+ allocated_output, allocated_scale = _allocate(input)
247
+ output = allocated_output if output is None else output
248
+ scale = allocated_scale if scale is None else scale
249
+ ops.gelu_tanh_bias_fp8_block128_bf16(input, bias, output, scale)
250
+ return output, scale
251
+
252
+
253
+ def silu_mul_fp8_block128_bf16(
254
+ gate: torch.Tensor,
255
+ up: torch.Tensor,
256
+ *,
257
+ output: Optional[torch.Tensor] = None,
258
+ scale: Optional[torch.Tensor] = None,
259
+ ) -> tuple[torch.Tensor, torch.Tensor]:
260
+ if output is None or scale is None:
261
+ allocated_output, allocated_scale = _allocate(gate)
262
+ output = allocated_output if output is None else output
263
+ scale = allocated_scale if scale is None else scale
264
+ ops.silu_mul_fp8_block128_bf16(gate, up, output, scale)
265
+ return output, scale
266
+
267
+
268
+ def silu_mul_merged_fp8_block128_bf16(
269
+ gate_up: torch.Tensor,
270
+ *,
271
+ output: Optional[torch.Tensor] = None,
272
+ scale: Optional[torch.Tensor] = None,
273
+ ) -> tuple[torch.Tensor, torch.Tensor]:
274
+ rows, merged_dim = gate_up.shape
275
+ dim = merged_dim // 2
276
+ if output is None:
277
+ output = torch.empty(
278
+ (rows, dim), device=gate_up.device, dtype=torch.float8_e4m3fn
279
+ )
280
+ if scale is None:
281
+ scale = torch.empty(
282
+ (rows, dim // 128), device=gate_up.device, dtype=torch.float32
283
+ )
284
+ ops.silu_mul_merged_fp8_block128_bf16(gate_up, output, scale)
285
+ return output, scale
286
+
287
+
288
+ __all__ = [
289
+ "quantize_fp8_block128_bf16",
290
+ "layer_norm_fp8_block128_bf16",
291
+ "rms_norm_fp8_block128_bf16",
292
+ "residual_add_rms_norm_fp8_block128_bf16",
293
+ "gelu_tanh_fp8_block128_bf16",
294
+ "gelu_tanh_bias_fp8_block128_bf16",
295
+ "silu_mul_fp8_block128_bf16",
296
+ "silu_mul_merged_fp8_block128_bf16",
297
+ ]
build/torch211-cxx11-cu130-aarch64-linux/_blockwise_fp8_producers_cuda_7781728.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:293d539efbdddbf49f647c269e2fd34d619e35ae6eb462dac4434780075d0bf6
3
+ size 455696
build/torch211-cxx11-cu130-aarch64-linux/_ops.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _blockwise_fp8_producers_cuda_7781728
3
+ ops = torch.ops._blockwise_fp8_producers_cuda_7781728
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ return f"_blockwise_fp8_producers_cuda_7781728::{op_name}"
build/torch211-cxx11-cu130-aarch64-linux/blockwise_fp8_producers/__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": "blockwise-fp8-producers",
3
+ "id": "_blockwise_fp8_producers_cuda_7781728",
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": "jTa/yZ4lH7PUVKeENwdd7iZgdhrc9AOOJ8+L2usA23M=",
17
+ "_blockwise_fp8_producers_cuda_7781728.abi3.so": "KT1Tnvvd2/SfZHwmni/TTWGeNa5utGLaxENHgAddC/Y=",
18
+ "_ops.py": "pl0Svm/AyQFPOD+QjsTr7CaugfBN69uRVroTvi3cHrE=",
19
+ "blockwise_fp8_producers/__init__.py": "v6p5XMfQzddhi1fLSAw4HX9CyS0rQsidvu9VsT01xi4="
20
+ }
21
+ }
22
+ }