huggingface / diffusers

🤗 Diffusers: State-of-the-art diffusion models for image and audio generation in PyTorch and FLAX.
https://huggingface.co/docs/diffusers
Apache License 2.0
26.45k stars 5.45k forks source link

AttributeError: module transformers has no attribute FeatureExtractionMixin #246

Closed loretoparisi closed 2 years ago

loretoparisi commented 2 years ago

Describe the bug

Getting the error

AttributeError: module transformers has no attribute FeatureExtractionMixin

when running the example script provided for StableDiffusio v1.3: https://huggingface.co/CompVis/stable-diffusion-v1-3

Reproduction

# make sure you're logged in with `huggingface-cli login`
import os
import torch
from torch import autocast
from diffusers import StableDiffusionPipeline, LMSDiscreteScheduler

# To swap out the noise scheduler, pass it to from_pretrained:
lms = LMSDiscreteScheduler(
    beta_start=0.00085, 
    beta_end=0.012, 
    beta_schedule="scaled_linear"
)

device = 'cuda' if torch.cuda.is_available() else 'cpu'
device_name = torch.cuda.get_device_name(0)
print(f'running on {device} name {device_name}')

pipe = StableDiffusionPipeline.from_pretrained(
    "CompVis/stable-diffusion-v1-3", 
    scheduler=lms,
    torch_dtype=torch.float16,
    revision="fp16",
    use_auth_token=True
    cache_dir=os.getenv("cache_dir", "./models")
).to(device)

prompt = "a photo of an astronaut riding a horse on mars"
with autocast(device):
    image = pipe(prompt)["sample"][0]  

image.save("astronaut_rides_horse.png")

requirements.txt:

scipy
transformers
torch
diffusers

Logs

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_2015/1295046785.py in <module>
     14 device = 'cuda' if torch.cuda.is_available() else 'cpu'
     15 print(f'running on {device}')
---> 16 pipe = StableDiffusionPipeline.from_pretrained(
     17     "CompVis/stable-diffusion-v1-3",
     18     scheduler=lms,

~/.conda/envs/default/lib/python3.9/site-packages/diffusers/pipeline_utils.py in from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
    229                 class_obj = getattr(library, class_name)
    230                 importable_classes = LOADABLE_CLASSES[library_name]
--> 231                 class_candidates = {c: getattr(library, c) for c in importable_classes.keys()}
    232 
    233             if loaded_sub_model is None:

~/.conda/envs/default/lib/python3.9/site-packages/diffusers/pipeline_utils.py in <dictcomp>(.0)
    229                 class_obj = getattr(library, class_name)
    230                 importable_classes = LOADABLE_CLASSES[library_name]
--> 231                 class_candidates = {c: getattr(library, c) for c in importable_classes.keys()}
    232 
    233             if loaded_sub_model is None:

~/.conda/envs/default/lib/python3.9/site-packages/transformers/file_utils.py in __getattr__(self, name)

AttributeError: module transformers has no attribute FeatureExtractionMixin

System Info

OS: 4.14.287-215.504.amzn2.x86_64 (Sagemaker Studio Lab)
diffusers: latest
python: Python 3.9.7
GPU: Tesla T4
hysts commented 2 years ago

Hi, @loretoparisi I think installing transformers>=4.17.0 would solve the problem.

anton-l commented 2 years ago

Indeed, FeatureExtractionMixin is implemented in transformers>=4.17.0, installing a newer version should fix the issue. @loretoparisi feel free to reopen if it doesn't help :)