Skip to content

vllm.model_executor.model_loader.reload.sanitize

Functions:

  • restore_layer_refs –

    Restores references to layer held by tensor attributes.

  • sanitize_layer_refs –

    Removes references to layer held by tensor attributes. Specifically, removes the

restore_layer_refs(tensor, layer)

Restores references to layer held by tensor attributes.

Used by restore_layer_on_meta to add back layer references, allowing for proper weight loading.

Parameters:

  • tensor

    (Tensor) –

    tensor to be sanitized

  • layer

    (Module) –

    layer whose references should be removed

Returns:

sanitize_layer_refs(tensor, layer)

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.

Parameters:

  • tensor

    (Tensor) –

    tensor to be sanitized

  • layer

    (Module) –

    layer whose references should be removed

Returns: