BLD: require peft>=0.18.0 for transformers 5.x compatibility - #5260
Merged
qinxuye merged 1 commit intoJul 30, 2026
Merged
Conversation
peft 0.17.1 and below import HybridCache at module level in
peft/peft_model.py:
from transformers import Cache, DynamicCache, EncoderDecoderCache, \
HybridCache, PreTrainedModel
HybridCache was removed in transformers 5.0.0, and peft declares an
unbounded transformers requirement, so pip happily resolves the pair and
the failure only surfaces at runtime.
This broke launching any rerank model on the sentence_transformers
engine, via the import chain:
rerank/sentence_transformers/core.py -> import sentence_transformers
-> base/model_card.py -> from transformers import TrainerCallback
-> trainer_utils.py -> from peft import PeftMixedModel, PeftModel
-> ImportError: cannot import name 'HybridCache'
The reported error was misleading: core.py wraps the ImportError as
"Failed to import module 'sentence-transformers'" and suggests installing
sentence-transformers, which is unrelated and already present. GGUF LLMs
were unaffected because they never touch this chain, so only rerank and
embedding models appeared broken.
The <=0.17.1 upper bound was added in xorbitsai#4249 when transformers was still
4.x; it became inconsistent once requirements-runtime.txt moved to
transformers==5.13.1. peft 0.18.0 made the HybridCache import lazy, so
requiring >=0.18.0 fixes the conflict.
Verified in a clean venv that transformers 5.13.1 + peft 0.17.1
reproduces the ImportError, and that peft>=0.18.0 restores both
`import sentence_transformers` and a full CrossEncoder rerank predict.
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the dependency constraint for peft from <=0.17.1 to >=0.18.0 in both pyproject.toml and requirements_cpu-ml.txt to avoid compatibility issues with transformers 5.0.0. Feedback points out that the corresponding update to .github/workflows/python.yaml is missing and should be added to maintain consistency across all configuration files.
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.
Problem
Launching any rerank model on the
sentence_transformersengine fails at load time with:The suggested remedy is misleading —
sentence-transformersis installed and is not the problem.Root cause
peft<=0.17.1importsHybridCacheat module level inpeft/peft_model.py:HybridCachewas removed in transformers 5.0.0 (present in 4.57.1, gone from 5.0.0 onward). Becausepeftdeclares an unboundedtransformersrequirement, pip resolves the incompatible pair without any warning, so images build fine and the failure only appears at runtime.The failing import chain:
core.pycatches theImportErrorand re-raises it as "Failed to import module 'sentence-transformers'", which hides the real cause. GGUF LLMs never touch this chain, so on an affected image LLMs work while rerank/embedding models appear broken — which makes this easy to misdiagnose as a rerank bug.The
<=0.17.1upper bound was introduced in #4249 while transformers was still 4.x. It became self-inconsistent oncexinference/deploy/docker/requirements-runtime.txtmoved totransformers==5.13.1: the GPU image installs xinference under that constraint, and the CPU image pins both inrequirements_cpu-ml.txt(transformers>=4.53.3+peft<=0.17.1).peft0.18.0 moved theHybridCacheimport inside the function that needs it, so it no longer breaks at import time.Fix
Require
peft>=0.18.0in the three places the pin appears:pyproject.toml— also covers the GPU image, which installs xinference with--constraint requirements-runtime.txtxinference/deploy/docker/requirements_cpu/requirements_cpu-ml.txt.github/workflows/python.yamlComments were added at the first two sites recording the transformers-5.x constraint, so the bound is not lowered again without checking the shipped transformers major version.
Verification
In a clean venv:
transformers==5.13.1+peft==0.17.1installs with no pip warning and reproduces the exactImportErrorfrom the report.peft>=0.18.0(resolved 0.20.0) against the sametransformers==5.13.1:import sentence_transformers,from sentence_transformers.cross_encoder import CrossEncoder, a fullCrossEncoder.predictrerank call, andfrom peft import PeftModel, PeftMixedModel(used byllm/transformers/core.py) all succeed.pre-commit run --files <changed files>passes;pyproject.tomlparses and resolves topeft>=0.18.0.Not run locally: rerank tests that require model downloads or GPU, and a full image rebuild — both too costly in this environment.
test_auto_detect_typefails on my machine both with and without this change, due to a pre-existing local numpy/scipy ABI mismatch unrelated to the patch.