Skip to content

fix: replace deprecated CLIPFeatureExtractor with CLIPImageProcessor for transformers 5.x compatibility#2315

Merged
kohya-ss merged 1 commit intokohya-ss:sd3from
marcus165090-spec:fix/transformers5-clip-feature-extractor-compat
Apr 23, 2026
Merged

fix: replace deprecated CLIPFeatureExtractor with CLIPImageProcessor for transformers 5.x compatibility#2315
kohya-ss merged 1 commit intokohya-ss:sd3from
marcus165090-spec:fix/transformers5-clip-feature-extractor-compat

Conversation

@marcus165090-spec
Copy link
Copy Markdown
Contributor

Problem

CLIPFeatureExtractor was deprecated in transformers 4.x (renamed to CLIPImageProcessor) and fully removed in transformers 5.0. Users running sd-scripts with transformers>=5.0.0 get the following error:

ImportError: cannot import name 'CLIPFeatureExtractor' from 'transformers'

This affects both lpw_stable_diffusion.py and sdxl_lpw_stable_diffusion.py.

Fix

Replace the import with CLIPImageProcessor aliased as CLIPFeatureExtractor to maintain full backward compatibility while supporting transformers 5.x:

# Before
from transformers import CLIPFeatureExtractor, CLIPTextModel, CLIPTokenizer, ...

# After
from transformers import CLIPImageProcessor as CLIPFeatureExtractor, CLIPTextModel, CLIPTokenizer, ...

Files changed

  • library/lpw_stable_diffusion.py
  • library/sdxl_lpw_stable_diffusion.py

Testing

Verified working with:

  • Python 3.13.11
  • PyTorch 2.10.0+cu130
  • transformers 5.3.0
  • NVIDIA GeForce RTX 2060

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'
@WhitePr
Copy link
Copy Markdown
Contributor

WhitePr commented Apr 19, 2026

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#57

qwen3_encoding = self.qwen3_tokenizer.batch_encode_plus(
            text, return_tensors="pt", truncation=True, padding="max_length", max_length=self.qwen3_max_length
        )

https://github.com/kohya-ss/sd-scripts/blob/main/library/strategy_anima.py#64

t5_encoding = self.t5_tokenizer.batch_encode_plus(
            text, return_tensors="pt", truncation=True, padding="max_length", max_length=self.t5_max_length
        )

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.

@kohya-ss kohya-ss changed the base branch from main to sd3 April 23, 2026 10:42
@kohya-ss
Copy link
Copy Markdown
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.

@kohya-ss kohya-ss merged commit 13b7297 into kohya-ss:sd3 Apr 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants