Skip to content

Add last token pooling support for ORT. #664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions backends/ort/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl OrtBackend {
let pool = match model_type {
ModelType::Classifier => Pool::Cls,
ModelType::Embedding(pool) => match pool {
Pool::Splade | Pool::LastToken => {
Pool::Splade => {
return Err(BackendError::Start(format!(
"Pooling {pool} is not supported for this backend. Use `candle` backend instead."
)));
Expand Down Expand Up @@ -204,8 +204,10 @@ impl Backend for OrtBackend {
let pooled_embeddings = match self.pool {
// CLS pooling
Pool::Cls => outputs.slice(s![.., 0, ..]).into_owned().into_dyn(),
// Last token pooling is not supported for this model
Pool::LastToken => unreachable!(),
Pool::LastToken => {
let axis_len = outputs.len_of(Axis(1));
outputs.slice(s![.., axis_len - 1, ..]).into_owned().into_dyn()
},
// Mean pooling
Pool::Mean => {
if masking {
Expand Down