[Model][LoRA] Enable LoRA support for BERT and RoBERTa embedding models (#61033)
Signed-off-by: hoaivoke <vokehoai@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
716961cf1f
commit
f3cb10b690
@@ -41,7 +41,7 @@ from vllm.sequence import IntermediateTensors
|
||||
from vllm.tasks import PoolingTask
|
||||
from vllm.v1.pool.metadata import PoolingMetadata
|
||||
|
||||
from .interfaces import SupportsCrossEncoding, SupportsQuant
|
||||
from .interfaces import SupportsCrossEncoding, SupportsLoRA, SupportsQuant
|
||||
from .interfaces_base import attn_type, default_pooling_type
|
||||
from .utils import AutoWeightsLoader, WeightsMapper, maybe_prefix
|
||||
|
||||
@@ -448,7 +448,7 @@ class BertPoolingModel(BertModel):
|
||||
|
||||
|
||||
@default_pooling_type(seq_pooling_type="CLS")
|
||||
class BertEmbeddingModel(nn.Module, SupportsQuant):
|
||||
class BertEmbeddingModel(nn.Module, SupportsQuant, SupportsLoRA):
|
||||
"""A model that uses Bert to provide embedding functionalities.
|
||||
|
||||
This class encapsulates the BertModel and provides an interface for
|
||||
@@ -463,9 +463,22 @@ class BertEmbeddingModel(nn.Module, SupportsQuant):
|
||||
is_pooling_model = True
|
||||
embedding_class: type[nn.Module] = BertEmbedding
|
||||
|
||||
packed_modules_mapping = {"qkv_proj": ["query", "key", "value"]}
|
||||
# PEFT adapters name modules relative to the HF backbone (optionally under
|
||||
# `bert.`/`roberta.`), while vLLM nests the backbone under `model.`.
|
||||
hf_to_vllm_mapper = WeightsMapper(
|
||||
orig_to_new_prefix={
|
||||
"bert.": "model.",
|
||||
"roberta.": "model.",
|
||||
"encoder.": "model.encoder.",
|
||||
"embeddings.": "model.embeddings.",
|
||||
}
|
||||
)
|
||||
|
||||
def __init__(self, *, vllm_config: VllmConfig, prefix: str = ""):
|
||||
super().__init__()
|
||||
|
||||
self.config = vllm_config.model_config.hf_config
|
||||
pooler_config = vllm_config.model_config.pooler_config
|
||||
assert pooler_config is not None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user