vllm.model_executor.model_loader.reload.sanitize ¶
restore_layer_refs ¶
Restores references to layer held by tensor attributes.
Used by restore_layer_on_meta to add back layer references, allowing for proper weight loading.
:param tensor: tensor to be sanitized :param layer: layer whose references should be removed :return: sanitized tensor
Source code in vllm/model_executor/model_loader/reload/sanitize.py
sanitize_layer_refs ¶
Removes references to layer held by tensor attributes. Specifically, removes the __self__ attribute of weight loader methods attached to the tensor.
Used by capture_layer_to_meta to avoid circular references to layers in LAYERWISE_INFO, leading to modules never being cleaned up. Without sanitation, tensors will reference layers, and the WeakKeyDictionary will never evict entries, even when the model is deleted.
:param tensor: tensor to be sanitized :param layer: layer whose references should be removed :return: sanitized tensor