mjolnir-kernel 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.
- mjolnir_kernel-0.1.0/.gitignore +28 -0
- mjolnir_kernel-0.1.0/LICENSE +202 -0
- mjolnir_kernel-0.1.0/NOTICE +64 -0
- mjolnir_kernel-0.1.0/PKG-INFO +222 -0
- mjolnir_kernel-0.1.0/README.md +192 -0
- mjolnir_kernel-0.1.0/mjolnir/__init__.py +76 -0
- mjolnir_kernel-0.1.0/mjolnir/backend.py +934 -0
- mjolnir_kernel-0.1.0/mjolnir/banner.py +127 -0
- mjolnir_kernel-0.1.0/mjolnir/calibrate.py +182 -0
- mjolnir_kernel-0.1.0/mjolnir/draftvocab.py +150 -0
- mjolnir_kernel-0.1.0/mjolnir/kvfp6.py +326 -0
- mjolnir_kernel-0.1.0/mjolnir/kvscales.py +162 -0
- mjolnir_kernel-0.1.0/mjolnir/lmhead.py +379 -0
- mjolnir_kernel-0.1.0/mjolnir/qpack.py +132 -0
- mjolnir_kernel-0.1.0/mjolnir/runner.py +754 -0
- mjolnir_kernel-0.1.0/mjolnir/t5_decode.py +2990 -0
- mjolnir_kernel-0.1.0/pyproject.toml +55 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
.venv/
|
|
4
|
+
.pytest_cache/
|
|
5
|
+
.ruff_cache/
|
|
6
|
+
dist/
|
|
7
|
+
build/
|
|
8
|
+
*.egg-info/
|
|
9
|
+
.mjolnir-state.json
|
|
10
|
+
data/
|
|
11
|
+
runs/
|
|
12
|
+
# benchmark data: the structured verify results are committed (charts,
|
|
13
|
+
# README and docs are rendered from them); logs and e2e raw dirs are not
|
|
14
|
+
benchmarks/raw/*
|
|
15
|
+
!benchmarks/raw/verify/
|
|
16
|
+
# accuracy: accuracy.json per run is committed; each leg's tool-eval-bench
|
|
17
|
+
# workdir (SQLite, trace reports, server log) is not
|
|
18
|
+
!benchmarks/raw/accuracy/
|
|
19
|
+
benchmarks/raw/accuracy/*/*/
|
|
20
|
+
benchmarks/logs/
|
|
21
|
+
task/
|
|
22
|
+
|
|
23
|
+
# autoresearch: the live ledger is untracked (discards are `git reset --hard`);
|
|
24
|
+
# `mjolnir autoresearch export` snapshots it into research/runs/<tag>/
|
|
25
|
+
research/ledger.jsonl
|
|
26
|
+
research/ledger.tsv
|
|
27
|
+
# …and the exported runs ARE committed (the generic runs/ rule above would hide them)
|
|
28
|
+
!research/runs/
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
Mjolnir
|
|
2
|
+
Copyright 2026 Mieszko Syty (ms1design)
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (see LICENSE),
|
|
5
|
+
except where a file states otherwise. It includes or modifies the third-party
|
|
6
|
+
works listed below; each keeps its own license and copyright notice.
|
|
7
|
+
|
|
8
|
+
-------------------------------------------------------------------------------
|
|
9
|
+
1. NVIDIA CUTLASS — CuTe DSL examples BSD-3-Clause
|
|
10
|
+
-------------------------------------------------------------------------------
|
|
11
|
+
src/mjolnir/mjolnir/t5_decode.py (the Mjolnir decode-attention kernel) is
|
|
12
|
+
derived from
|
|
13
|
+
|
|
14
|
+
examples/python/CuTeDSL/cute/blackwell/kernel/attention/mixed_input_fmha/
|
|
15
|
+
mixed_input_fmha_decode.py
|
|
16
|
+
https://github.com/NVIDIA/cutlass
|
|
17
|
+
Copyright (c) 2025 - 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
18
|
+
|
|
19
|
+
The file is distributed under the BSD-3-Clause license, as a whole, with the
|
|
20
|
+
original NVIDIA notice and license text retained at its top; the Mjolnir
|
|
21
|
+
modifications to it are Copyright (c) 2026 Mieszko Syty and are licensed under
|
|
22
|
+
the same BSD-3-Clause terms.
|
|
23
|
+
|
|
24
|
+
-------------------------------------------------------------------------------
|
|
25
|
+
2. vLLM Apache-2.0
|
|
26
|
+
-------------------------------------------------------------------------------
|
|
27
|
+
https://github.com/vllm-project/vllm — Copyright the vLLM project contributors.
|
|
28
|
+
|
|
29
|
+
- docker/vllm-thor/patches/*.patch (except thor-gdn-prefill-fi-sm110.patch)
|
|
30
|
+
modify vLLM source files; the narandill/mjolnir-vllm image applies them to
|
|
31
|
+
the vLLM package of the official vllm/vllm-openai image, and marks every file
|
|
32
|
+
it changes (see docker/vllm-thor/apply_patches.py). Patches 49652, 50885,
|
|
33
|
+
54165 and 55519 are adapted from the corresponding (unmerged) vLLM pull
|
|
34
|
+
requests.
|
|
35
|
+
- docker/perses/dashboards/performance_statistics.yaml and
|
|
36
|
+
query_statistics.yaml are adapted from
|
|
37
|
+
examples/observability/dashboards/perses/ (changes listed in their headers).
|
|
38
|
+
|
|
39
|
+
-------------------------------------------------------------------------------
|
|
40
|
+
3. FlashAttention (FA4, CuTe DSL; vendored in vLLM as vllm_flash_attn) BSD-3-Clause
|
|
41
|
+
-------------------------------------------------------------------------------
|
|
42
|
+
https://github.com/Dao-AILab/flash-attention — Copyright (c) Tri Dao and
|
|
43
|
+
contributors. thor-fa4-fp8kv-sm110.patch, thor-fa4-hd256-fp8-sm110.patch and
|
|
44
|
+
thor-fa4-hd256-1cta-decode-sm110.patch modify files of vllm/vllm_flash_attn/
|
|
45
|
+
cute/ (the FlashAttention 4 kernels as vendored by vLLM). The Mjolnir kernel
|
|
46
|
+
itself contains no FlashAttention code; it follows the published
|
|
47
|
+
FlashAttention / FlashDecoding algorithms (online softmax, split-KV + LSE merge).
|
|
48
|
+
|
|
49
|
+
-------------------------------------------------------------------------------
|
|
50
|
+
4. FlashInfer Apache-2.0
|
|
51
|
+
-------------------------------------------------------------------------------
|
|
52
|
+
https://github.com/flashinfer-ai/flashinfer — Copyright the FlashInfer
|
|
53
|
+
contributors. thor-gdn-prefill-fi-sm110.patch modifies flashinfer/gdn_prefill.py
|
|
54
|
+
in the image's FlashInfer package.
|
|
55
|
+
|
|
56
|
+
-------------------------------------------------------------------------------
|
|
57
|
+
The narandill/mjolnir-vllm container image
|
|
58
|
+
-------------------------------------------------------------------------------
|
|
59
|
+
The image is built FROM the official vllm/vllm-openai image and redistributes
|
|
60
|
+
everything in it (vLLM, PyTorch, FlashInfer, NVIDIA CUDA libraries, the
|
|
61
|
+
NVIDIA CUTLASS DSL, Ubuntu packages, ...) under those components' own licenses
|
|
62
|
+
— see the license files inside the image and the upstream projects. It adds
|
|
63
|
+
the mjolnir-kernel package and the patches above; their LICENSE and this
|
|
64
|
+
NOTICE are installed at /usr/share/doc/mjolnir/.
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mjolnir-kernel
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Mjolnir: a paged decode-attention kernel for NVIDIA Jetson AGX Thor (sm_110) on tcgen05 / TMEM / TMA (CuTe DSL), with fp8 and 6-bit (e2m3) KV caches — packaged as the vLLM MJOLNIR attention backend.
|
|
5
|
+
Project-URL: Homepage, https://github.com/thor-arena/mjolnir
|
|
6
|
+
Project-URL: Documentation, https://github.com/thor-arena/mjolnir/tree/main/docs/kernel
|
|
7
|
+
Project-URL: Repository, https://github.com/thor-arena/mjolnir.git
|
|
8
|
+
Project-URL: Issues, https://github.com/thor-arena/mjolnir/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/thor-arena/mjolnir/releases
|
|
10
|
+
Author-email: Mieszko Syty <mieszko@ms1design.pl>
|
|
11
|
+
License-Expression: Apache-2.0 AND BSD-3-Clause
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
License-File: NOTICE
|
|
14
|
+
Keywords: attention,blackwell,cute-dsl,decode,fp8,jetson,sm110,tcgen05,thor,vllm
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Environment :: GPU :: NVIDIA CUDA
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: Intended Audience :: Science/Research
|
|
19
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Provides-Extra: dsl
|
|
28
|
+
Requires-Dist: nvidia-cutlass-dsl>=4.2; extra == 'dsl'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# mjolnir-kernel
|
|
32
|
+
|
|
33
|
+
**Mjolnir** — a paged decode-attention kernel for NVIDIA Jetson AGX Thor
|
|
34
|
+
(`sm_110`, 20 SMs), written in CuTe DSL on Blackwell `tcgen05` tensor cores, and
|
|
35
|
+
packaged as a vLLM attention backend.
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
vllm serve <model> --attention-backend MJOLNIR # the mjolnir-vllm image
|
|
39
|
+
vllm serve <model> --attention-backend CUSTOM # stock vLLM 0.31.0 + this package
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This package is the kernel only. Serving, calibration and benchmarking are the
|
|
43
|
+
[`mjolnir-cli`](https://pypi.org/project/mjolnir-cli/) package; benchmarks
|
|
44
|
+
(Mjolnir vs FlashInfer vs FlashAttention 2 across context lengths), the design,
|
|
45
|
+
and one chapter per kernel feature live in the project repository:
|
|
46
|
+
**[thor-arena/mjolnir](https://github.com/thor-arena/mjolnir)** — numbers there
|
|
47
|
+
are rendered from the raw results, so they are never stale.
|
|
48
|
+
|
|
49
|
+
## What it does
|
|
50
|
+
|
|
51
|
+
The backend subclasses a stock vLLM backend — the *fallback* — and inherits
|
|
52
|
+
its KV-cache allocation, cache write, prefill and validation:
|
|
53
|
+
|
|
54
|
+
- **on the image**, FlashAttention 4 (`FLASH_ATTN`, resolved to FA4 on sm_110
|
|
55
|
+
by the image's patch — its prefill is ~40% faster than FlashInfer's on
|
|
56
|
+
Thor). If FA4's one-time fp8-KV probe fails on the device, the backend logs
|
|
57
|
+
it and uses FlashInfer instead;
|
|
58
|
+
- **on a stock vLLM**, FlashInfer (stock FA on sm_110 is FA2, which cannot
|
|
59
|
+
read an fp8 KV cache);
|
|
60
|
+
- `MJOLNIR_ATTN_FALLBACK` picks another either way.
|
|
61
|
+
|
|
62
|
+
Steps that are **decode only** run on Mjolnir:
|
|
63
|
+
|
|
64
|
+
- every request has the same `q_len ≤ 1 + num_speculative_tokens` (so MTP /
|
|
65
|
+
n-gram speculative verification runs on Mjolnir too);
|
|
66
|
+
- CUDA-graph padding requests (zero tokens) may trail the batch;
|
|
67
|
+
- the step is causal — or the non-causal block of a parallel drafter (DSpark,
|
|
68
|
+
DFlash: every query token sees every key) — and has no cascade prefix.
|
|
69
|
+
|
|
70
|
+
Every other step (prefill, mixed, cascade) is built and run by the base backend,
|
|
71
|
+
unchanged.
|
|
72
|
+
|
|
73
|
+
A decode step:
|
|
74
|
+
|
|
75
|
+
1. **Plan** — an occupancy-pinned split-KV plan (`plan_split_kv`): exactly one
|
|
76
|
+
wave of 2 CTAs × 20 SMs. The plan lives in persistent device buffers padded to
|
|
77
|
+
a fixed grid, so full CUDA graphs replay new plans without re-capture.
|
|
78
|
+
2. **Quantize Q** — dynamic e4m3 per `(sequence, KV head)` by default: fp8 Q,
|
|
79
|
+
fp8 KV and fp8 P go straight into the tensor cores, no conversion warps.
|
|
80
|
+
3. **Stream KV** — TMA loads pages into a shared-memory ring
|
|
81
|
+
(L2 evict-first: KV is read once), `tcgen05` MMAs accumulate S and O in TMEM,
|
|
82
|
+
softmax warpgroups run the online softmax.
|
|
83
|
+
4. **Merge** — a small second kernel combines the split-KV partials by LSE.
|
|
84
|
+
|
|
85
|
+
The KV cache is read through runtime strides: vLLM's `(B,H,N,2D)`, FlashInfer
|
|
86
|
+
NHD/HND, or FlashAttention `(2,B,…)`, uint8 or fp8, with per-tensor or per-head
|
|
87
|
+
scales. Q and O are zero-copy for `q_len == 1`, even as strided views of the
|
|
88
|
+
fused QKV buffer.
|
|
89
|
+
|
|
90
|
+
## Install
|
|
91
|
+
|
|
92
|
+
**On the image** (`narandill/mjolnir-vllm:v0.31.0`) it is pre-installed and the
|
|
93
|
+
`MJOLNIR` backend name is patched into vLLM — nothing to do.
|
|
94
|
+
|
|
95
|
+
**On a stock vLLM 0.31.0** (inside a container that has CUDA 13 and `sm_110`):
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
pip install "mjolnir-kernel[dsl]" # [dsl] pulls nvidia-cutlass-dsl
|
|
99
|
+
VLLM_KV_CACHE_LAYOUT=HND vllm serve Qwen/Qwen3-8B \
|
|
100
|
+
--kv-cache-dtype fp8 --attention-backend CUSTOM
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The package registers a `vllm.general_plugins` entry point (`mjolnir:register`)
|
|
104
|
+
that maps `AttentionBackendEnum.CUSTOM` — and `MJOLNIR`, when the vLLM build has
|
|
105
|
+
that member — to `mjolnir.backend.MjolnirAttentionBackend` in every vLLM process.
|
|
106
|
+
The two-line enum patch for vLLM is
|
|
107
|
+
[`thor-mjolnir-attention-backend.patch`](https://github.com/thor-arena/mjolnir/blob/main/docker/vllm-thor/patches/thor-mjolnir-attention-backend.patch).
|
|
108
|
+
|
|
109
|
+
Look for this line in the server log:
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
Mjolnir decode enabled: h_q=… h_k=… d=… page=… q_len<=… Q=fp8 ctas/SM=2 …
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Requirements
|
|
116
|
+
|
|
117
|
+
- An fp8 (`fp8` / `fp8_e4m3`) KV cache — or, on the image, a 6-bit
|
|
118
|
+
`fp6_e2m3` one with calibrated scales (see below); head-major pages
|
|
119
|
+
(`VLLM_KV_CACHE_LAYOUT=HND`) are fastest.
|
|
120
|
+
- `head_size % 128 == 0`; block size 16, 32, 64 or 128.
|
|
121
|
+
- A bf16 or fp16 model.
|
|
122
|
+
- No sliding window, soft-cap, sinks or ALiBi; no DCP or PCP.
|
|
123
|
+
|
|
124
|
+
If a layer does not qualify, the builder logs the reason and that KV-cache group
|
|
125
|
+
runs on the fallback backend.
|
|
126
|
+
|
|
127
|
+
## Configuration
|
|
128
|
+
|
|
129
|
+
| variable | default | meaning |
|
|
130
|
+
|---|---|---|
|
|
131
|
+
| `MJOLNIR_ATTN_DISABLE` | – | `1`: the plugin does not register; everything runs on the fallback |
|
|
132
|
+
| `MJOLNIR_ATTN_FALLBACK` | `FLASH_ATTN` (FA4) on the image, `FLASHINFER` on stock vLLM | base backend (`FLASHINFER`, `TRITON_ATTN`, …) for prefill and mixed steps |
|
|
133
|
+
| `MJOLNIR_ATTN_Q_DTYPE` | `fp8` | `fp8` (dynamic per-(seq, KV head) quantization) or `bf16` |
|
|
134
|
+
| `MJOLNIR_ATTN_MAX_QLEN` | `1 + num_speculative_tokens` | the largest q_len Mjolnir takes |
|
|
135
|
+
| `MJOLNIR_ATTN_CTAS` | `2` | CTAs per SM (2 is fastest on Thor) |
|
|
136
|
+
| `MJOLNIR_ATTN_MAX_SPLITS` | `16` | max KV chunks per sequence (1 = never split, no merge kernel) |
|
|
137
|
+
| `MJOLNIR_ATTN_KV_STAGES` | `0` | KV ring depth override (0 = the tuned default) |
|
|
138
|
+
| `MJOLNIR_ATTN_PDL` | `0` | `1`: programmatic dependent launch |
|
|
139
|
+
| `MJOLNIR_ATTN_L2_PREFETCH` | `0` | TMA-prefetch K/V this many tiles ahead into L2 |
|
|
140
|
+
| `MJOLNIR_ATTN_KV_EVICT_FIRST` | `1` for fp8 Q, `0` for bf16 Q | L2 evict-first policy on K/V loads |
|
|
141
|
+
| `MJOLNIR_ATTN_PRECOMPILE` | `all` | compile every variant at start-up; `none` compiles on first use |
|
|
142
|
+
| `MJOLNIR_ATTN_KERNEL_CACHE` | on | compiled variants are exported to `$VLLM_CACHE_ROOT/mjolnir/kernels` (else `~/.cache/mjolnir/kernels`) and loaded on the next start instead of recompiling; `0` = off, a path = that directory. Keyed by variant, kernel source, CuTe DSL version and GPU |
|
|
143
|
+
| `MJOLNIR_ATTN_DRAFT_T5` | `1` | `0`: the drafter's layers (MTP / EAGLE) run on the fallback — isolates the draft-step cost (`mjolnir verify profile`). fp8 KV only: refused on fp6 KV, whose fallback cannot be CUDA-graphed |
|
|
144
|
+
| `MJOLNIR_ATTN_NONCAUSAL` | `1` | `0`: a parallel drafter's non-causal block steps (DSpark / DFlash) go to the fallback instead of the decode kernel — fp8 KV only for the same reason as above |
|
|
145
|
+
| `MJOLNIR_ATTN_FUSED_DRAFT` | `1` | `0`: tell vLLM the backend cannot advance draft metadata in place → one graph replay per draft step instead of the fused draft loop |
|
|
146
|
+
| `MJOLNIR_LM_HEAD` | – | `fp8`: quantize the lm_head to e4m3 per row at load, Triton fp8-weight GEMM for the verify and every draft (`mjolnir.lmhead`; config `NVFP4_MJOLNIR_E2M3_LMH8`); the bf16 copy is freed automatically (untied heads only, +2.5 GB KV) |
|
|
147
|
+
| `MJOLNIR_DRAFT_VOCAB` | – | path to a `draft_vocab.json` (`mjolnir calibrate --draft-vocab`): the drafter's logits only over those tokens (VocabTrim); `MJOLNIR_DRAFT_VOCAB_SIZE` keeps the first N (a shorter file is padded with the lowest unused ids, with a warning) |
|
|
148
|
+
| `MJOLNIR_ATTN_VERBOSE` | – | `1`: print the kernel's compile-time notes (ring stages, TMEM columns) — the standalone harness always does |
|
|
149
|
+
| `MJOLNIR_ATTN_BANNER` | `1` | `0`: skip the Mjolnir hammer banner in the vLLM boot log (`mjolnir.banner.emit`, once per start, coloured with the server's formatter) |
|
|
150
|
+
| `MJOLNIR_ATTN_KV_LAYOUT` | auto | force the KV view: `BHN2D BNH2D B2NHD B2HND 2BNHD 2BHND` |
|
|
151
|
+
| `MJOLNIR_ATTN_FUSED_QPACK` | `1` | `0`: quantize fp8 Q with PyTorch ops (~10 launches) instead of one Triton kernel |
|
|
152
|
+
| `MJOLNIR_ATTN_KV_SCALES` | – | `fp6_e2m3` KV: the per-(layer, KV head, channel) scales file from `python -m mjolnir.calibrate` |
|
|
153
|
+
| `MJOLNIR_ATTN_KV_SCALE_HEADROOM` | `1.0` | `fp6_e2m3` KV: multiply every calibrated scale |
|
|
154
|
+
| `MJOLNIR_ATTN_KV_CALIBRATE` | – | `1`: record the per-channel amax of every K/V written (what `mjolnir.calibrate` reads) |
|
|
155
|
+
|
|
156
|
+
The pre-rename `THOR_T5_*` spellings are still honored. Each default is backed
|
|
157
|
+
by a measurement — see the
|
|
158
|
+
[kernel chapters](https://github.com/thor-arena/mjolnir/tree/main/docs/kernel).
|
|
159
|
+
|
|
160
|
+
## fp6 (e2m3) KV in vLLM
|
|
161
|
+
|
|
162
|
+
On the image, `--kv-cache-dtype fp6_e2m3` stores K/V as packed 6-bit e2m3
|
|
163
|
+
codes (25% fewer bytes than fp8) with static per-(layer, KV head, channel)
|
|
164
|
+
scales — per channel because K has outlier channels a head-wide scale would
|
|
165
|
+
crush the rest under. Mjolnir writes that cache (`mjolnir/kvfp6.py`), decodes
|
|
166
|
+
from it directly (K's channel scales folded into Q, V's into the output), and
|
|
167
|
+
expands the pages a prefill / mixed step reads to e4m3 for the FA4 fallback
|
|
168
|
+
(channel scales applied, one descale per head). The scales come from a calibration run on fp8 KV:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
python -m mjolnir.calibrate --config <serve.yaml> --out kv_scales.json # in the image
|
|
172
|
+
MJOLNIR_ATTN_KV_SCALES=kv_scales.json vllm serve ... --kv-cache-dtype fp6_e2m3 --attention-backend MJOLNIR
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
(`mjolnir calibrate` / `mjolnir serve` do both for you —
|
|
176
|
+
[docs/faq/fp6-kv.md](https://github.com/thor-arena/mjolnir/blob/main/docs/faq/fp6-kv.md).)
|
|
177
|
+
|
|
178
|
+
## Beyond fp8: the harness
|
|
179
|
+
|
|
180
|
+
`mjolnir/t5_decode.py` is the kernel **and** its standalone harness
|
|
181
|
+
(`python -m mjolnir.t5_decode --help`) with a bit-faithful emulator as the
|
|
182
|
+
correctness reference. The harness can also read KV formats vLLM cannot write
|
|
183
|
+
yet — fp6 (`e2m3`/`e3m2`) and fp4 (`e2m1`) read directly by `tcgen05
|
|
184
|
+
kind::f8f6f4`, and `nvfp4` — and defaults to e2m3 on head-major pages for fp8 Q.
|
|
185
|
+
How they compare in speed and accuracy:
|
|
186
|
+
[`kvfmt`](https://github.com/thor-arena/mjolnir/blob/main/docs/kernel/kvfmt.md) and
|
|
187
|
+
[`quant`](https://github.com/thor-arena/mjolnir/blob/main/docs/kernel/quant.md).
|
|
188
|
+
Wiring a vLLM cache-write path for fp6 is an open contribution.
|
|
189
|
+
|
|
190
|
+
## Tests
|
|
191
|
+
|
|
192
|
+
From a checkout, on a Thor:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
mjolnir verify correctness # kernel vs the emulator, the full case matrix
|
|
196
|
+
mjolnir verify vllm # runner tests + greedy MJOLNIR-vs-FLASHINFER smoke runs
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
or directly in the container: `python tests/kernel/test_runner.py`,
|
|
200
|
+
`python tests/kernel/smoke_vllm.py [--eager] [--spec 2]` (they find the package
|
|
201
|
+
installed, via `$MJOLNIR_SRC`, or by walking up to `src/mjolnir`).
|
|
202
|
+
|
|
203
|
+
Mjolnir rounds P (and, by default, Q) to e4m3, so greedy outputs can flip on
|
|
204
|
+
near-tie tokens and then drift apart — FlashInfer's own greedy output differs
|
|
205
|
+
between CUDA-graph and eager mode. The smoke test therefore compares
|
|
206
|
+
per-step logprobs, not text: the chosen tokens must get the same logprob from
|
|
207
|
+
both backends on the shared prefix, and every divergence must be a near-tie
|
|
208
|
+
(each token in the other's top-5, at most 1 nat apart). The matching prefix
|
|
209
|
+
is printed as information.
|
|
210
|
+
|
|
211
|
+
## Files
|
|
212
|
+
|
|
213
|
+
| file | what |
|
|
214
|
+
|---|---|
|
|
215
|
+
| `mjolnir/t5_decode.py` | the CuTe-DSL kernel, the split-KV merge, the harness and the emulator |
|
|
216
|
+
| `mjolnir/runner.py` | plan buffers, compile cache, launch, KV views (no vLLM import) |
|
|
217
|
+
| `mjolnir/backend.py` | the vLLM backend, metadata builder, impl |
|
|
218
|
+
| `mjolnir/__init__.py` | `register()` — the vLLM plugin entry point |
|
|
219
|
+
|
|
220
|
+
Apache-2.0, except `mjolnir/t5_decode.py`, which is derived from an NVIDIA
|
|
221
|
+
CUTLASS CuTe DSL example and stays under BSD-3-Clause — see `LICENSE` and
|
|
222
|
+
`NOTICE` in this package.
|