model loading error

#34
by EvgeniyKr - opened

I`m trying this:

Load the pipeline

if torch.cuda.is_available():
torch_dtype = torch.bfloat16
device = "cuda"
else:
torch_dtype = torch.float32
device = "cpu"
pipe = DiffusionPipeline.from_pretrained(model_name, torch_dtype=torch_dtype)
pipe = pipe.to(device)

and got error:
File "C:\Users\Admin\AppData\Roaming\Python\Python311\site-packages\diffusers\utils\import_utils.py", line 876, in getattr
raise AttributeError(f"module {self.name} has no attribute {name}")
AttributeError: module diffusers has no attribute QwenImagePipeline. Did you mean: 'HiDreamImagePipeline'?

diffusers - 0.34.0
python 3.11

please help

got the same error here, maybe diffuser libary hasnt update the attribute yet?

EvgeniyKr changed discussion title from Error to load model to model loading error

@EvgeniyKr @jingieboy

Try installing:

!pip install git+https://github.com/huggingface/diffusers.git

This installs version 0.35.0.dev0 of diffusers. Then, try loading the model.

from diffusers import DiffusionPipeline
import torch

model_name = "Qwen/Qwen-Image"

# Load the pipeline
if torch.cuda.is_available():
    torch_dtype = torch.bfloat16
    device = "cuda"
else:
    torch_dtype = torch.float32
    device = "cpu"

pipe = DiffusionPipeline.from_pretrained(model_name, torch_dtype=torch_dtype)
pipe = pipe.to(device)

positive_magic = {
    "en": "Ultra HD, 4K, cinematic composition." # for english prompt,
    "zh": "超清,4K,电影级构图" # for chinese prompt,
}

# Generate image
prompt = '''A coffee shop entrance features a chalkboard sign reading "Qwen Coffee 😊 $2 per cup," with a neon light beside it displaying "通义千问". Next to it hangs a poster showing a beautiful Chinese woman, and beneath the poster is written "π≈3.1415926-53589793-23846264-33832795-02384197". Ultra HD, 4K, cinematic composition'''

negative_prompt = " " # using an empty string if you do not have specific concept to remove


# Generate with different aspect ratios
aspect_ratios = {
    "1:1": (1328, 1328),
    "16:9": (1664, 928),
    "9:16": (928, 1664),
    "4:3": (1472, 1140),
    "3:4": (1140, 1472),
    "3:2": (1584, 1056),
    "2:3": (1056, 1584),
}

width, height = aspect_ratios["16:9"]

image = pipe(
    prompt=prompt + positive_magic["en"],
    negative_prompt=negative_prompt,
    width=width,
    height=height,
    num_inference_steps=50,
    true_cfg_scale=4.0,
    generator=torch.Generator(device="cuda").manual_seed(42)
).images[0]

image.save("example.png")

I got it working with different pipeline. Try changing the following:

  1. from diffusers import DiffusionPipeline => from diffusers import QwenImagePipeline
  2. pipe = DiffusionPipeline.from_pretrained(...) => pipe = QwenImagePipeline.from_pretrained(...)

Had to change it according to model_index.json and it worked

Sign up or log in to comment