vllm.lora.layers.base ¶
BaseLayerWithLoRA ¶
Bases: Module
Source code in vllm/lora/layers/base.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
can_replace_layer classmethod ¶
can_replace_layer(
source_layer: Module,
lora_config: LoRAConfig,
packed_modules_list: list,
model_config: PretrainedConfig | None = None,
) -> bool
Returns True if the layer can be replaced by this LoRA layer.
Source code in vllm/lora/layers/base.py
create_lora_weights ¶
create_lora_weights(
max_loras: int,
lora_config: LoRAConfig,
model_config: PretrainedConfig | None = None,
) -> None
load_weights ¶
Forward checkpoint weights to the unwrapped base layer.
Source code in vllm/lora/layers/base.py
named_modules ¶
named_modules(
memo: set[Module] | None = None,
prefix: str = "",
remove_duplicate: bool = True,
) -> Iterable[tuple[str, Module]]
Make the LoRA wrapper transparent in the module tree.
LoRA wrapping moves a layer's parameters under base_layer (e.g. qkv_proj.weight -> qkv_proj.base_layer.weight). Checkpoint files and model-specific load_weights() methods use the original (un-prefixed) names.
This override flattens base_layer out of the hierarchy so that :meth:named_parameters and :meth:named_buffers return the original names, making weight loading work transparently.
Source code in vllm/lora/layers/base.py
set_lora ¶
slice_lora_a ¶
slice_lora_b ¶
zero_lora_state ¶
Re-zero all unregistered GPU tensor attributes.
LoRA stacked tensors (lora_a_stacked, lora_b_stacked, etc.) are plain attributes, not nn.Parameter or registered buffers. After level-2 sleep the GPU memory backing them is discarded and remapped with undefined contents. reload_weights() restores only parameters and buffers, so these tensors must be explicitly re-zeroed to avoid adding garbage to the base-model output.