vllm.model_executor.layers.logits_processor
¶
A layer that compute logits from hidden_stats.
Classes:
-
LogitsProcessor–Process logits and apply logits processors from sampling metadata.
LogitsProcessor
¶
Bases: PluggableLayer
Process logits and apply logits processors from sampling metadata.
This layer does the following: 1. Gather logits from model hidden_states. 2. Scale logits if needed. 3. Apply logits processors (if any).
Methods:
-
__init__–Args:
-
get_top_k_tokens–Vocab-parallel top-k without all-gathering full logits.
-
get_top_tokens–Vocab-parallel argmax without all-gathering full logits.
__init__(vocab_size, org_vocab_size=None, scale=1.0, logits_as_input=False, soft_cap=None)
¶
Args: scale: A scaling factor to apply to the logits.
_apply_head(lm_head, hidden_states, embedding_bias)
¶
Project hidden states through the lm_head, honoring head_dtype.
_gather_logits(logits)
¶
gather/all-gather the logits tensor across model parallel group.
_mask_outside_vocab(logits, lm_head)
¶
Mask this shard's padding and any head rows past org_vocab_size.
A head shared with another model can have rows past this processor's
vocabulary, as _get_logits drops them.
get_top_k_tokens(lm_head, hidden_states, k, embedding_bias=None, *, return_log_probs=False)
¶
Vocab-parallel top-k without all-gathering full logits.
The get_top_tokens reduction widened from one token to k, returning
the values as well as the global ids. Communication is
O(batch * 2k * tp_size) rather than O(batch * vocab_size).
With return_log_probs, values use the full-vocabulary log-partition.
Otherwise scale and soft cap are applied to the k selected values rather than the whole vocabulary; both are monotonic, so the selection is the same and only k entries are touched.
get_top_tokens(lm_head, hidden_states, embedding_bias=None)
¶
Vocab-parallel argmax without all-gathering full logits.
Each TP rank computes local argmax, then only the (value, index) pairs are gathered and reduced. Communication: O(batch * 2 * tp_size) vs O(batch * vocab_size).
_flashinfer_topk()
cached
¶
FlashInfer's radix top-k, or None for torch.topk.
The top-k spans the vocabulary, where the radix kernel is about twice torch.topk.