[CI] Add mteb testing for rerank models (#19344)
This commit is contained in:
@@ -156,7 +156,10 @@ class MeanPool(SimplePooler):
|
||||
) -> Union[list[torch.Tensor], torch.Tensor]:
|
||||
prompt_lens = self.get_prompt_lens(hidden_states, pooling_metadata)
|
||||
|
||||
cumsum = torch.cumsum(hidden_states, dim=0)
|
||||
# Use float32 for torch.cumsum in MeanPool,
|
||||
# otherwise precision will be lost significantly.
|
||||
cumsum = torch.cumsum(hidden_states, dim=0, dtype=torch.float32)
|
||||
|
||||
start_indices = torch.cat([
|
||||
torch.tensor([0], device=hidden_states.device),
|
||||
torch.cumsum(prompt_lens[:-1], dim=0)
|
||||
@@ -220,6 +223,13 @@ class PoolerHead(nn.Module):
|
||||
def forward(self, pooled_data: Union[list[torch.Tensor], torch.Tensor],
|
||||
pooling_metadata: PoolingMetadata):
|
||||
|
||||
# Using float32 in PoolerHead
|
||||
if isinstance(pooled_data, list):
|
||||
for i in range(len(pooled_data)):
|
||||
pooled_data[i] = pooled_data[i].to(torch.float32)
|
||||
else:
|
||||
pooled_data = pooled_data.to(torch.float32)
|
||||
|
||||
dimensions_list = [
|
||||
pooling_param.dimensions
|
||||
for _, pooling_param in pooling_metadata.seq_groups
|
||||
|
||||
@@ -414,15 +414,10 @@ class BertEmbeddingModel(nn.Module, SupportsV0Only, SupportsQuant):
|
||||
intermediate_tensors: Optional[IntermediateTensors] = None,
|
||||
inputs_embeds: Optional[torch.Tensor] = None,
|
||||
) -> torch.Tensor:
|
||||
hidden_states = self.model(input_ids=input_ids,
|
||||
position_ids=positions,
|
||||
inputs_embeds=inputs_embeds,
|
||||
intermediate_tensors=intermediate_tensors)
|
||||
|
||||
# convert the embedding output to float32,
|
||||
# otherwise precision will be lost significantly
|
||||
hidden_states = hidden_states.to(torch.float32)
|
||||
return hidden_states
|
||||
return self.model(input_ids=input_ids,
|
||||
position_ids=positions,
|
||||
inputs_embeds=inputs_embeds,
|
||||
intermediate_tensors=intermediate_tensors)
|
||||
|
||||
def pooler(
|
||||
self,
|
||||
|
||||
@@ -432,12 +432,7 @@ class BertWithRope(nn.Module, SupportsV0Only, SupportsQuant):
|
||||
else:
|
||||
hidden_states = self.embeddings(input_ids=input_ids,
|
||||
token_type_ids=token_type_ids)
|
||||
hidden_states = self.encoder(positions, hidden_states)
|
||||
|
||||
# convert the embedding output to float32,
|
||||
# otherwise precision will be lost significantly
|
||||
hidden_states = hidden_states.to(torch.float32)
|
||||
return hidden_states
|
||||
return self.encoder(positions, hidden_states)
|
||||
|
||||
def load_weights(self, weights: Iterable[tuple[str,
|
||||
torch.Tensor]]) -> set[str]:
|
||||
|
||||
Reference in New Issue
Block a user