Error 'expected scalar type Half but found Float'

I’m following along this notebook sd_dreambooth_inference created by HuggingFace.

I got an error ‘expected scalar type Half but found Float’ when trying to do inference

pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
p = pipe(prompt, num_images_per_prompt=num_samples, num_inference_steps=50, guidance_scale=7.5)

I tried adding revision=“fp16” in the pipe declaration but that doesn’t help either, seeing the same error
pipe = StableDiffusionPipeline.from_pretrained(model_id, revision="fp16", torch_dtype=torch.float16).to("cuda")

My initial guess was this has to do with the version of Pytorch. Because I can run this with no error on Google Colab, but face this error when running on Paperspace.

For reference, here are the specifications on each:

On Paperspace with diffusers 0.4.1 and pytorch versions:

torch==1.12.0+cu116

torchaudio==0.12.0+cu116

torchvision==0.13.0+cu116

Works fine on Google Colab using the same diffusers version and slightly more updated version torchvision

torch @ (link)/whl/cu113/torch-1.12.1%2Bcu113-cp37-cp37m-linux_x86_64.whl

torchaudio @ (link)/whl/cu113/torchaudio-0.12.1%2Bcu113-cp37-cp37m-linux_x86_64.whl

torchsummary==1.5.1

torchtext==0.13.1

torchvision @ https://download.pytorch.org/whl/cu113/torchvision-0.13.1%2Bcu113-cp37-cp37m-linux_x86_64.whl

I have then tried to upgrade pytorch but that doesn’t work (same error)
My current version of pytorch after upgrading:
torch==1.13.0
torchaudio==0.12.0+cu116
torchvision==0.14.0

What should I do now? Is this due to the specific GPU type used, or cuda some how? How do I fix this

Thanks in advance for any help and suggestion!

Perhaps you need to upgrade the transformers version in Paperspace?

2 Likes

Thank you so much, that works!!

It didn’t occur to me that the pipeline called transformers

For reference , the version of transformers was 4.20.1 before, and is 4.24.0 after upgrading, works now with the new transformers package version

1 Like