fix: replace deprecated CLIPFeatureExtractor with CLIPImageProcessor for transformers 5.x compatibility#2315
Merged
kohya-ss merged 1 commit intokohya-ss:sd3from Apr 23, 2026
Conversation
CLIPFeatureExtractor was renamed to CLIPImageProcessor in transformers 4.x and fully removed in transformers 5.x. This causes an ImportError when running sd-scripts with transformers>=5.0.0. Replace the import with CLIPImageProcessor aliased as CLIPFeatureExtractor to maintain backward compatibility while supporting newer transformers versions. Affected files: - library/lpw_stable_diffusion.py - library/sdxl_lpw_stable_diffusion.py Fixes: ImportError: cannot import name 'CLIPFeatureExtractor' from 'transformers'
Contributor
|
This change isn’t enough for Anima; you’ll also need to modify the following code: https://github.com/kohya-ss/sd-scripts/blob/main/library/strategy_anima.py#64 Change 'batch_encode_plus' to '_encode_plus' I haven’t tested whether other training scripts work properly; scripts that use Qwen as the TE may also need to be modified. |
Owner
|
Thank you for this PR! As WhitePr mentioned, it seems that several additional modifications are needed to support transformers 5, so I will address this after the merge. |
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
CLIPFeatureExtractorwas deprecated in transformers 4.x (renamed toCLIPImageProcessor) and fully removed in transformers 5.0. Users running sd-scripts withtransformers>=5.0.0get the following error:This affects both
lpw_stable_diffusion.pyandsdxl_lpw_stable_diffusion.py.Fix
Replace the import with
CLIPImageProcessoraliased asCLIPFeatureExtractorto maintain full backward compatibility while supporting transformers 5.x:Files changed
library/lpw_stable_diffusion.pylibrary/sdxl_lpw_stable_diffusion.pyTesting
Verified working with: