mjolnir-kernel
Mjolnir — a paged decode-attention kernel for NVIDIA Jetson AGX Thor
(sm_110, 20 SMs), written in CuTe DSL on Blackwell tcgen05 tensor cores, and
packaged as a vLLM attention backend.
vllm serve <model> --attention-backend MJOLNIR # the mjolnir-vllm image
vllm serve <model> --attention-backend CUSTOM # stock vLLM 0.32.0 + this package
This package is the kernel only. Serving, calibration and benchmarking are the
mjolnir-cli package; benchmarks
(Mjolnir vs FlashInfer vs FlashAttention 2 across context lengths), the design,
and one chapter per kernel feature live in the project repository:
GoBrrr-ai/mjolnir — numbers there
are rendered from the raw results, so they are never stale.
What it does
The backend subclasses a stock vLLM backend — the fallback — and inherits its KV-cache allocation, cache write, prefill and validation:
- on the image, FlashAttention 4 (
FLASH_ATTN, resolved to FA4 on sm_110 by the image's patch — its prefill is ~40% faster than FlashInfer's on Thor). If FA4's one-time fp8-KV probe fails on the device, the backend logs it and uses FlashInfer instead; - on a stock vLLM, FlashInfer (stock FA on sm_110 is FA2, which cannot read an fp8 KV cache);
MJOLNIR_ATTN_FALLBACKpicks another either way.
Steps that are decode only run on Mjolnir:
- every request has the same
q_len ≤ 1 + num_speculative_tokens(so MTP / n-gram speculative verification runs on Mjolnir too); - CUDA-graph padding requests (zero tokens) may trail the batch;
- the step is causal — or the non-causal block of a parallel drafter (DSpark, DFlash: every query token sees every key) — and has no cascade prefix.
Every other step (prefill, mixed, cascade) is built and run by the base backend, unchanged.
A decode step:
- Plan — an occupancy-pinned split-KV plan (
plan_split_kv): exactly one wave of 2 CTAs × 20 SMs. The plan lives in persistent device buffers padded to a fixed grid, so full CUDA graphs replay new plans without re-capture. - Quantize Q — dynamic e4m3 per
(sequence, KV head)by default: fp8 Q, fp8 KV and fp8 P go straight into the tensor cores, no conversion warps. - Stream KV — TMA loads pages into a shared-memory ring
(L2 evict-first: KV is read once),
tcgen05MMAs accumulate S and O in TMEM, softmax warpgroups run the online softmax. - Merge — a small second kernel combines the split-KV partials by LSE.
The KV cache is read through runtime strides: vLLM's (B,H,N,2D), FlashInfer
NHD/HND, or FlashAttention (2,B,…), uint8 or fp8, with per-tensor or per-head
scales. Q and O are zero-copy for q_len == 1, even as strided views of the
fused QKV buffer.
Install
On the image (narandill/mjolnir-vllm:v0.32.0) it is pre-installed and the
MJOLNIR backend name is patched into vLLM — nothing to do.
On a stock vLLM 0.32.0 (inside a container that has CUDA 13 and sm_110):
pip install "mjolnir-kernel[dsl]" # [dsl] pulls nvidia-cutlass-dsl
VLLM_KV_CACHE_LAYOUT=HND vllm serve Qwen/Qwen3-8B \
--kv-cache-dtype fp8 --attention-backend CUSTOM
The package registers a vllm.general_plugins entry point (mjolnir:register)
that maps AttentionBackendEnum.CUSTOM — and MJOLNIR, when the vLLM build has
that member — to mjolnir.backend.MjolnirAttentionBackend in every vLLM process.
The two-line enum patch for vLLM is
thor-mjolnir-attention-backend.patch.
Look for this line in the server log:
Mjolnir decode enabled: h_q=… h_k=… d=… page=… q_len<=… Q=fp8 ctas/SM=2 …
Requirements
- An fp8 (
fp8/fp8_e4m3) KV cache — or, on the image, a 6-bitfp6_e2m3one with calibrated scales (see below); head-major pages (VLLM_KV_CACHE_LAYOUT=HND) are fastest. head_size % 128 == 0; block size 16, 32, 64 or 128.- A bf16 or fp16 model.
- No sliding window, soft-cap, sinks or ALiBi; no DCP or PCP.
If a layer does not qualify, the builder logs the reason and that KV-cache group runs on the fallback backend.
Configuration
| variable | default | meaning |
|---|---|---|
MJOLNIR_ATTN_DISABLE |
– | 1: the plugin does not register; everything runs on the fallback |
MJOLNIR_ATTN_FALLBACK |
FLASH_ATTN (FA4) on the image, FLASHINFER on stock vLLM |
base backend (FLASHINFER, TRITON_ATTN, …) for prefill and mixed steps |
MJOLNIR_ATTN_Q_DTYPE |
fp8 |
fp8 (dynamic per-(seq, KV head) quantization) or bf16 |
MJOLNIR_ATTN_MAX_QLEN |
1 + num_speculative_tokens |
the largest q_len Mjolnir takes |
MJOLNIR_ATTN_CTAS |
2 |
CTAs per SM (2 is fastest on Thor) |
MJOLNIR_ATTN_MAX_SPLITS |
16 |
max KV chunks per sequence (1 = never split, no merge kernel). On Orin it caps the split capacity the kernel's occupancy picks (8 for the mma kernel on AGX Orin) |
| MJOLNIR_ATTN_KV_STAGES | 0 | KV ring depth override (0 = the tuned default) |
| MJOLNIR_ATTN_PDL | 0 | 1: programmatic dependent launch |
| MJOLNIR_ATTN_L2_PREFETCH | 0 | TMA-prefetch K/V this many tiles ahead into L2 |
| MJOLNIR_ATTN_KV_EVICT_FIRST | 1 for fp8 Q, 0 for bf16 Q | L2 evict-first policy on K/V loads |
| MJOLNIR_ATTN_PRECOMPILE | all | compile every variant at start-up; none compiles on first use |
| 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 |
| 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 |
| 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 |
| 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 |
| 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_VT64K); the bf16 copy is freed automatically (untied heads only, +2.5 GB KV). MJOLNIR_LM_HEAD_TILES overrides the GEMV launch config (BN,BK,warps,stages; default 64,256,8,5 — the 2026-11-04 serving A/B winner) |
| MJOLNIR_MTP_FP8 | – | 1: fp8-row-quantize the drafter's big unquantized linears (≥16M params) at load, same e4m3-per-row scheme + self-test (≤0.02 rel err) as the head; the bf16 originals are freed. Halves the MTP draft loop's streamed weight bytes |
| MJOLNIR_MTP_LAYER | – | fp8: the older, narrower variant — W8A8 via cuBLASLt rowwise scaled_mm on the MTP layer + eh_proj fc only. Measured negative on sm_110 (cuBLASLt fp8 ≈60% of peak on layer shapes; 16–22% slower decode, acceptance safe) — see config NVFP4_MJOLNIR_E2M3_LMH8_VT64K_M8; revisit only with a faster skinny-shape fp8 GEMM |
| 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). The kept head stays in the drafter's native quant (NVFP4 4-bit in-kernel, FP8 row-slice) — never up-scaled to bf16; a bf16 head is the one exception (fp8 only when MJOLNIR_LM_HEAD=fp8 is set). MJOLNIR_DRAFT_VOCAB_NATIVE=0 forces the dequant→fp8 path. qwen4_exp (image patch thor-qwen4-draft-head): the MTP drafter builds its own reduced BF16 head from the same file and this VocabTrim skips it; MJOLNIR_LM_HEAD does not cover that head (QWEN4EXP_DRAFT_HEAD_FP8 does), and a quantized lm_head is not supported there |
| MJOLNIR_NVFP4_MOE_W4A4 | – | 1: serve routed experts declared W4A16_NVFP4 (ModelOpt MIXED_PRECISION) as NVFP4 W4A4 with the checkpoint's calibrated per-expert input_scale tensors (mjolnir.moew4a4; config NVFP4_MJOLNIR_W4A4), so the NVFP4 MoE oracle can pick FLASHINFER_CUTEDSL (patches thor-sm110-cutedsl-moe-gate + fi-cutedsl-moe-sm110) instead of MARLIN. Linear layers, shared experts and the lm_head keep their algorithm; the load refuses if a checkpoint ships no expert input scales |
| MJOLNIR_PLE_DISK_CACHE_GB | 0 | GiB (Qwen3.8-Flash-Next, image patch thor-qwen4-ple-disk): with vLLM's --engram-config '{"disk_offload": true}' (the on/off switch of the disk table), > 0 puts a GPU CLOCK slot pool of that size and a prefetch thread in front of it (mjolnir.qwen4exp.ple_disk); 0 = vLLM's stock reader. MJOLNIR_PLE_DISK_PREFETCH=0 = synchronous lookup; MJOLNIR_PLE_DISK_STATS_SEC = stats line period |
| QWEN4EXP_DRAFT_HEAD_FP8 / QWEN4EXP_MTP_DENSE_FP8 | – | 1 (Qwen3.8-Flash-Next, patch thor-qwen4-draft-head): online 8-bit for the MTP drafter's reduced head (built from MJOLNIR_DRAFT_VOCAB; for qwen4_exp the drafter carries that head itself and mjolnir.lmhead skips it) / its BF16 dense projections (mjolnir.qwen4exp.draft_head). QWEN4EXP_FP8_FORMAT = fp8_per_block (default) or mxfp8 |
| QWEN4EXP_LM_HEAD_SCREENED | – | 1 (Qwen3.8-Flash-Next, patch thor-qwen4-screened-head): exact top-k target logits from an FP8 screen of the BF16 lm_head (backport of vLLM #60566, mjolnir.qwen4exp.screened_head) for greedy / top_k <= QWEN4EXP_LM_HEAD_SCREEN_K (32) batches; refuses next to MJOLNIR_LM_HEAD=fp8. QWEN4EXP_LM_HEAD_SCREEN_CHECK=N / QWEN4EXP_LM_HEAD_SCREEN_STATS=<s>: in-server check / call counts |
| QWEN4EXP_SIDE_FP8 | – | 1 (Qwen3.8-Flash-Next NVFP4, patch thor-qwen4-side-fp8): online FP8 (QWEN4EXP_FP8_FORMAT) for the target's BF16 dense side layers, a no-op when the checkpoint already quantizes them (QWEN4EXP_SIDE_FP8_SKIP = comma-separated kinds left BF16, unknown kinds refuse; self_attn.indexer.index_qk_proj keeps only the QSA indexer BF16 and unfused) |
| QWEN4EXP_HC_FP8 | – | 1 (Qwen3.8-Flash-Next, patch thor-qwen4-hc-fp8): online 8-bit for the target's hyperconnection GEMMs (mjolnir.qwen4exp.hc_fp8); QWEN4EXP_HC_FP8_FORMAT="<down>[,<up>]" (default fp8_per_block,mxfp8, the only pair the sm_110 kernels accept) |
| MJOLNIR_SPEC_STEP_DRAFT_FULL_CG | – | 1 (image patch thor-draft-full-cg-piecewise, any autoregressive drafter, MTP included): FULL CUDA graphs for the draft decode passes while the target stays PIECEWISE |
| MJOLNIR_MXFP8_TACTIC | – | <max_m>:<tactic>[,…] (image patch thor-mxfp8-tactic-sm110): FlashInfer CUTLASS MXFP8 linears run the pinned tactic for M up to the bucket, the stock call above; bit-identical. 256:8 on Thor (FP4-Local side layers) |
| MJOLNIR_ATTN_VERBOSE | – | 1: print the kernel's compile-time notes (ring stages, TMEM columns) — the standalone harness always does |
| 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) |
| MJOLNIR_ATTN_KV_LAYOUT | auto | force the KV view: BHN2D BNH2D B2NHD B2HND 2BNHD 2BHND |
| MJOLNIR_ATTN_FUSED_QPACK | 1 | 0: quantize fp8 Q with PyTorch ops (~10 launches) instead of one Triton kernel |
| MJOLNIR_ATTN_KV_SCALES | – | fp6_e2m3 KV: the per-(layer, KV head, channel) scales file from python -m mjolnir.calibrate |
| MJOLNIR_ATTN_KV_SCALE_HEADROOM | 1.0 | fp6_e2m3 KV: multiply every calibrated scale |
| MJOLNIR_ATTN_KV_CALIBRATE | – | 1: record the per-channel amax of every K/V written (what mjolnir.calibrate reads) |
The pre-rename THOR_T5_* spellings are still honored. Each default is backed
by a measurement — see the
kernel chapters.
fp6 (e2m3) KV in vLLM
On the image, --kv-cache-dtype fp6_e2m3 stores K/V as packed 6-bit e2m3
codes (25% fewer bytes than fp8) with static per-(layer, KV head, channel)
scales — per channel because K has outlier channels a head-wide scale would
crush the rest under. Mjolnir writes that cache (mjolnir/kvfp6.py), decodes
from it directly (K's channel scales folded into Q, V's into the output), and
expands the pages a prefill / mixed step reads to e4m3 for the FA4 fallback
(channel scales applied, one descale per head). The scales come from a calibration run on fp8 KV:
python -m mjolnir.calibrate --config <serve.yaml> --out kv_scales/e2m3.json # in the image
MJOLNIR_ATTN_KV_SCALES=kv_scales/e2m3.json vllm serve ... --kv-cache-dtype fp6_e2m3 --attention-backend MJOLNIR
(mjolnir calibrate / mjolnir serve do both for you —
docs/faq/fp6-kv.md.)
Beyond fp8: the harness
mjolnir/arch/thor/decode.py is the kernel; mjolnir/arch/thor/harness.py
(python -m mjolnir.arch.thor.harness --help) is its standalone harness, with a bit-faithful emulator as the
correctness reference. The harness can also read KV formats vLLM cannot write
yet — fp6 (e2m3/e3m2) and fp4 (e2m1) read directly by tcgen05 kind::f8f6f4, and nvfp4 — and defaults to e2m3 on head-major pages for fp8 Q.
How they compare in speed and accuracy:
kvfmt and
quant.
Wiring a vLLM cache-write path for fp6 is an open contribution.
Platforms and architectures
The kernel is written for one architecture today — Thor (sm_110) — but the
package is organized by platform: mjolnir/arch/ is the implemented-kernel
registry (mjolnir.arch.thor re-exports the exact runner surface the backend
consumes), and mjolnir/platforms.py is the torch-free leaf that maps a
compute capability to it. Thor and Jetson Orin (sm_87) are implemented;
DGX Spark (sm_121) is declared research — named in the matrix, no kernel
yet. Orin ships one kernel: the mma.m16n8k16 decode kernel (fp8 KV at
hd 128/256, fp6-e2m3 KV hd 256, M ≤ 8, bf16 Q) — see mjolnir/arch/orin/README.md.
kernel_for((11, 0)) returns mjolnir.arch.thor; any other compute
capability raises PlatformNotSupported naming the requested sm_XX and the
shipped platforms. The vLLM backend never sees that exception: its metadata
builder consults the pure unsupported_reason() and takes the normal
ineligible-config path — that layer's decode steps run on the fallback
backend, the serve continues. On a host without a usable CUDA device,
MJOLNIR_ARCH (sm_110 or 11.0) pins the architecture instead of the
torch read (the standalone harness).
There is no remembered platform state anywhere in the stack: the CLI side
resolves its platform per invocation (flag > $MJOLNIR_PLATFORM > host
detection — four source classes with provenance, the /tmp/nv_jetson_model
model copy corroboration-only), so the kernel is always resolved from the
device the run actually happens on. See
docs/faq/platforms.md.
Tests
From a checkout, on a Thor:
mjolnir verify correctness # kernel vs the emulator, the full case matrix
mjolnir verify vllm # runner tests + greedy MJOLNIR-vs-FLASHINFER smoke runs
or directly in the container: python tests/kernel/test_runner.py,
python tests/kernel/smoke_vllm.py [--eager] [--spec 2] (they find the package
installed, via $MJOLNIR_SRC, or by walking up to src/mjolnir).
Mjolnir rounds P (and, by default, Q) to e4m3, so greedy outputs can flip on near-tie tokens and then drift apart — FlashInfer's own greedy output differs between CUDA-graph and eager mode. The smoke test therefore compares per-step logprobs, not text: the chosen tokens must get the same logprob from both backends on the shared prefix, and every divergence must be a near-tie (each token in the other's top-5, at most 1 nat apart). The matching prefix is printed as information.
Files
| file | what |
|---|---|
mjolnir/arch/thor/ |
the Thor kernel family: decode.py (the CuTe-DSL kernel + merge), call.py, const.py, plan.py, runner.py, harness.py (driver + emulator) |
mjolnir/runner.py |
plan buffers, compile cache, launch, KV views (no vLLM import) |
mjolnir/backend.py |
the vLLM backend, metadata builder, impl |
mjolnir/platforms.py |
arch → kernel resolution (kernel_for, PlatformNotSupported), MJOLNIR_ARCH detection — torch-free |
mjolnir/arch/thor.py |
the Thor (sm_110) kernel surface: re-exports of the runner |
mjolnir/__init__.py |
register() — the vLLM plugin entry point |
Apache-2.0, except mjolnir/arch/thor/decode.py, which is derived from an NVIDIA
CUTLASS CuTe DSL example and stays under BSD-3-Clause — see LICENSE and
NOTICE in this package.
Metadata
Release files for mjolnir-kernel 0.3.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mjolnir_kernel-0.3.6.tar.gz | 217.6 kB | With provenance | Details for mjolnir_kernel-0.3.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mjolnir_kernel-0.3.6-py3-none-any.whl | Python 3 | none | any | Details for mjolnir_kernel-0.3.6-py3-none-any.whl |
Total release size: 462.1 kB
Release files / mjolnir_kernel-0.3.6.tar.gz
| Download URL | mjolnir_kernel-0.3.6.tar.gz |
|---|---|
| Size | 217.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a7202aa1ba13ed461a6b466b5c03c5a7c6a9c59a4defd50434c0a86e6578efeb
|
|
BLAKE2b-256 checksum How to use checksums |
0367ee160ec002241b812a4610de2c01bca38410bc73125b927e019e7a048345
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logRelease files / mjolnir_kernel-0.3.6-py3-none-any.whl
| Download URL | mjolnir_kernel-0.3.6-py3-none-any.whl |
|---|---|
| Size | 244.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
33f253a6ce3daf7c7dfa4ee0710c7a5541a4ca0d09142ed5d6144913606ddd26
|
|
BLAKE2b-256 checksum How to use checksums |
1962b08cc9725e552626ea963d9bf3b0a50c4e1dc78edf3f6af2c304e4292ac4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logSecurity for mjolnir-kernel 0.3.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mjolnir_kernel-0.3.6.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.