disentangled-flash 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,338 @@
1
+ Metadata-Version: 2.4
2
+ Name: disentangled-flash
3
+ Version: 0.1.0
4
+ Summary: Fast exact DeBERTa-style disentangled attention in Triton
5
+ Author-email: Delyan Boychev <delyan.boychev05@gmail.com>
6
+ License-Expression: Apache-2.0
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: torch>=2.7
11
+ Provides-Extra: hf
12
+ Requires-Dist: transformers>=4.57; extra == "hf"
13
+ Requires-Dist: sentencepiece>=0.2; extra == "hf"
14
+ Requires-Dist: protobuf>=4; extra == "hf"
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest>=8; extra == "dev"
17
+ Requires-Dist: ruff>=0.12; extra == "dev"
18
+ Dynamic: license-file
19
+
20
+ # DisentangledFlash
21
+
22
+ [![CI](https://github.com/delyan-boychev/disentangled-flash/actions/workflows/ci.yml/badge.svg)](https://github.com/delyan-boychev/disentangled-flash/actions/workflows/ci.yml)
23
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
24
+
25
+ ***Fast exact DeBERTa-style disentangled attention in Triton.***
26
+
27
+ DisentangledFlash is an inference-oriented implementation of bidirectional
28
+ DeBERTa-v2/v3 disentangled self-attention.
29
+
30
+ The Triton kernel is inspired by [FlashAttention](https://github.com/Dao-AILab/flash-attention)'s tiling, IO-aware computations, and online softmax without memory materialization, while its relative position encoding implementation is inspired by [FlexAttention](https://pytorch.org/blog/flexattention/). It fuses QK, relative-score lookup, factorized padding-mask application, online softmax, and PV without materializing a `[B, H, L, L]` attention tensor. C2P/P2C projection score GEMMs remain regular PyTorch GEMMs over the pruned active relative-position slots.
31
+
32
+ The PyTorch-optimized (`torch`) backend is constructed by optimizing operations, employing smart caching techniques, and leveraging fused QKV projection.
33
+
34
+
35
+ ## Status
36
+
37
+ - NVIDIA CUDA + Triton
38
+ - inference only
39
+ - DeBERTa-v2/v3-style C2P/P2C disentangled attention
40
+ - FP16, BF16, strict FP32, and optional fast FP32/TF32 mode
41
+ - head dimensions 32, 64, and 128
42
+ - factorized 2-D padding masks
43
+ - prepared fixed-length buckets with dynamic batch size
44
+ - **fused QKV projection is always enabled** for the PyTorch/Triton backends
45
+
46
+ Training/backward is not implemented. CPU/MPS use the PyTorch backend
47
+ for development/benchmarking, not the Triton kernel.
48
+
49
+ While currently tailored to DeBERTa-v2/v3, the kernel and caching abstractions are designed to be extensible to other architectures requiring factorized relative-position or disentangled attention schemes in the future.
50
+
51
+ > [!IMPORTANT]
52
+ > **GPU Compatibility**: The Triton kernel has been validated and benchmarked primarily on the **NVIDIA RTX 6000 Ada** (Compute Capability 8.9). Further testing, benchmarking, and autotuning calibration are required to ensure optimal performance on other GPU models and hardware architectures. **Pull requests, benchmark results, and configurations for other GPUs are highly welcome!**
53
+
54
+ ## Install
55
+
56
+ Use a PyTorch build appropriate for your CUDA environment, then install this
57
+ repository editable while developing:
58
+
59
+ ```bash
60
+ pip install -e ".[dev]"
61
+ ```
62
+
63
+ For the pretrained Hugging Face MNLI parity benchmark:
64
+
65
+ ```bash
66
+ pip install -e ".[dev,hf]"
67
+ ```
68
+
69
+ `sentencepiece` and `protobuf` are included in the `hf` extra because the
70
+ DeBERTa-v2 tokenizer uses a SentencePiece `spm.model`.
71
+
72
+ ## Hugging Face usage
73
+
74
+ ```python
75
+ from transformers import AutoModelForSequenceClassification
76
+ from disentangled_flash import optimize_deberta
77
+
78
+ model = (
79
+ AutoModelForSequenceClassification.from_pretrained("microsoft/deberta-v2-xlarge-mnli")
80
+ .cuda()
81
+ .eval()
82
+ )
83
+
84
+ optimize_deberta(
85
+ model.deberta,
86
+ sequence_lengths=[64, 128, 256, 512],
87
+ )
88
+ ```
89
+
90
+ `optimize_deberta()` replaces only the DeBERTa encoder attention path. The
91
+ existing layer output, residual, FFN, convolution, classifier, and checkpoint
92
+ parameter names are preserved.
93
+
94
+ For lower-level experiments, `enable_deberta_inference(..., backend="optimized")`
95
+ selects the PyTorch backend instead of Triton.
96
+
97
+ ## CUDA benchmark
98
+
99
+ Attention-only:
100
+
101
+ ```bash
102
+ python -m benchmarks.benchmark_cuda --scope attention
103
+ ```
104
+
105
+ Full encoder:
106
+
107
+ ```bash
108
+ python -m benchmarks.benchmark_cuda \
109
+ --scope encoder \
110
+ --implementations original,optimized,triton \
111
+ --dtypes fp16,fp32 \
112
+ --output encoder_attention_cuda_results.json
113
+ ```
114
+
115
+ The original backend remains unfused and acts as the reference baseline. The
116
+ PyTorch and Triton backends always use one packed QKV projection.
117
+
118
+ ## Pretrained task parity + speed
119
+
120
+ The MNLI script loads `microsoft/deberta-v2-xlarge-mnli`, compares the untouched
121
+ Hugging Face model with the same checkpoint using DisentangledFlash, verifies
122
+ logits/probabilities/hidden-state parity, and benchmarks the full classification
123
+ forward. Tokenization and model loading are excluded from timing.
124
+
125
+ Defaults are batch size 8 and 500 measured iterations:
126
+
127
+ ```bash
128
+ python -m benchmarks.parity_pretrained_mnli
129
+ ```
130
+
131
+ ## Hostile CUDA validation
132
+
133
+ ```bash
134
+ python -m validation.validate_cuda
135
+ ```
136
+
137
+ The validation matrix covers FP16/BF16/FP32, boundary sequence lengths, several
138
+ padding patterns, and C2P/P2C position modes while reporting raw max/mean errors.
139
+
140
+ > [!NOTE]
141
+ > **Test Coverage**: The current test suite is basic and incomplete. Expanding testing to cover more edge cases, parameters, and configurations is actively planned and is work to be done.
142
+
143
+ ## Autotuning
144
+
145
+ The autotuning is to be optimized in the future as it is currently greedy (evaluating too many configuration candidates). The next step is to run offline calibration sweeps per GPU family to determine and pre-select the fastest block configurations, significantly reducing runtime compilation and tuning overhead.
146
+
147
+ Do not treat the current candidate table as a universal final table for every GPU.
148
+
149
+
150
+ ## Results
151
+
152
+ DisentangledFlash was benchmarked against:
153
+
154
+ - the original Hugging Face DeBERTa encoder,
155
+ - the PyTorch implementation,
156
+ - and the Triton DisentangledFlash implementation.
157
+
158
+ The benchmark covers the full 12-layer encoder, not only the isolated attention operator.
159
+
160
+ ### Benchmark configuration
161
+
162
+ | Parameter | Value |
163
+ |---|---:|
164
+ | Hidden size | 768 |
165
+ | Attention heads | 12 |
166
+ | Head dimension | 64 |
167
+ | Encoder layers | 12 |
168
+ | FFN intermediate size | 3072 |
169
+ | Convolution kernel | 3 |
170
+ | Batch sizes | 1, 8, 16, 32 |
171
+ | Sequence lengths | 16, 32, 64, 128, 256, 384, 512 |
172
+ | Precisions | FP16, strict FP32 |
173
+ | Execution mode | Eager |
174
+ | GPU | NVIDIA RTX 6000 Ada Generation |
175
+ | Compute capability | 8.9 |
176
+
177
+ > The benchmark snapshot below predates the current always-fused-QKV API and was run with QKV fusion disabled for both the PyTorch and Triton backends. The current DisentangledFlash implementation always uses fused QKV projection.
178
+
179
+ ### Overall encoder speedup
180
+
181
+ Across all 28 tested `(batch size, sequence length)` configurations per precision:
182
+
183
+ | Precision | Geomean speedup vs. Hugging Face | Geomean speedup vs. PyTorch impl. | Best speedup vs. PyTorch impl. |
184
+ |---|---:|---:|---:|
185
+ | FP16 | **1.75×** | **1.32×** | **1.97×** |
186
+ | FP32 | **1.56×** | **1.24×** | **1.50×** |
187
+
188
+ The advantage over the PyTorch implementation increases substantially for longer sequences, where the quadratic attention matrix becomes increasingly expensive.
189
+
190
+ ### FP16 encoder latency
191
+
192
+ Median end-to-end encoder latency:
193
+
194
+ | Batch | Seq. length | Hugging Face | PyTorch impl. | DisentangledFlash | vs. HF | vs. PyTorch impl. |
195
+ |---:|---:|---:|---:|---:|---:|---:|
196
+ | 8 | 128 | 6.25 ms | 3.79 ms | **3.27 ms** | **1.91×** | **1.16×** |
197
+ | 8 | 256 | 7.56 ms | 7.09 ms | **5.27 ms** | **1.43×** | **1.34×** |
198
+ | 8 | 384 | 14.16 ms | 14.73 ms | **9.73 ms** | **1.45×** | **1.51×** |
199
+ | 8 | 512 | 21.94 ms | 22.70 ms | **12.03 ms** | **1.82×** | **1.89×** |
200
+ | 16 | 128 | 6.32 ms | 6.18 ms | **4.84 ms** | **1.30×** | **1.27×** |
201
+ | 16 | 256 | 15.40 ms | 16.58 ms | **11.36 ms** | **1.36×** | **1.46×** |
202
+ | 16 | 384 | 30.61 ms | 32.86 ms | **20.61 ms** | **1.48×** | **1.59×** |
203
+ | 16 | 512 | 52.37 ms | 53.44 ms | **27.19 ms** | **1.93×** | **1.97×** |
204
+ | 32 | 128 | 12.50 ms | 13.09 ms | **9.48 ms** | **1.32×** | **1.38×** |
205
+ | 32 | 256 | 33.81 ms | 36.35 ms | **24.61 ms** | **1.37×** | **1.48×** |
206
+ | 32 | 384 | 67.93 ms | 71.55 ms | **41.08 ms** | **1.65×** | **1.74×** |
207
+ | 32 | 512 | 108.11 ms | 110.28 ms | **57.84 ms** | **1.87×** | **1.91×** |
208
+
209
+ At `B=16, L=512`, DisentangledFlash reduces encoder latency from **53.44 ms to 27.19 ms** relative to the PyTorch path, corresponding to approximately a **49% latency reduction**.
210
+
211
+ ### FP32 encoder latency
212
+
213
+ Strict FP32 also benefits significantly:
214
+
215
+ | Batch | Seq. length | Hugging Face | PyTorch impl. | DisentangledFlash | vs. HF | vs. PyTorch impl. |
216
+ |---:|---:|---:|---:|---:|---:|---:|
217
+ | 8 | 128 | 12.86 ms | 11.93 ms | **10.22 ms** | **1.26×** | **1.17×** |
218
+ | 8 | 256 | 27.24 ms | 27.50 ms | **22.73 ms** | **1.20×** | **1.21×** |
219
+ | 8 | 384 | 45.98 ms | 45.91 ms | **34.40 ms** | **1.34×** | **1.33×** |
220
+ | 8 | 512 | 70.78 ms | 69.20 ms | **46.09 ms** | **1.54×** | **1.50×** |
221
+ | 16 | 128 | 25.50 ms | 24.47 ms | **21.11 ms** | **1.21×** | **1.16×** |
222
+ | 16 | 256 | 52.04 ms | 53.26 ms | **41.73 ms** | **1.25×** | **1.28×** |
223
+ | 16 | 384 | 93.33 ms | 93.72 ms | **65.53 ms** | **1.42×** | **1.43×** |
224
+ | 16 | 512 | 137.84 ms | 137.07 ms | **91.96 ms** | **1.50×** | **1.49×** |
225
+ | 32 | 128 | 46.55 ms | 45.94 ms | **38.61 ms** | **1.21×** | **1.19×** |
226
+ | 32 | 256 | 109.15 ms | 110.59 ms | **84.57 ms** | **1.29×** | **1.31×** |
227
+ | 32 | 384 | 183.83 ms | 185.52 ms | **130.02 ms** | **1.41×** | **1.43×** |
228
+ | 32 | 512 | 280.22 ms | 278.36 ms | **187.99 ms** | **1.49×** | **1.48×** |
229
+
230
+ ### Scaling with sequence length
231
+
232
+ Geometric-mean speedup across all tested batch sizes:
233
+
234
+ | Sequence length | FP16 vs. HF | FP16 vs. PyTorch impl. | FP32 vs. HF | FP32 vs. PyTorch impl. |
235
+ |---:|---:|---:|---:|---:|
236
+ | 16 | **1.96×** | **1.17×** | **2.10×** | **1.18×** |
237
+ | 32 | **1.89×** | **1.18×** | **1.75×** | **1.17×** |
238
+ | 64 | **1.81×** | **1.15×** | **1.52×** | **1.13×** |
239
+ | 128 | **1.60×** | **1.23×** | **1.38×** | **1.17×** |
240
+ | 256 | **1.52×** | **1.39×** | **1.37×** | **1.27×** |
241
+ | 384 | **1.63×** | **1.48×** | **1.40×** | **1.34×** |
242
+ | 512 | **1.91×** | **1.69×** | **1.55×** | **1.47×** |
243
+
244
+ The comparison against the PyTorch implementation is particularly useful: both implementations already avoid several pieces of Hugging Face encoder overhead, so the increasing gap at long sequence lengths isolates the benefit of the streaming Triton attention path more clearly.
245
+
246
+ ### Peak GPU memory
247
+
248
+ At batch size 32, the memory advantage grows with sequence length:
249
+
250
+ #### FP16
251
+
252
+ | Sequence length | Hugging Face | PyTorch impl. | DisentangledFlash | Reduction vs. PyTorch impl. |
253
+ |---:|---:|---:|---:|---:|
254
+ | 128 | 0.64 GB | 0.73 GB | **0.70 GB** | 4.2% |
255
+ | 256 | 0.96 GB | 1.10 GB | **0.97 GB** | 12.3% |
256
+ | 384 | 1.45 GB | 1.58 GB | **1.26 GB** | 20.3% |
257
+ | 512 | 2.09 GB | 2.14 GB | **1.55 GB** | **27.3%** |
258
+
259
+ #### FP32
260
+
261
+ | Sequence length | Hugging Face | PyTorch impl. | DisentangledFlash | Reduction vs. PyTorch impl. |
262
+ |---:|---:|---:|---:|---:|
263
+ | 128 | 1.25 GB | 1.44 GB | **1.38 GB** | 3.8% |
264
+ | 256 | 1.87 GB | 2.19 GB | **1.92 GB** | 12.2% |
265
+ | 384 | 2.85 GB | 3.13 GB | **2.50 GB** | 20.3% |
266
+ | 512 | 4.12 GB | 4.25 GB | **3.09 GB** | **27.3%** |
267
+
268
+ This behavior is expected because DisentangledFlash performs tiled streaming softmax and does not materialize the full `[B, H, L, L]` attention score/probability tensor.
269
+
270
+ ### Numerical accuracy
271
+
272
+ DisentangledFlash was compared directly against the original Hugging Face implementation at both the isolated attention level and across the full 12-layer DeBERTa encoder.
273
+
274
+ | Precision | Level | Max absolute error | Mean absolute error |
275
+ |---|---|---:|---:|
276
+ | FP16 | Attention | **7.63e-6** | **2.48e-7** |
277
+ | FP16 | Full encoder | **1.56e-2** | **1.12e-3** |
278
+ | FP32 | Attention | **4.89e-9** | **1.79e-10** |
279
+ | FP32 | Full encoder | **7.57e-6** | **6.26e-7** |
280
+
281
+ The maximum absolute error is the worst observed value across all tested batch-size and sequence-length configurations. The mean absolute error is averaged across the 28 tested configurations for each precision and level.
282
+
283
+ ### Pretrained-model parity
284
+
285
+ Task-level parity was additionally tested with the pretrained `microsoft/deberta-v2-xlarge-mnli` checkpoint.
286
+
287
+ The original Hugging Face model and the same checkpoint with its DeBERTa encoder replaced by DisentangledFlash achieved **full task-level parity** on the parity test.
288
+
289
+ The test verifies:
290
+
291
+ - final MNLI predictions,
292
+ - classification logits and probabilities,
293
+ - final encoder hidden states,
294
+ - and the complete sequence-classification inference path.
295
+
296
+ This test exercising a real pretrained DeBERTa model rather than only synthetic attention tensors.
297
+
298
+ ### Test environment
299
+
300
+ All current CUDA benchmarks and pretrained-model parity tests were run on:
301
+
302
+ | Component | Configuration |
303
+ |---|---|
304
+ | OS | Ubuntu 24.04.3 LTS |
305
+ | GPU | NVIDIA RTX 6000 Ada Generation |
306
+ | Compute capability | 8.9 |
307
+ | CUDA | 13.0 |
308
+ | PyTorch | 2.13.0+cu13 |
309
+ | Triton | 3.7.1 |
310
+ | Transformers | 5.15.1 |
311
+ | CPU | AMD Ryzen Threadripper PRO 7975WX, 32 cores |
312
+ | System RAM | 512 GB |
313
+
314
+ Latency numbers above are steady-state measurements. Triton compilation and autotuning startup cost are excluded from the reported p50 latency.
315
+
316
+ Further validation and benchmarking are needed on other GPU architectures and configurations to guarantee optimal tuning and performance across different hardware.
317
+
318
+
319
+ ## Attribution
320
+
321
+ The auditable reference implementation is derived from Hugging Face Transformers
322
+ 4.57.6 DeBERTa-v2/v3 modeling code and retains its original Apache-2.0 header.
323
+ See `THIRD_PARTY_NOTICES.md`.
324
+
325
+ ## Citation
326
+
327
+ If you use DisentangledFlash in your research or project, please cite it as follows:
328
+
329
+ ```bibtex
330
+ @software{boychev2026disentangledflash,
331
+ author = {Boychev, Delyan},
332
+ title = {DisentangledFlash: Fast exact DeBERTa-style disentangled attention in Triton},
333
+ url = {https://github.com/delyan-boychev/disentangled-flash},
334
+ version = {0.1.0},
335
+ year = {2026}
336
+ }
337
+ ```
338
+