Fix Gemma reranker imports with Transformers v5#1580
Open
Gui-Yue wants to merge 1 commit into
Open
Conversation
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.
Summary
This PR fixes a remaining Transformers v5 import compatibility issue in the Gemma decoder-only reranker.
FlagEmbeddingalready has Transformers v5 compatibility work in #1563, and #1571 is addressing tokenizer API changes in reranker inference. This PR is complementary to both: it handles an import-time failure caused bygemma_model.pyimporting private Gemma2 docstring constants fromtransformers.models.gemma2.modeling_gemma2.In Transformers v5,
GEMMA2_START_DOCSTRINGandGEMMA2_INPUTS_DOCSTRINGare no longer available from that private module path. They are only used for generated docstrings, so falling back to empty strings preserves importability without changing runtime model behavior.Changes
GEMMA2_START_DOCSTRINGandGEMMA2_INPUTS_DOCSTRINGoptional inFlagEmbedding/inference/reranker/decoder_only/models/gemma_model.py.CostWiseGemmaForCausalLMintests/test_imports_v5.py.Reproduction
I reproduced the original import failure in a temporary local environment with:
The pre-fix import statement used by
FlagEmbedding/inference/reranker/decoder_only/models/gemma_model.pyfails with Transformers v5:Output:
These symbols are only used for generated docstrings, and they are not present in the Transformers v5
modeling_gemma2.pymodule.Verification
After this change, the Gemma reranker module imports successfully in the same environment:
Output:
Top-level import also works:
Output:
I also ran the v5 import test file:
PYTHONPATH=$PWD python -m pytest tests/test_imports_v5.py -qOutput:
Related PRs
is_torch_fx_availablecompatibility path for Transformers v5.Related Issues
FlagEmbedding/inference/reranker/decoder_only/models/gemma_model.pyafter upgrading Transformers, caused by private Gemma2 symbols imported fromtransformers.models.gemma2.modeling_gemma2.is_torch_fx_availablefunction #1561 is related background for the same class of Transformers v5 compatibility issue. It covered the removedis_torch_fx_availableAPI and was resolved by feat: add compatibility with transformers V5 #1563.