liangsu9988 commited on
Commit
ff2f6be
·
verified ·
1 Parent(s): 485c421

Initialize legacy kernels compatibility mirror

Browse files
Files changed (1) hide show
  1. README.md +6 -138
README.md CHANGED
@@ -1,141 +1,9 @@
1
- # adaptive-layernorm-producers
2
 
3
- FlashRT native CUDA producer kernels for DiT/Wan-style adaptive LayerNorm
4
- blocks.
5
 
6
- This package fuses the producer side of the block:
7
 
8
- ```text
9
- LayerNorm / adaptive LayerNorm modulation -> low-precision activation
10
- ```
11
-
12
- into a single Kernel Hub operator. It is intended for transformer and diffuser
13
- runtimes where the following GEMM already consumes FP8 or NVFP4 activations.
14
- Without this fusion, the runtime pays for separate normalization, modulation,
15
- BF16 materialization, and quantization launches before the GEMM.
16
-
17
- The source kernels are derived from the production FlashRT runtime:
18
-
19
- - `official/FlashRT/csrc/quantize/ada_layer_norm_fp8.cu`
20
- - `official/FlashRT/csrc/kernels/dit_bf16.cu::layer_norm_no_affine_fp8_static_bf16`
21
-
22
- The full FlashRT model runtime and serving pipeline live upstream at
23
- [LiangSu8899/FlashRT](https://github.com/LiangSu8899/FlashRT).
24
-
25
- ## Available Functions
26
-
27
- - `ada_layer_norm_quant_fp8_bf16(x, scale, shift, act_scale, eps=1e-5, out=None)`
28
- - `ada_layer_norm_quant_fp8_ptok_bf16(x, scale, shift, act_scale, eps=1e-5, out=None)`
29
- - `ada_layer_norm_quant_fp8_ptok_table_bf16(x, temb, table, act_scale, shift_idx, scale_idx, eps=1e-5, out=None)`
30
- - `ada_layer_norm_quant_fp8_modfp8_bf16(x, scale_fp8, shift_fp8, scale_deq, shift_deq, act_scale, eps=1e-5, out=None)`
31
- - `awq_ada_layer_norm_quant_fp8_bf16(x, scale, shift, inv_s, act_scale, eps=1e-5, out=None)`
32
- - `ada_layer_norm_quant_nvfp4_swizzled_bf16(x, scale, shift, eps=1e-5, packed=None, sf_swizzled=None)`
33
- - `ada_layer_norm_quant_nvfp4_swizzled_modfp8_bf16(x, scale_fp8, shift_fp8, scale_deq, shift_deq, eps=1e-5, packed=None, sf_swizzled=None)`
34
- - `layer_norm_no_affine_quant_fp8_static_bf16(x, act_scale, eps=1e-5, out=None)`
35
- - `adaln_modulation6_bf16(adaln_params, layer_modulation, out=None)`
36
- - `swizzled_sf_size(rows, dim)`
37
-
38
- ## Tensor Contract
39
-
40
- - `x`: contiguous CUDA `torch.bfloat16`, shape `(rows, dim)`.
41
- - Broadcast `scale`, `shift`, and `inv_s`: contiguous CUDA
42
- `torch.bfloat16`, shape `(dim,)`.
43
- - Per-token `scale` and `shift`: contiguous CUDA `torch.bfloat16`, shape
44
- `(rows, dim)`.
45
- - Table form `temb`: contiguous CUDA `torch.bfloat16`, shape
46
- `(rows, chunks, dim)`; `table`: contiguous CUDA `torch.float32`, shape
47
- `(chunks, dim)`.
48
- - `scale_fp8`, `shift_fp8`: contiguous CUDA `torch.float8_e4m3fn`, shape `(dim,)`.
49
- - `scale_deq`, `shift_deq`, `act_scale`: CUDA `torch.float32` scalar tensors.
50
- - FP8 outputs use `torch.float8_e4m3fn`, shape `(rows, dim)`.
51
- - NVFP4 packed output uses `torch.uint8`, shape `(rows, dim // 2)`.
52
- - NVFP4 scale output uses the FlashRT/CUTLASS 128x4 swizzled uint8 scale
53
- layout. Allocate with `swizzled_sf_size(rows, dim)`.
54
- - `dim` must be even for FP8 outputs and divisible by 16 for NVFP4 outputs.
55
- - The package targets CUDA 12.8+ and Blackwell-class deployment paths.
56
- - `adaln_modulation6_bf16` takes FP32 `(batch, sequence, 6, dim)` parameters
57
- plus FP32 `(6, dim)` layer modulation and returns six BF16
58
- `(batch, sequence, dim)` tensors.
59
-
60
- ## Minimal Usage
61
-
62
- ```python
63
- from kernels import get_kernel
64
- import torch
65
-
66
- ops = get_kernel("flashrt/adaptive-layernorm-producers", version=1, trust_remote_code=True)
67
-
68
- rows, dim = 2520, 3072
69
- x = torch.randn((rows, dim), device="cuda", dtype=torch.bfloat16)
70
- scale = torch.zeros((dim,), device="cuda", dtype=torch.bfloat16)
71
- shift = torch.zeros((dim,), device="cuda", dtype=torch.bfloat16)
72
- act_scale = torch.tensor([0.025], device="cuda", dtype=torch.float32)
73
-
74
- x_fp8 = ops.ada_layer_norm_quant_fp8_bf16(x, scale, shift, act_scale)
75
- ```
76
-
77
- Per-token modulation without materializing a broadcast buffer:
78
-
79
- ```python
80
- ptok_scale = torch.zeros_like(x)
81
- ptok_shift = torch.zeros_like(x)
82
- x_fp8 = ops.ada_layer_norm_quant_fp8_ptok_bf16(
83
- x, ptok_scale, ptok_shift, act_scale
84
- )
85
- ```
86
-
87
- Fused host modulation table add and chunk selection:
88
-
89
- ```python
90
- chunks = 6
91
- temb = torch.zeros((rows, chunks, dim), device="cuda", dtype=torch.bfloat16)
92
- table = torch.zeros((chunks, dim), device="cuda", dtype=torch.float32)
93
- x_fp8 = ops.ada_layer_norm_quant_fp8_ptok_table_bf16(
94
- x, temb, table, act_scale, shift_idx=0, scale_idx=1
95
- )
96
- ```
97
-
98
- Static-buffer usage for CUDA Graph capture:
99
-
100
- ```python
101
- out = torch.empty_like(x, dtype=torch.float8_e4m3fn)
102
- ops.ada_layer_norm_quant_fp8_bf16(x, scale, shift, act_scale, out=out)
103
- ```
104
-
105
- NVFP4 producer:
106
-
107
- ```python
108
- packed, sf = ops.ada_layer_norm_quant_nvfp4_swizzled_bf16(x, scale, shift)
109
- ```
110
-
111
- Six-way DiT modulation:
112
-
113
- ```python
114
- params = torch.randn((1, rows, 6, dim), device="cuda", dtype=torch.float32)
115
- modulation = torch.randn((6, dim), device="cuda", dtype=torch.float32)
116
- outputs = ops.adaln_modulation6_bf16(params, modulation)
117
- ```
118
-
119
- ## Validation
120
-
121
- ```bash
122
- python adaptive-layernorm-producers/tests/test_adaptive_layernorm_producers.py --backend source --mode full
123
- python adaptive-layernorm-producers/benchmarks/benchmark.py --backend source --iters 100
124
- ```
125
-
126
- The validation suite checks exact FP8 output for small producer shapes, exact
127
- NVFP4 packed/scalefactor output for representative shapes, and strict FP8
128
- boundary accounting for long video shapes. The long-shape policy requires
129
- `p99_abs == 0` and only a tiny count of adjacent FP8-code boundary differences
130
- against the eager reference.
131
-
132
- See `VALIDATION.md` and `benchmarks/RESULTS.md` for the current local RTX 5090
133
- source-build results.
134
-
135
- The aarch64 release variant `torch211-cxx11-cu130-aarch64-linux` contains
136
- native SM87 and SM110a code objects. Its SM110a path was validated on NVIDIA
137
- Thor from the exact Hub-downloaded artifact over decode, DiT, vision, and
138
- 2K/4K video rows. The two per-token entry points were also compared directly
139
- with their raw registered ops using A-B-B-A timing; all six wrapper/raw rows
140
- were bit-exact and the measured ratio was `0.997-1.000`. SM87 runtime
141
- validation remains pending on Jetson AGX Orin hardware.
 
1
+ # flashrt/adaptive-layernorm-producers
2
 
3
+ This repository is a compatibility mirror for older `kernels` clients
4
+ that resolve repositories through the default Hugging Face model repo API.
5
 
6
+ Canonical Kernel Hub repo: https://huggingface.co/kernels/flashrt/adaptive-layernorm-producers
7
 
8
+ Do not edit this mirror by hand. It is generated from the Kernel Hub
9
+ `vN` branches and contains the same `build/**` artifacts.