[Model] Make the BERT/RoBERTa embedding class a class attribute (#59348)
Signed-off-by: Avishek Goswami <avishek.goswami@ibm.com> Signed-off-by: Avishek Goswami <86944690+GOavi101@users.noreply.github.com> Co-authored-by: Avishek Goswami <avishek.goswami@ibm.com>
This commit is contained in:
co-authored by
Avishek Goswami
parent
3627a6a124
commit
fb91712b38
@@ -117,6 +117,8 @@ class RobertaClassificationHead(nn.Module):
|
||||
class RobertaEmbeddingModel(BertEmbeddingModel):
|
||||
"""A model that uses Roberta to provide embedding functionalities."""
|
||||
|
||||
embedding_class: type[nn.Module] = RobertaEmbedding
|
||||
|
||||
def __init__(self, *, vllm_config: VllmConfig, prefix: str = ""):
|
||||
super().__init__(vllm_config=vllm_config, prefix=prefix)
|
||||
self.padding_idx: int = vllm_config.model_config.hf_config.pad_token_id
|
||||
@@ -143,7 +145,7 @@ class RobertaEmbeddingModel(BertEmbeddingModel):
|
||||
return BertModel(
|
||||
vllm_config=vllm_config,
|
||||
prefix=prefix,
|
||||
embedding_class=RobertaEmbedding,
|
||||
embedding_class=self.embedding_class,
|
||||
)
|
||||
else:
|
||||
return JinaRobertaModel(vllm_config=vllm_config, prefix=prefix)
|
||||
@@ -293,6 +295,8 @@ class RobertaForSequenceClassification(nn.Module, SupportsCrossEncoding, Support
|
||||
}
|
||||
)
|
||||
|
||||
embedding_class: type[nn.Module] = RobertaEmbedding
|
||||
|
||||
def __init__(self, *, vllm_config: VllmConfig, prefix: str = ""):
|
||||
super().__init__()
|
||||
config = vllm_config.model_config.hf_config
|
||||
@@ -303,7 +307,7 @@ class RobertaForSequenceClassification(nn.Module, SupportsCrossEncoding, Support
|
||||
self.roberta = BertModel(
|
||||
vllm_config=vllm_config,
|
||||
prefix=maybe_prefix(prefix, "bert"),
|
||||
embedding_class=RobertaEmbedding,
|
||||
embedding_class=self.embedding_class,
|
||||
)
|
||||
self.classifier = RobertaClassificationHead(vllm_config.model_config)
|
||||
|
||||
@@ -355,6 +359,7 @@ class RobertaForTokenClassification(nn.Module):
|
||||
"""
|
||||
|
||||
is_pooling_model = True
|
||||
embedding_class: type[nn.Module] = RobertaEmbedding
|
||||
|
||||
def __init__(self, *, vllm_config: VllmConfig, prefix: str = ""):
|
||||
super().__init__()
|
||||
@@ -364,7 +369,7 @@ class RobertaForTokenClassification(nn.Module):
|
||||
self.roberta = BertModel(
|
||||
vllm_config=vllm_config,
|
||||
prefix=maybe_prefix(prefix, "roberta"),
|
||||
embedding_class=RobertaEmbedding,
|
||||
embedding_class=self.embedding_class,
|
||||
)
|
||||
self.classifier = nn.Linear(
|
||||
config.hidden_size, config.num_labels, dtype=self.head_dtype
|
||||
|
||||
Reference in New Issue
Block a user