liangsu9988 commited on
Commit
a5e66ea
·
verified ·
1 Parent(s): c999307

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

Browse files
build/torch211-cxx11-cu130-aarch64-linux/__init__.py ADDED
@@ -0,0 +1,328 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """FlashRT adaptive LayerNorm producer kernels for DiT/Wan-style blocks."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import torch
6
+
7
+ from ._ops import add_op_namespace_prefix, ops
8
+
9
+
10
+ def _check_x(x: torch.Tensor) -> None:
11
+ if x.dim() != 2:
12
+ raise RuntimeError("x must have shape (rows, dim)")
13
+ if x.shape[1] % 2 != 0:
14
+ raise RuntimeError("x.shape[1] must be even")
15
+
16
+
17
+ def _check_mod(x: torch.Tensor, scale: torch.Tensor, shift: torch.Tensor) -> None:
18
+ _check_x(x)
19
+ dim = x.shape[1]
20
+ if scale.shape != (dim,) or shift.shape != (dim,):
21
+ raise RuntimeError("scale and shift must have shape (dim,)")
22
+
23
+
24
+ def _check_scalar(scale: torch.Tensor, name: str) -> None:
25
+ if scale.numel() != 1:
26
+ raise RuntimeError(f"{name} must be a scalar tensor")
27
+
28
+
29
+ def swizzled_sf_size(rows: int, dim: int) -> int:
30
+ """Return bytes required by the FlashRT/CUTLASS NVFP4 swizzled scale layout."""
31
+
32
+ if dim % 16 != 0:
33
+ raise RuntimeError("dim must be divisible by 16 for NVFP4 swizzled output")
34
+ n_blocks = dim // 16
35
+ n_row_super = (rows + 127) // 128
36
+ n_col_super = (n_blocks + 3) // 4
37
+ return n_row_super * n_col_super * 128 * 64
38
+
39
+
40
+ def _alloc_fp8(x: torch.Tensor) -> torch.Tensor:
41
+ return torch.empty_like(x, dtype=torch.float8_e4m3fn)
42
+
43
+
44
+ def _alloc_nvfp4(x: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
45
+ rows, dim = x.shape
46
+ packed = torch.empty((rows, dim // 2), device=x.device, dtype=torch.uint8)
47
+ sf = torch.zeros((swizzled_sf_size(rows, dim),), device=x.device, dtype=torch.uint8)
48
+ return packed, sf
49
+
50
+
51
+ @torch.library.register_fake(add_op_namespace_prefix("ada_layer_norm_quant_fp8_bf16"))
52
+ def _ada_layer_norm_quant_fp8_bf16_fake(
53
+ x: torch.Tensor,
54
+ scale: torch.Tensor,
55
+ shift: torch.Tensor,
56
+ act_scale: torch.Tensor,
57
+ eps: float,
58
+ out: torch.Tensor,
59
+ ) -> None:
60
+ _check_mod(x, scale, shift)
61
+ _check_scalar(act_scale, "act_scale")
62
+ if out.shape != x.shape:
63
+ raise RuntimeError("out must have the same shape as x")
64
+ return None
65
+
66
+
67
+ @torch.library.register_fake(add_op_namespace_prefix("ada_layer_norm_quant_fp8_modfp8_bf16"))
68
+ def _ada_layer_norm_quant_fp8_modfp8_bf16_fake(
69
+ x: torch.Tensor,
70
+ scale_fp8: torch.Tensor,
71
+ shift_fp8: torch.Tensor,
72
+ scale_deq: torch.Tensor,
73
+ shift_deq: torch.Tensor,
74
+ act_scale: torch.Tensor,
75
+ eps: float,
76
+ out: torch.Tensor,
77
+ ) -> None:
78
+ _check_mod(x, scale_fp8, shift_fp8)
79
+ _check_scalar(scale_deq, "scale_deq")
80
+ _check_scalar(shift_deq, "shift_deq")
81
+ _check_scalar(act_scale, "act_scale")
82
+ if out.shape != x.shape:
83
+ raise RuntimeError("out must have the same shape as x")
84
+ return None
85
+
86
+
87
+ @torch.library.register_fake(add_op_namespace_prefix("awq_ada_layer_norm_quant_fp8_bf16"))
88
+ def _awq_ada_layer_norm_quant_fp8_bf16_fake(
89
+ x: torch.Tensor,
90
+ scale: torch.Tensor,
91
+ shift: torch.Tensor,
92
+ inv_s: torch.Tensor,
93
+ act_scale: torch.Tensor,
94
+ eps: float,
95
+ out: torch.Tensor,
96
+ ) -> None:
97
+ _check_mod(x, scale, shift)
98
+ if inv_s.shape != (x.shape[1],):
99
+ raise RuntimeError("inv_s must have shape (dim,)")
100
+ _check_scalar(act_scale, "act_scale")
101
+ if out.shape != x.shape:
102
+ raise RuntimeError("out must have the same shape as x")
103
+ return None
104
+
105
+
106
+ @torch.library.register_fake(add_op_namespace_prefix("ada_layer_norm_quant_nvfp4_swizzled_bf16"))
107
+ def _ada_layer_norm_quant_nvfp4_swizzled_bf16_fake(
108
+ x: torch.Tensor,
109
+ scale: torch.Tensor,
110
+ shift: torch.Tensor,
111
+ eps: float,
112
+ packed: torch.Tensor,
113
+ sf_swizzled: torch.Tensor,
114
+ ) -> None:
115
+ _check_mod(x, scale, shift)
116
+ rows, dim = x.shape
117
+ if packed.shape != (rows, dim // 2):
118
+ raise RuntimeError("packed must have shape (rows, dim // 2)")
119
+ if sf_swizzled.numel() < swizzled_sf_size(rows, dim):
120
+ raise RuntimeError("sf_swizzled is too small")
121
+ return None
122
+
123
+
124
+ @torch.library.register_fake(add_op_namespace_prefix("ada_layer_norm_quant_nvfp4_swizzled_modfp8_bf16"))
125
+ def _ada_layer_norm_quant_nvfp4_swizzled_modfp8_bf16_fake(
126
+ x: torch.Tensor,
127
+ scale_fp8: torch.Tensor,
128
+ shift_fp8: torch.Tensor,
129
+ scale_deq: torch.Tensor,
130
+ shift_deq: torch.Tensor,
131
+ eps: float,
132
+ packed: torch.Tensor,
133
+ sf_swizzled: torch.Tensor,
134
+ ) -> None:
135
+ _check_mod(x, scale_fp8, shift_fp8)
136
+ _check_scalar(scale_deq, "scale_deq")
137
+ _check_scalar(shift_deq, "shift_deq")
138
+ rows, dim = x.shape
139
+ if packed.shape != (rows, dim // 2):
140
+ raise RuntimeError("packed must have shape (rows, dim // 2)")
141
+ if sf_swizzled.numel() < swizzled_sf_size(rows, dim):
142
+ raise RuntimeError("sf_swizzled is too small")
143
+ return None
144
+
145
+
146
+ @torch.library.register_fake(add_op_namespace_prefix("layer_norm_no_affine_quant_fp8_static_bf16"))
147
+ def _layer_norm_no_affine_quant_fp8_static_bf16_fake(
148
+ x: torch.Tensor,
149
+ act_scale: torch.Tensor,
150
+ eps: float,
151
+ out: torch.Tensor,
152
+ ) -> None:
153
+ _check_x(x)
154
+ _check_scalar(act_scale, "act_scale")
155
+ if out.shape != x.shape:
156
+ raise RuntimeError("out must have the same shape as x")
157
+ return None
158
+
159
+
160
+ def ada_layer_norm_quant_fp8_bf16(
161
+ x: torch.Tensor,
162
+ scale: torch.Tensor,
163
+ shift: torch.Tensor,
164
+ act_scale: torch.Tensor,
165
+ eps: float = 1e-5,
166
+ out: torch.Tensor | None = None,
167
+ ) -> torch.Tensor:
168
+ """Fused no-affine LayerNorm + AdaLN scale/shift + static FP8 quantize."""
169
+
170
+ if out is None:
171
+ out = _alloc_fp8(x)
172
+ ops.ada_layer_norm_quant_fp8_bf16(x, scale, shift, act_scale, float(eps), out)
173
+ return out
174
+
175
+
176
+ def ada_layer_norm_quant_fp8_modfp8_bf16(
177
+ x: torch.Tensor,
178
+ scale_fp8: torch.Tensor,
179
+ shift_fp8: torch.Tensor,
180
+ scale_deq: torch.Tensor,
181
+ shift_deq: torch.Tensor,
182
+ act_scale: torch.Tensor,
183
+ eps: float = 1e-5,
184
+ out: torch.Tensor | None = None,
185
+ ) -> torch.Tensor:
186
+ """Fused AdaLN producer when modulation vectors are stored in FP8."""
187
+
188
+ if out is None:
189
+ out = _alloc_fp8(x)
190
+ ops.ada_layer_norm_quant_fp8_modfp8_bf16(
191
+ x, scale_fp8, shift_fp8, scale_deq, shift_deq, act_scale, float(eps), out
192
+ )
193
+ return out
194
+
195
+
196
+ def awq_ada_layer_norm_quant_fp8_bf16(
197
+ x: torch.Tensor,
198
+ scale: torch.Tensor,
199
+ shift: torch.Tensor,
200
+ inv_s: torch.Tensor,
201
+ act_scale: torch.Tensor,
202
+ eps: float = 1e-5,
203
+ out: torch.Tensor | None = None,
204
+ ) -> torch.Tensor:
205
+ """Fused AdaLN producer with AWQ/SmoothQuant per-channel activation scale."""
206
+
207
+ if out is None:
208
+ out = _alloc_fp8(x)
209
+ ops.awq_ada_layer_norm_quant_fp8_bf16(x, scale, shift, inv_s, act_scale, float(eps), out)
210
+ return out
211
+
212
+
213
+ def ada_layer_norm_quant_nvfp4_swizzled_bf16(
214
+ x: torch.Tensor,
215
+ scale: torch.Tensor,
216
+ shift: torch.Tensor,
217
+ eps: float = 1e-5,
218
+ packed: torch.Tensor | None = None,
219
+ sf_swizzled: torch.Tensor | None = None,
220
+ ) -> tuple[torch.Tensor, torch.Tensor]:
221
+ """Fused AdaLN producer to NVFP4 packed activations and swizzled scale factors."""
222
+
223
+ if packed is None or sf_swizzled is None:
224
+ packed, sf_swizzled = _alloc_nvfp4(x)
225
+ ops.ada_layer_norm_quant_nvfp4_swizzled_bf16(x, scale, shift, float(eps), packed, sf_swizzled)
226
+ return packed, sf_swizzled
227
+
228
+
229
+ def ada_layer_norm_quant_nvfp4_swizzled_modfp8_bf16(
230
+ x: torch.Tensor,
231
+ scale_fp8: torch.Tensor,
232
+ shift_fp8: torch.Tensor,
233
+ scale_deq: torch.Tensor,
234
+ shift_deq: torch.Tensor,
235
+ eps: float = 1e-5,
236
+ packed: torch.Tensor | None = None,
237
+ sf_swizzled: torch.Tensor | None = None,
238
+ ) -> tuple[torch.Tensor, torch.Tensor]:
239
+ """Fused FP8-modulated AdaLN producer to NVFP4 packed activations."""
240
+
241
+ if packed is None or sf_swizzled is None:
242
+ packed, sf_swizzled = _alloc_nvfp4(x)
243
+ ops.ada_layer_norm_quant_nvfp4_swizzled_modfp8_bf16(
244
+ x, scale_fp8, shift_fp8, scale_deq, shift_deq, float(eps), packed, sf_swizzled
245
+ )
246
+ return packed, sf_swizzled
247
+
248
+
249
+ def layer_norm_no_affine_quant_fp8_static_bf16(
250
+ x: torch.Tensor,
251
+ act_scale: torch.Tensor,
252
+ eps: float = 1e-5,
253
+ out: torch.Tensor | None = None,
254
+ ) -> torch.Tensor:
255
+ """Fused no-affine LayerNorm + static FP8 quantize."""
256
+
257
+ if out is None:
258
+ out = _alloc_fp8(x)
259
+ ops.layer_norm_no_affine_quant_fp8_static_bf16(x, act_scale, float(eps), out)
260
+ return out
261
+
262
+
263
+ @torch.library.register_fake(add_op_namespace_prefix("adaln_modulation6_bf16"))
264
+ def _adaln_modulation6_bf16_fake(
265
+ adaln_params: torch.Tensor,
266
+ layer_modulation: torch.Tensor,
267
+ out0: torch.Tensor,
268
+ out1: torch.Tensor,
269
+ out2: torch.Tensor,
270
+ out3: torch.Tensor,
271
+ out4: torch.Tensor,
272
+ out5: torch.Tensor,
273
+ ) -> None:
274
+ if adaln_params.dim() != 4 or adaln_params.shape[2] != 6:
275
+ raise RuntimeError(
276
+ "adaln_params must have shape (batch, sequence, 6, dim)"
277
+ )
278
+ expected = (
279
+ adaln_params.shape[0],
280
+ adaln_params.shape[1],
281
+ adaln_params.shape[3],
282
+ )
283
+ if layer_modulation.shape != (6, expected[2]):
284
+ raise RuntimeError("layer_modulation must have shape (6, dim)")
285
+ for output in (out0, out1, out2, out3, out4, out5):
286
+ if output.shape != expected:
287
+ raise RuntimeError(
288
+ "each output must have shape (batch, sequence, dim)"
289
+ )
290
+ return None
291
+
292
+
293
+ def adaln_modulation6_bf16(
294
+ adaln_params: torch.Tensor,
295
+ layer_modulation: torch.Tensor,
296
+ *,
297
+ out: tuple[torch.Tensor, ...] | None = None,
298
+ ) -> tuple[torch.Tensor, ...]:
299
+ """Add six FP32 AdaLN modulation vectors and return six BF16 tensors."""
300
+
301
+ batch, sequence, _, dim = adaln_params.shape
302
+ if out is None:
303
+ out = tuple(
304
+ torch.empty(
305
+ (batch, sequence, dim),
306
+ device=adaln_params.device,
307
+ dtype=torch.bfloat16,
308
+ )
309
+ for _ in range(6)
310
+ )
311
+ if len(out) != 6:
312
+ raise RuntimeError("out must contain six tensors")
313
+ ops.adaln_modulation6_bf16(
314
+ adaln_params, layer_modulation, *out
315
+ )
316
+ return out
317
+
318
+
319
+ __all__ = [
320
+ "ada_layer_norm_quant_fp8_bf16",
321
+ "ada_layer_norm_quant_fp8_modfp8_bf16",
322
+ "awq_ada_layer_norm_quant_fp8_bf16",
323
+ "ada_layer_norm_quant_nvfp4_swizzled_bf16",
324
+ "ada_layer_norm_quant_nvfp4_swizzled_modfp8_bf16",
325
+ "layer_norm_no_affine_quant_fp8_static_bf16",
326
+ "adaln_modulation6_bf16",
327
+ "swizzled_sf_size",
328
+ ]
build/torch211-cxx11-cu130-aarch64-linux/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (13.8 kB). View file
 
build/torch211-cxx11-cu130-aarch64-linux/__pycache__/_ops.cpython-312.pyc ADDED
Binary file (599 Bytes). View file
 
build/torch211-cxx11-cu130-aarch64-linux/_adaptive_layernorm_producers_cuda_7781728.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:34e6e6e5a82ce354180b41746d8e703825a0bca39a247e0eb326710951f6b497
3
+ size 389352
build/torch211-cxx11-cu130-aarch64-linux/_ops.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _adaptive_layernorm_producers_cuda_7781728
3
+ ops = torch.ops._adaptive_layernorm_producers_cuda_7781728
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ return f"_adaptive_layernorm_producers_cuda_7781728::{op_name}"
build/torch211-cxx11-cu130-aarch64-linux/adaptive_layernorm_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/adaptive_layernorm_producers/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (1.39 kB). View file
 
build/torch211-cxx11-cu130-aarch64-linux/metadata.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "adaptive-layernorm-producers",
3
+ "id": "_adaptive_layernorm_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": "4NZMN7oQ+stR735F4NXwBZ1dbTlAj1Q67+X/X6B/8zI=",
17
+ "_adaptive_layernorm_producers_cuda_7781728.abi3.so": "NObm5ags41QYC0F0bY5wOCWgvKOaJH4OsyZxCVH2tJc=",
18
+ "_ops.py": "kG1EL+EuLDtXPuUtyj/ygYLPUZg6eszWjMCBtbLC0pw=",
19
+ "adaptive_layernorm_producers/__init__.py": "v6p5XMfQzddhi1fLSAw4HX9CyS0rQsidvu9VsT01xi4="
20
+ }
21
+ }
22
+ }