vllm.model_executor.layers.quantization.online.lm_head
¶
Online-quantized copies of an already-loaded lm_head.
Functions:
-
quantized_lm_head_copy–A ParallelLMHead holding this rank's shard of
lm_head, quantized. -
refresh_quantized_lm_heads–Re-derive the quantized lm_head copies in
modelfrom their source heads. -
restore_quantized_lm_heads–Undo
share_source_lm_heads, then re-derive the copies inmodel. -
share_source_lm_heads–Replace each quantized copy in
modelwith its source head.
_LMHeadNvfp4Method
¶
Bases: OnlineLinearBase
Weight-only NVFP4 lm_head copy on the platform's W4A16 kernel; activations stay in the model dtype.
Source code in vllm/model_executor/layers/quantization/online/lm_head.py
_quantize_nvfp4(weight, chunk_rows=8192)
¶
NVFP4-quantize the rows of weight without the SM100+ quant kernel.
Returns packed E2M1 codes (low nibble first), E4M3 scales per 16 values and the fp32 dequantization global scale, in the checkpoint layout.
Source code in vllm/model_executor/layers/quantization/online/lm_head.py
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.
Source code in vllm/model_executor/layers/quantization/online/lm_head.py
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.
Source code in vllm/model_executor/layers/quantization/online/lm_head.py
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.
Source code in vllm/model_executor/layers/quantization/online/lm_head.py
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.