Skip to content

vllm.model_executor.layers.quantization.online.lm_head

Online lm_head quantization: weight-only methods for the model's own lm_head, selected by a quantization_config.targets pattern naming it, and private quantized copies of an already-loaded lm_head for speculative-decoding drafters (draft_lm_head_quantization).

Classes:

Functions:

OnlineLMHeadMethodBase

Bases: OnlineLinearBase

Weight-only lm_head quantized at load time and run on the platform's mixed-precision linear kernel (choose_mp_linear_kernel).

A subclass sets the weight format and implements quantize. An untied head loads its fp16/bf16 weight like any online linear layer and replaces it with the quantized copy. A tied head shares the input embeddings' weight, which stays unchanged: the quantized copy is added next to it.

Methods:

  • quantize –

    Quantize weight [N, K] into the MPLinearKernel layout.

Attributes:

  • group_size (int) –

    Input channels per scale; -1 for one scale per output channel.

  • k_align (int) –

    Required divisor of the hidden size (input columns).

  • n_align (int) –

    Required divisor of the vocab shard (output rows).

  • scheme (str) –

    The weight name in QUANT_KEY_NAMES, for logs and errors.

group_size class-attribute

Input channels per scale; -1 for one scale per output channel.

k_align = 1 class-attribute

Required divisor of the hidden size (input columns).

n_align = 1 class-attribute

Required divisor of the vocab shard (output rows).

scheme class-attribute

The weight name in QUANT_KEY_NAMES, for logs and errors.

quantize(weight) abstractmethod

Quantize weight [N, K] into the MPLinearKernel layout.

Returns the weight packed along K, the scales [N, K // group_size] ([N, 1] per channel) and the zero points packed along N, or None without zero points.

lm_head_padding_size(tp_size)

The vocabulary padding of a quantized lm_head sharded over tp_size ranks: its GEMM kernels need a multiple of 16 output columns per rank.

lm_head_quant_method(quantization)

The online method of a quantization lm_head, for a drafter that builds its own head quantized (ParallelLMHead(..., quant_method=...)) instead of sharing the target's.

quantized_lm_head_copy(lm_head, quantization)

A ParallelLMHead holding this rank's shard of lm_head, quantized.

"fp8" uses per-row weight and per-token activation scales on the platform's FP8 linear kernel; "nvfp4" is weight-only on the platform's W4A16 kernel. lm_head is left unchanged and no bf16 copy of its weight is made. The copy is derived state: refresh_quantized_lm_heads re-derives it after lm_head changes.

refresh_quantized_lm_heads(model)

Re-derive the quantized lm_head copies in model from their source heads.

Copies in place, so CUDA graphs keep pointing at valid tensors.

restore_quantized_lm_heads(model, refresh=True)

Undo share_source_lm_heads, then re-derive the copies in model.

Parameters:

  • model

    (Module) –

    The model passed to share_source_lm_heads, if any.

  • refresh

    (bool, default: True ) –

    Whether to re-derive the copies; False when the source heads may be mid-reload.

share_source_lm_heads(model)

Replace each quantized copy in model with its source head.

model then loads weights like a drafter sharing the unquantized head, until restore_quantized_lm_heads swaps the copies back in.