[Misc] Reduce LoRA-related static variable (#13166)
This commit is contained in:
@@ -29,6 +29,7 @@ from vllm.lora.layers import (BaseLayerWithLoRA, ColumnParallelLinearWithLoRA,
|
||||
ReplicatedLinearWithLoRA,
|
||||
RowParallelLinearWithLoRA,
|
||||
VocabParallelEmbeddingWithLoRA)
|
||||
from vllm.model_executor.layers.linear import LinearBase
|
||||
# yapf: enable
|
||||
from vllm.model_executor.layers.logits_processor import LogitsProcessor
|
||||
from vllm.model_executor.layers.vocab_parallel_embedding import ParallelLMHead
|
||||
@@ -68,6 +69,14 @@ def from_layer(layer: nn.Module,
|
||||
ret = lora_cls(layer)
|
||||
ret.create_lora_weights(max_loras, lora_config, model_config)
|
||||
return ret
|
||||
|
||||
# The Case for HFCompatibleLinear
|
||||
if (hasattr(layer, "get_lora_class")
|
||||
and layer.__class__.__name__ == "HFCompatibleLinear"):
|
||||
lora_cls = layer.get_lora_class(lora_config.fully_sharded_loras)
|
||||
ret = lora_cls(layer)
|
||||
ret.create_lora_weights(max_loras, lora_config, model_config)
|
||||
return ret
|
||||
return layer
|
||||
|
||||
|
||||
@@ -170,6 +179,23 @@ def is_regex_target_modules(load_modules: Union[str, List[str]],
|
||||
return False
|
||||
|
||||
|
||||
def get_supported_lora_modules(model: nn.Module) -> List[str]:
|
||||
"""
|
||||
In vLLM, all linear layers support LoRA.
|
||||
"""
|
||||
supported_lora_modules: Set[str] = set()
|
||||
# step1: traverse the model to get all the linear subfixes.
|
||||
for name, module in model.named_modules():
|
||||
if isinstance(module, (LinearBase, )):
|
||||
supported_lora_modules.add(name.split(".")[-1])
|
||||
# step 2: get the embedding modules if the model's mbedding_modules
|
||||
# is not empty.
|
||||
if model.embedding_modules:
|
||||
for name in model.embedding_modules:
|
||||
supported_lora_modules.add(name)
|
||||
return list(supported_lora_modules)
|
||||
|
||||
|
||||
def get_adapter_absolute_path(lora_path: str) -> str:
|
||||
"""
|
||||
Resolves the given lora_path to an absolute local path.
|
||||
|
||||
Reference in New Issue
Block a user