Can't use safetensors in the tutorial

Hi experts!
I’m new to diffusers and following the official tutorial. But I have trouble making the first pipeline:

from diffusers import DDPMPipeline
ddpm = DDPMPipeline.from_pretrained("google/ddpm-cat-256", use_safetensors=True).to('cuda')
image = ddpm(num_inference_steps=25).images[0]
image.save("pipline_cat.png")

It reports:

 "OSError: Could not find the necessary `safetensors` weights in {'diffusion_pytorch_model.bin', 'diffusion_pytorch_model.safetensors'} (variant=None)"

When I remove the ‘use_safetensores=True’ parameter, the error disappears. However, this also means I can no longer use safetensors to load the model. Could you advise how I might resolve this issue?

My Environment:

  • :hugs: Diffusers version: 0.32.2
  • Platform: Linux-5.15.0-130-generic-x86_64-with-glibc2.31
  • Running on Google Colab?: No
  • Python version: 3.10.16
  • PyTorch version (GPU?): 2.4.1+cu124 (True)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Huggingface_hub version: 0.28.1
  • Transformers version: 4.48.3
  • Accelerate version: 1.4.0
  • PEFT version: not installed
  • Bitsandbytes version: not installed
  • Safetensors version: 0.5.2
  • xFormers version: not installed
1 Like

It seems to be just a bug in Diffusers. In other words, the safetensors file placed in the root directory is not recognized as a replacement for the bin file.

After fixing the folder structure, it was recognized. I just did save_pretrained…

from diffusers import DDPMPipeline

#ddpm = DDPMPipeline.from_pretrained("google/ddpm-cat-256", use_safetensors=True) # it doesn't work.
ddpm = DDPMPipeline.from_pretrained("google/ddpm-cat-256")
ddpm.save_pretrained("ddpm-sft")
ddpm.from_pretrained("ddpm-sft", use_safetensors=True).to('cuda') # it works.
ddpm = DDPMPipeline.from_pretrained("John6666/google_ddpm-cat-256-safetensors", use_safetensors=True).to('cuda') # it works.
image = ddpm(num_inference_steps=25).images[0]
image.save("pipline_cat.png")
1 Like

Thank you so much for your help! That totally fixed my issue. I really appreciate your time and expertise!

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.