Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
23a04e08
Unverified
Commit
23a04e08
authored
Jun 26, 2025
by
lsz05
Committed by
GitHub
Jun 25, 2025
Browse files
[Fix] Support cls pooling in ModernBertPooler (#20067)
Signed-off-by:
shengzhe.li
<
shengzhe.li@sbintuitions.co.jp
>
parent
02c97d9a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
1 deletion
+8
-1
vllm/model_executor/models/modernbert.py
vllm/model_executor/models/modernbert.py
+8
-1
No files found.
vllm/model_executor/models/modernbert.py
View file @
23a04e08
...
@@ -258,6 +258,7 @@ class ModernBertPooler(nn.Module):
...
@@ -258,6 +258,7 @@ class ModernBertPooler(nn.Module):
super
().
__init__
()
super
().
__init__
()
self
.
dense
=
nn
.
Linear
(
config
.
hidden_size
,
config
.
hidden_size
,
self
.
dense
=
nn
.
Linear
(
config
.
hidden_size
,
config
.
hidden_size
,
config
.
classifier_bias
)
config
.
classifier_bias
)
self
.
pooling_type
=
config
.
classifier_pooling
self
.
act
=
nn
.
GELU
()
self
.
act
=
nn
.
GELU
()
self
.
norm
=
nn
.
LayerNorm
(
config
.
hidden_size
,
self
.
norm
=
nn
.
LayerNorm
(
config
.
hidden_size
,
eps
=
config
.
norm_eps
,
eps
=
config
.
norm_eps
,
...
@@ -265,7 +266,13 @@ class ModernBertPooler(nn.Module):
...
@@ -265,7 +266,13 @@ class ModernBertPooler(nn.Module):
def
forward
(
self
,
hidden_states
:
torch
.
Tensor
)
->
torch
.
Tensor
:
def
forward
(
self
,
hidden_states
:
torch
.
Tensor
)
->
torch
.
Tensor
:
pooled_output
=
hidden_states
pooled_output
=
hidden_states
if
self
.
pooling_type
==
"mean"
:
pooled_output
=
pooled_output
.
mean
(
dim
=
0
,
keepdim
=
False
)
pooled_output
=
pooled_output
.
mean
(
dim
=
0
,
keepdim
=
False
)
elif
self
.
pooling_type
==
"cls"
:
pooled_output
=
pooled_output
[
0
,
:]
else
:
raise
ValueError
(
"Pooling type should be either `cls` or `mean`, "
f
"but got
{
self
.
pooling_type
}
"
)
pooled_output
=
self
.
norm
(
self
.
act
(
self
.
dense
(
pooled_output
)))
pooled_output
=
self
.
norm
(
self
.
act
(
self
.
dense
(
pooled_output
)))
return
pooled_output
return
pooled_output
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment