[Model] Avoid hardcoding pooling type (#32119)

Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
Cyrus Leung
2026-01-11 21:28:12 -08:00
committed by GitHub
parent 025a32f9ed
commit 9101dc756c
6 changed files with 47 additions and 22 deletions
+12 -4
View File
@@ -8,7 +8,7 @@ from transformers import ModernBertConfig
from transformers.activations import ACT2FN
from vllm.compilation.decorators import support_torch_compile
from vllm.config import VllmConfig
from vllm.config import PoolerConfig, VllmConfig
from vllm.distributed import get_tensor_model_parallel_world_size
from vllm.model_executor.layers.attention.encoder_only_attention import (
EncoderOnlyAttention,
@@ -282,9 +282,14 @@ class ModernBertModel(nn.Module):
class ModernBertPooler(SequencePooler):
def __init__(self, config: ModernBertConfig):
def __init__(self, config: ModernBertConfig, pooler_config: PoolerConfig):
hf_pooling_type = config.classifier_pooling.upper()
# vllm_pooling_type = pooler_config.seq_pooling_type
# Currently we don't have a way to see if the user set the pooling type
# explicitly or not, so we always use the HF pooling type for now.
super().__init__(
pooling=get_seq_pooling_method(config.classifier_pooling.upper()),
pooling=get_seq_pooling_method(hf_pooling_type),
head=self.head,
)
@@ -314,7 +319,9 @@ class ModernBertForSequenceClassification(nn.Module, SupportsCrossEncoding):
def __init__(self, *, vllm_config: VllmConfig, prefix: str = ""):
super().__init__()
config = vllm_config.model_config.hf_config
self.config = config
self.model = ModernBertModel(
vllm_config=vllm_config, prefix=maybe_prefix(prefix, "modernbert")
@@ -324,11 +331,12 @@ class ModernBertForSequenceClassification(nn.Module, SupportsCrossEncoding):
config.num_labels,
dtype=vllm_config.model_config.head_dtype,
)
self.pooling = ModernBertPooler(config)
pooler_config = vllm_config.model_config.pooler_config
assert pooler_config is not None
self.pooling = ModernBertPooler(config, pooler_config)
self.pooler = DispatchPooler.for_seq_cls(
pooler_config,
pooling=self.pooling,