[Bugfix] Preserve padding token types for cross encoders (#58143)

Signed-off-by: zhaoye <772971548@qq.com>
Co-authored-by: Taneem Ibrahim <taneem.ibrahim@gmail.com>
This commit is contained in:
Feanor
2026-10-15 03:09:24 +00:00
committed by GitHub
co-authored by Taneem Ibrahim
parent 429a3da665
commit 5d5c3d7c43
5 changed files with 64 additions and 25 deletions
@@ -105,12 +105,15 @@ class EncoderOnlyModelState(DefaultModelState):
if pooling_params is None or pooling_params.extra_kwargs is None:
return
token_type_start = pooling_params.extra_kwargs.get("compressed_token_type_ids")
if token_type_start is not None:
token_type_range = pooling_params.extra_kwargs.get("compressed_token_type_ids")
if token_type_range is not None:
assert new_req_data.prompt_token_ids is not None
token_type_start, token_type_end = token_type_range
positions = torch.arange(
len(new_req_data.prompt_token_ids), dtype=torch.int32
)
self.token_type_ids[new_req_data.req_id] = (
torch.arange(len(new_req_data.prompt_token_ids), dtype=torch.int32)
>= token_type_start
(positions >= token_type_start) & (positions < token_type_end)
).to(torch.int32)
def remove_request(self, req_id: str) -> None: