Late Interaction Kernels

Fused Triton kernels for MaxSim scoring, packaged for Hugging Face Kernels and maintained under the Sentence Transformers organization. The kernels support inference and training with token embeddings from late interaction models such as ColBERT.

The kernel algorithms were developed by Aurélien Lac and Tony Wu at H Company in Late Interaction Kernels (LIK). This package adapts the CUDA MaxSim implementation from v0.4.5 to the Sentence Transformers scoring interface. It is distributed under the Apache 2.0 license.

What does it compute?

For each query token, MaxSim finds the document token with the highest dot product, then sums those maxima over the query:

MaxSim⁡(Q,D)=∑i∈valid query tokensmax⁡j∈valid document tokensQi⊤Dj \operatorname{MaxSim}(Q, D) = \sum_{i \in \text{valid query tokens}} \max_{j \in \text{valid document tokens}} Q_i^\top D_j

The fused implementation computes similarities and reductions without materializing the full [Nq, Nd, Lq, Ld] token similarity tensor in GPU memory. This reduces intermediate memory use and can accelerate scoring, especially for larger batches or longer documents. Both scoring layers support autograd, so gradients flow into query and document embeddings.

Quickstart

Use a Linux environment with CUDA-enabled PyTorch, Triton, and a supported NVIDIA GPU (compute capability 7.5 or newer). Install the following alongside your CUDA-enabled PyTorch installation:

pip install kernels triton

The following example scores two queries against four documents, then scores two matching pairs:

import torch
import torch.nn.functional as F
from kernels import get_kernel

kernel = get_kernel(
    "sentence-transformers/late-interaction-kernels",
    version=0,
    trust_remote_code=True,
)

queries = F.normalize(torch.randn(2, 32, 128, device="cuda"), dim=-1).half().requires_grad_()
documents = F.normalize(torch.randn(4, 180, 128, device="cuda"), dim=-1).half().requires_grad_()
query_mask = torch.ones(2, 32, dtype=torch.bool, device="cuda")
document_mask = torch.ones(4, 180, dtype=torch.bool, device="cuda")
document_mask[:, 150:] = False

scores = kernel.layers.MaxSim()(queries, documents, query_mask, document_mask)
paired_scores = kernel.layers.MaxSimPairwise()(
    queries, documents[:2], query_mask, document_mask[:2]
)

print(scores.shape)  # torch.Size([2, 4])
print(paired_scores.shape)  # torch.Size([2])
scores.sum().backward()

trust_remote_code=True allows the loader to execute the Python code in this kernel repository. The first call for a new input configuration may take longer while Triton compiles and autotunes the kernel.

Sentence Transformers

With Sentence Transformers 6.3.0 or newer, set use_kernels=True when loading a MultiVectorEncoder to enable these MaxSim kernels automatically on supported CUDA devices:

pip install "sentence-transformers[kernels]>=6.3.0" triton
from sentence_transformers import MultiVectorEncoder

model = MultiVectorEncoder("lightonai/LateOn", device="cuda", use_kernels=True)
queries = model.encode_query(["What is the capital of France?"])
documents = model.encode_document(["Paris is the capital of France.", "Berlin is the capital of Germany."])
scores = model.similarity(queries, documents)

Scoring interface

Layer Query shape Document shape Output shape
MaxSim [Nq, Lq, dim] [Nd, Ld, dim] [Nq, Nd]
MaxSimPairwise [B, Lq, dim] [B, Ld, dim] [B]

MaxSim scores every query against every document, for example for in-batch training. MaxSimPairwise scores corresponding pairs, for example for reranking, without computing the full cross product.

  • Inputs must share the embedding dimension, device, and dtype.
  • Masks have shape [batch_size, sequence_length]. Use boolean masks with True for valid tokens and False for padding, on the same device as the embeddings. Pass None for either mask to include all tokens.
  • Query masks exclude tokens from the sum. Document masks exclude tokens from the maximum. Documents with no valid tokens receive a score of -1e9.
  • The layers use dot products and do not normalize embeddings internally. Normalize each token embedding beforehand if your model uses cosine similarity.
  • Scores are returned in torch.float32.

Precision and compatibility

Supports float16, bfloat16, and float32 inputs. The accelerated path uses half precision with float32 accumulation, so scores and gradients may differ slightly from full precision PyTorch scoring.

The published kernel targets CUDA. Inputs that cannot use the fused kernel fall back to PyTorch scoring, as does execution inside torch.compile.

Performance and support

See the upstream algorithm walkthrough and benchmarks for implementation details and performance measurements.

Report issues with this package or its use in Sentence Transformers in the Hub discussions. Include your GPU, PyTorch and Triton versions, input shapes and dtypes, and a minimal reproducer.

Citation

Please credit the original kernel authors using the upstream citation:

@software{late_interaction_kernels_2026,
  author  = {Lac, Aurélien and Wu, Tony},
  title   = {{late-interaction-kernels}: Fused Triton kernels for late-interaction scoring},
  year    = {2026},
  url     = {https://github.com/hcompai/late-interaction-kernels},
}
Downloads last month
-
kernels
triton
maxsim
colbert
late-interaction
sentence-transformers
apache-2.0
arxiv: 2004.12832
Supported hardwares new
CUDA
7.58.09.010.012.0
GPU
B300
288GB
GPU
RTX Spark N1X Laptop
24GB
GPU
RTX Spark N1X Desktop
128GB
DGX Spark
GB10
64GB
GPU
RTX PRO 6000 WS
96GB
GPU
RTX PRO 6000 Max-Q
96GB
GPU
RTX PRO 5000
48GB
GPU
RTX PRO 4500 WS
32GB
RTX
RTX 5090
32GB
RTX
RTX 5090 D
32GB
GPU
RTX PRO 4000
24GB
GPU
RTX PRO 4000 SFF
24GB
RTX
RTX 5090 Mobile
24GB
GPU
RTX PRO 2000
16GB
RTX
RTX 5080
16GB
RTX
RTX 5080 Mobile
16GB
RTX
RTX 5070 Ti
16GB
RTX
RTX 5060 Ti
16GB
RTX
RTX 5070
12GB
RTX
RTX 5070 Mobile
8GB
RTX
RTX 5070 Ti Mobile
12GB
RTX
RTX 5060
8GB
RTX
RTX 5060 Mobile
8GB
RTX
RTX 5050
8GB
RTX
RTX 5050 Mobile
8GB
NVIDIA SXM
B200
192GB
NVIDIA SXM
H200
141GB
GPU
H20
96GB
GPU
RTX 5880 Ada
48GB
GPU
RTX 2000 Ada
16GB
RTX
RTX 4080 SUPER
16GB
RTX
RTX 4070 Ti Super
16GB
RTX
RTX 4070 Super
12GB
GPU
H800
80GB
GPU
L40s
48GB
GPU
L20
48GB
RTX
RTX 4090D
24GB
RTX
RTX 5000 Ada
32GB
GPU
L4
24GB
GPU
RTX 4500 Ada
24GB
RTX
RTX 4000 Ada
20GB
RTX
RTX 4000 SFF Ada
20GB
RTX
RTX 4090 Mobile
16GB
RTX
RTX 4060 Ti
8GB
RTX
RTX 4090 Laptop
16GB
Jetson
Jetson Orin NX 16GB
16GB
GPU
RTX 3500 Ada Mobile
12GB
RTX
RTX 4080 Mobile
12GB
RTX
RTX 4070
12GB
RTX
RTX 4070 Ti
12GB
RTX
RTX 4080 Laptop
12GB
RTX
RTX 4070 Mobile
8GB
RTX
RTX 4060
8GB
RTX
RTX 4070 Laptop
8GB
RTX
RTX 4060 Laptop
8GB
Jetson
Jetson Orin NX 8GB
8GB
Jetson
Jetson Orin Nano 8GB
8GB
RTX
RTX 4050 Laptop
6GB
Jetson
Jetson Orin Nano 4GB
4GB
NVIDIA SXM
H100
80GB
GPU
A800
40GB
Jetson
Jetson AGX Orin 64GB
64GB
GPU
L40
48GB
GPU
RTX 6000 Ada
48GB
Jetson
Jetson AGX Orin 32GB
32GB
RTX
RTX 4090
24GB
RTX
RTX 3090 Ti
24GB
RTX
RTX 4080
16GB
RTX
RTX 3070 Ti Mobile
8GB
RTX
RTX 3050
8GB
RTX
RTX 3050 Mobile
4GB
GPU
RTX A2000 Embedded
4GB
GPU
GTX 1630
4GB
GPU
RTX A5000
8GB
GPU
A30
24GB
GPU
A10
24GB
GPU
RTX A5000 Max-Q
16GB
GPU
RTX A5000 Mobile
16GB
GPU
RTX A4000
16GB
GPU
A2
16GB
RTX
RTX 3080 Mobile
16GB
GPU
RTX A3000 Mobile
6GB
GPU
RTX A2000
6GB
RTX
RTX 3080 Ti
12GB
RTX
RTX 3060
12GB
GPU
RTX 2060 12GB
12GB
GPU
RTX A4000 Max-Q
8GB
GPU
RTX A4000 Mobile
8GB
GPU
RTX A2000 Max-Q
4GB
GPU
RTX A2000 Mobile
4GB
RTX
RTX 3070 Ti
8GB
RTX
RTX 3060 Mobile
6GB
GPU
RTX 2050 Mobile
4GB
GPU
A100
80GB
GPU
RTX A6000
48GB
GPU
A40
48GB
RTX
RTX 3090
24GB
GPU
T10
16GB
RTX
RTX 3080
12GB
RTX
RTX 3070
8GB
RTX
RTX 3060 Ti
8GB
GPU
RTX 2070 SUPER Mobile
8GB
GPU
GTX 1650 Ti Mobile
4GB
GPU
T40
24GB
GPU
RTX 2080 SUPER
8GB
GPU
RTX 2070 SUPER
8GB
GPU
RTX 2060 SUPER
8GB
GPU
RTX 2060
6GB
GPU
RTX 2060 Mobile
6GB
GPU
GTX 1660 Ti
6GB
GPU
GTX 1660 Ti Mobile
6GB
GPU
GTX 1660 SUPER
6GB
GPU
GTX 1660
6GB
GPU
GTX 1650 SUPER
4GB
GPU
GTX 1650
4GB
GPU
GTX 1650 Mobile
4GB
GPU
Quadro RTX 8000
48GB
GPU
RTX Titan
24GB
GPU
Quadro RTX 6000
24GB
GPU
RTX 2080 Ti
11GB
NVIDIA T4
T4
16GB
GPU
Quadro RTX 5000
16GB
GPU
RTX 2080
8GB
GPU
RTX 2070
8GB
Kernel Builder
32b3dc8