vllm.v1.pool.flash_maxsim.flash_maxsim_rerank
¶
Flash-MaxSim rerank: one query vs variable-length docs in a packed tensor.
The kernel reads doc embeddings directly from a packed [total_tokens, d] tensor using per-doc (offset, length) pairs — no padding, no per-doc tensors, no materialised [B, Lq, Ld] similarity tensor.
Entry point
flash_maxsim_rerank_direct(Q, batch_tensor, doc_offsets, doc_lengths, max_ld) doc_offsets[i] = start token index of doc i in batch_tensor. doc_lengths[i] = number of tokens in doc i. Docs can be scattered (non-contiguous) in the batch tensor.
Functions:
-
flash_maxsim_rerank_direct–TRUE zero-copy: score query against docs scattered in a batch tensor.
_maxsim_rerank_kernel(Q_ptr, D_ptr, doc_offsets_ptr, doc_lengths_ptr, scores_ptr, B, Lq, Lq_bucket, max_Ld_bucket, d, d_pad, stride_q_t, stride_q_d, stride_d_t, stride_d_d, BLOCK_Q, BLOCK_D)
¶
One program per doc. Q shared (read from same location). D scattered.
Source code in vllm/v1/pool/flash_maxsim/flash_maxsim_rerank.py
_round_to_bucket(x)
¶
Round up to nearest bucket: 32, 64, 128, 256, 512, 1024, 2048, 4096.
_run_rerank_kernel(Q, D_tensor, doc_offsets, doc_lengths, max_seqlen_d)
¶
Common kernel launch for both rerank and rerank_direct.
Source code in vllm/v1/pool/flash_maxsim/flash_maxsim_rerank.py
flash_maxsim_rerank_direct(Q, batch_tensor, doc_offsets, doc_lengths, max_seqlen_d)
¶
TRUE zero-copy: score query against docs scattered in a batch tensor.
The kernel reads doc embeddings directly from batch_tensor at the positions specified by doc_offsets. No torch.stack, no torch.cat, no copy of any kind. The batch tensor is the model's output.
Memory for doc scoring: 0 bytes additional.
Parameters:
-
(Q¶Tensor) –[Lq, d] — single query embedding (from cache)
-
(batch_tensor¶Tensor) –[total_tokens, d] — the model's projected output tensor. Contains ALL requests' tokens (queries + docs + others).
-
(doc_offsets¶Tensor) –[B] int32 — start token index of each doc in batch_tensor
-
(doc_lengths¶Tensor) –[B] int32 — number of tokens per doc
-
(max_seqlen_d¶int) –int — max(doc_lengths)
Returns:
-
scores(Tensor) –[B] float32 — one MaxSim score per document