fix(classifier): adopt the tokenizer pad_token_id when the model config lacks one - #670
Open
olesxg wants to merge 1 commit into
Open
fix(classifier): adopt the tokenizer pad_token_id when the model config lacks one#670olesxg wants to merge 1 commit into
olesxg wants to merge 1 commit into
Conversation
…ig lacks one Decoder-only sequence-classification heads (Qwen2/Qwen3ForSequenceClassification) raise `Cannot handle batch sizes > 1 if no padding token is defined.` when config.pad_token_id is unset. michaelfeil/Qwen3-Reranker-0.6B-seq, produced by docs/lm_head_to_classifier/convert_lm.py, ships without that key, so infinity crashes during warmup at batch_size=32 before serving a request. No-op for every checkpoint that already carries pad_token_id.
Contributor
Greptile SummaryThe PR prevents decoder-only sequence classifiers from failing on batched inference when their model configuration omits a padding token ID.
Confidence Score: 5/5The PR appears safe to merge, with no concrete changed-code failure identified. The helper is narrowly scoped to missing configuration values, preserves existing model settings, tolerates tokenizers without padding, and runs before downstream model transformations that retain the updated configuration.
|
| Filename | Overview |
|---|---|
| libs/infinity_emb/infinity_emb/transformer/classifier/torch.py | Safely synchronizes a missing model padding token ID from the tokenizer before classifier optimization and inference. |
| libs/infinity_emb/tests/unit_test/transformer/classifier/test_torch_classifer.py | Adds isolated coverage for all branches of the padding-token synchronization helper. |
Reviews (1): Last reviewed commit: "fix(classifier): adopt the tokenizer pad..." | Re-trigger Greptile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
docs/lm_head_to_classifier/convert_lm.py(lines 166-170) listsQwen/Qwen3-Reranker-0.6B,-4Band-8B, and the converted checkpoints are publishedas
michaelfeil/Qwen3-Reranker-0.6B-seqet al. Theirconfig.jsoncarriesarchitectures: ["Qwen3ForSequenceClassification"]andid2label: {"0": "no", "1": "yes"}but no
pad_token_idkey.transformers' decoder-only sequence-classification forward requires one as soon as the
batch is larger than 1:
infinity hits this during
loaded_engine.warmup(batch_size=engine_args.batch_size, ...)in
inference/select_model.py, with the defaultbatch_size=32— so the server failsat load, before serving a single request.
michaelfeil/mxbai-rerank-base-v2-seqis unaffected because its config shipspad_token_id: 151643, which is why this has gone unnoticed.Fix
Adopt the tokenizer's
pad_token_idwhen the model config does not have one, rightafter the
pipeline(...)call and before quantization / BetterTransformer / compilewrap the model. It is a strict no-op for every checkpoint that already carries the key.
The four lines live in a small module-level helper rather than inline so they can be
unit-tested without downloading a model — which matters here, because the test group
pins
transformers = "4.47.0", and that version cannot parsemodel_type: qwen3at all.Which path this touches
inference/select_model.pyroutes on label count:len(id2label) < 2goes toRerankEngine, otherwisePredictEngine. These checkpoints have 2 labels, so they goto
SentenceClassifierand never reachCrossEncoderPatched. The crossencoder path istherefore untouched — the 1-label rerankers that do reach it are BERT-family encoders
that always carry
pad_token_id.Test
Three assertion-level tests appended to the existing
tests/unit_test/transformer/classifier/test_torch_classifer.py, usingtypes.SimpleNamespacestand-ins: missing -> adopted, already set -> untouched,tokenizer has none -> no crash. No download, no torch, version-independent, so they run
on the pinned 4.47.0 in CI. No new model id added to
conftest.py.Deliberately not in scope
No change to the
transformersfloor — I saw #620 was closed for exactly that reason(ONNX-optimum and BetterTransformer breakage). No causal-LM reranker engine, no
server-side Qwen chat template, no rerank-API
instructionfield. This is only theload-time crash.
Related to but does not close #642.
Verified
Config of the published checkpoint (
michaelfeil/Qwen3-Reranker-0.6B-seq/raw/main/config.json):versus
michaelfeil/mxbai-rerank-base-v2-seq, which carriespad_token_id: 151643and works today.Minimal reproduction, on this repo's own pinned
transformers==4.47.0, no download required(Qwen2 stands in for Qwen3 because 4.47.0 cannot parse
model_type: qwen3— the defect is inthe shared decoder-only sequence-classification path, not in Qwen3 specifically):
Local test run (Windows, Python 3.11.9):
ruff checkandcodespellpass;ruff format --checkdoes not flag either changed file;mypy ./infinity_emboutput is identical tomain.I have not benchmarked the converted checkpoint or verified score parity against the original
causal-LM model — this PR is only about the load-time crash.