Skip to content

dtype mismatch error for IPAdapterPlusXL #466

@yyl-github-1896

Description

@yyl-github-1896

Error information

Traceback (most recent call last):
File "/data/xxx/source/xxx/flux.py", line 207, in
main(args)
File "/data/xxx/source/xxx/flux.py", line 196, in main
image = image_generation_pipe(prompt, pipe, image_prompt, prior_pipe)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/xxx/source/xxx/flux.py", line 126, in image_generation_pipe
image = pipe.generate(
^^^^^^^^^^^^^^
File "/data/xxx/anaconda3/envs/xxx/lib/python3.11/site-packages/ip_adapter/ip_adapter.py", line 396, in generate
) = self.pipe.encode_prompt(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/xxx/anaconda3/envs/xxx/lib/python3.11/site-packages/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py", line 406, in encode_prompt
prompt_embeds = text_encoder(text_input_ids.to(device), output_hidden_states=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/xxx/anaconda3/envs/xxx/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1739, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/xxx/anaconda3/envs/xxx/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1750, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/xxx/anaconda3/envs/xxx/lib/python3.11/site-packages/transformers/models/clip/modeling_clip.py", line 1490, in forward
text_embeds = self.text_projection(pooled_output)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/xxx/anaconda3/envs/xxx/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1739, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/xxx/anaconda3/envs/xxx/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1750, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/xxx/anaconda3/envs/xxx/lib/python3.11/site-packages/torch/nn/modules/linear.py", line 125, in forward
return F.linear(input, self.weight, self.bias)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: expected mat1 and mat2 to have the same dtype, but got: float != c# 10::Half

My code with error

 ```
from diffusers import StableDiffusionXLPipeline
        pipe = StableDiffusionXLPipeline.from_pretrained(
            my_path_to_model,
            torch_dtype=torch.float16,
            add_watermarker=False,
            local_files_only=True
        ).to("cuda")
        if use_image_prior:
            from ip_adapter import IPAdapterPlusXL
            pipe = IPAdapterPlusXL(
                pipe,
                my_path_to_model2, 
                my_path_to_model3, 
                device="cuda",
                num_tokens=16
            )

    image = pipe.generate(
        pil_image=image_prompt, 
        num_samples=1, 
        num_inference_steps=30, 
        seed=42,
        prompt=prompt, 
        scale=0.5)[0][0]
    return image
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions