vllm.model_executor.model_loader.reload.layerwise
¶
Functions:
-
finalize_layerwise_processing–Apply processing to any layers which were not layerwise processed during loading.
-
get_layerwise_info–Get information related to restoring and layerwise processing. If no previous
-
initialize_layerwise_reload–Set up layerwise weight loading with deferred processing.
-
max_layer_reload_bytes–Bytes of the largest layer in checkpoint format, which a layerwise reload
-
record_metadata_for_reloading–Record layer metadata needed for later reloading.
_check_requantization_source_fully_loaded(layer, info)
¶
Raise if a requantization source layer was only partially loaded.
Serialized weights are created at their exact size, so unlike padded full-precision weights every element must be loaded. A missing checkpoint tensor would otherwise be materialized as zeros and silently requantized.
_copy_and_restore_kernel_tensors(layer, info)
¶
Copy processed values into original kernel tensor storage and restore kernel tensor references on the layer. Preserves cudagraph references.
_get_original_loader(tensor)
¶
Return the weight loader with any layerwise wrappers removed.
_layerwise_process(layer, info)
¶
Finalize layer loading after all weights have been buffered.
This function: 1. Materializes the layer onto the target device 2. Loads all buffered weights 3. Runs quantization processing if applicable 4. Copies processed values back to original tensor storage
_process_loaded_layer(layer, info)
¶
Finish a layer whose weights are all loaded: run its quant method's processing, copy the result into the persistent kernel storage and reset its reload info.
Shared by _layerwise_process and the sharded-RDT engine's quant stream,
which loads a layer's weights by scattering into it instead of through the
buffered loaders but finishes it exactly the same way.
_reload_attention_scales(layer, info)
¶
Load and process attention scale weights (k_scale, v_scale, etc.) during reload.
Assumes dtype/shapes of attention tensors do not change during processing, since we use .data.copy_() to preserve kernel tensor references.
_wrap_parameters_weight_loader(layer)
¶
Wrap each parameter's weight loader.
finalize_layerwise_processing(model, model_config)
¶
Apply processing to any layers which were not layerwise processed during loading. This includes attention layers and layers which have weight elements which are not loaded (due to padding).
This function should be applied after initialize_layerwise_reload is applied
unwrap the layerwise weight loaders.
Parameters:
-
(model¶Module) –model to finalize processing for
-
(model_config¶ModelConfig) –config needed for applying processing to attention layers
get_layerwise_info(layer)
¶
Get information related to restoring and layerwise processing. If no previous information existed, a new entry is constructed
initialize_layerwise_reload(model, *, defer_processing=False)
¶
Set up layerwise weight loading with deferred processing.
Must be called after record_metadata_for_reloading. This function:
1. Saves current kernel tensors for later copying
2. Restores layer parameters/buffers from metadata (on meta device)
3. Wraps weight loaders to defer processing until all weights are loaded
When all weights for a layer are loaded, the wrapped loaders will: 1. Materialize the layer onto the target device 2. Load all cached weights 3. Run quantization processing if applicable 4. Copy processed values back to original tensor storage
With defer_processing=True, only finalize_layerwise_reload triggers processing.
initialize_online_processing(layer)
¶
make_online_process_loader(layer, param_name)
¶
Create a wrapped weight loader that defers processing.
max_layer_reload_bytes(model)
¶
Bytes of the largest layer in checkpoint format, which a layerwise reload materializes on the device, one layer at a time, before processing it.
record_metadata_for_reloading(model)
¶
Record layer metadata needed for later reloading.
Stores parameter and buffer metadata as meta tensors for restoration.
Must be called before initialize_layerwise_reload.