vllm.model_executor.utils ¶
Utils for model executor.
Functions:
-
replace_parameter–Replace a parameter of a layer while maintaining the ability to reload the weight.
-
set_weight_attrs–Set attributes on a weight tensor.
replace_parameter(layer, param_name, new_data, prefer_copy=False) ¶
Replace a parameter of a layer while maintaining the ability to reload the weight. Called within implementations of the process_weights_after_loading method.
This function should not be called on weights which are tied/shared
Parameters:
-
(layer¶Module) –Layer containing parameter to replace
-
(param_name¶str) –Name of parameter to replace
-
(new_data¶Tensor | None) –New data of the new parameter, or None to set the parameter to None
-
(prefer_copy¶bool, default:False) –If True and the existing parameter is compatible with
new_data(same shape, dtype, and device), copynew_datainto the existing parameter in place rather than re-registering a new parameter. This preserves the parameter's storage address (data_ptr), which is required for captured CUDA graphs to remain valid across weight updates (e.g. in RL training loops).
Source code in vllm/model_executor/utils.py
set_weight_attrs(weight, weight_attrs) ¶
Set attributes on a weight tensor.
This method is used to set attributes on a weight tensor. This method will not overwrite existing attributes.
Parameters:
-
(weight¶Tensor) –The weight tensor.
-
(weight_attrs¶dict[str, Any] | None) –A dictionary of attributes to set on the weight tensor.