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:




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



torchvision @

I have then tried to upgrade pytorch but that doesn’t work (same error)
My current version of pytorch after upgrading:

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?


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