A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 11, 10:00 UTC
Don'e assume `position_embedding_type` will be present for BERT and RoBERTa models (#30770)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Harry Mellor committed
Dec 16, 2025 at 13:40 UTC
6f15ac5de7303ba0e7ea161452f8cfd9a1445cee
2 files changed
+8
-12
vllm/model_executor/models/bert.py
+3
-1
@@ -55,7 +55,9 @@ class BertEmbedding(nn.Module):
55
"position_ids",
56
torch.arange(config.max_position_embeddings).unsqueeze(0),
57
)
58
- self.position_embedding_type = config.position_embedding_type
58
+ self.position_embedding_type = getattr(
59
+ config, "position_embedding_type", "absolute"
60
+ )
61
if self.position_embedding_type != "absolute":
62
raise ValueError(
63
"Only 'absolute' position_embedding_type" + " is supported"
vllm/model_executor/models/roberta.py
+5
-11
@@ -57,12 +57,6 @@ class RobertaEmbedding(nn.Module):
57
torch.arange(config.max_position_embeddings).unsqueeze(0),
58
)
59
60
- self.position_embedding_type = config.position_embedding_type
61
- if self.position_embedding_type != "absolute":
62
- raise ValueError(
63
- "Only 'absolute' position_embedding_type" + " is supported"
64
- )
65
-
60
def forward(
61
self,
62
input_ids: torch.Tensor,
@@ -135,12 +129,12 @@ class RobertaEmbeddingModel(BertEmbeddingModel):
129
def _build_model(
130
self, vllm_config: VllmConfig, prefix: str = ""
131
) -> BertModel | BertWithRope:
138
- if vllm_config.model_config.hf_config.position_embedding_type == "rotary":
139
- return JinaRobertaModel(vllm_config=vllm_config, prefix=prefix)
132
+ hf_config = vllm_config.model_config.hf_config
133
+ kwargs = dict(vllm_config=vllm_config, prefix=prefix)
134
+ if getattr(hf_config, "position_embedding_type", "absolute") == "absolute":
135
+ return BertModel(**kwargs, embedding_class=RobertaEmbedding)
136
else:
141
- return BertModel(
142
- vllm_config=vllm_config, prefix=prefix, embedding_class=RobertaEmbedding
143
- )
137
+ return JinaRobertaModel(**kwargs)
138
139
def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]):
140
weights_list = list(weights)