Module 'torch.library' has no attribute 'custom_op'

First time posting here - the context:

I just wanted to try the below sourcecode from HuggingFace

#%matplotlib inline
import torch

from diffusers.pipelines import DiffusionPipeline
from matplotlib import pyplot as plt 
model_id = ""

ldm = DiffusionPipeline.from_pretrained(model_id)
prompt = "PastelPusheen"
images = ldm([prompt], num_inference_steps=50, eta=0.3, guidance_scale=6)["sample"]
plt.imshow(images[0])

Once it’s run it threw me this error

Traceback (most recent call last):
File “/Users/Casey/Desktop/myDevPortFolio/PastelPusheenGenV2/psndf.py”, line 6, in
from diffusers.pipelines import DiffusionPipeline
File “”, line 1075, in _handle_fromlist
File “/Users/Casey/Desktop/myDevPortFolio/PastelPusheenGenV2/my-env/lib/python3.10/site-packages/diffusers/utils/import_utils.py”, line 943, in getattr
module = self._get_module(self._class_to_module[name])
File “/Users/Casey/Desktop/myDevPortFolio/PastelPusheenGenV2/my-env/lib/python3.10/site-packages/diffusers/utils/import_utils.py”, line 955, in _get_module
raise RuntimeError(
RuntimeError: Failed to import diffusers.pipelines.pipeline_utils because of the following error (look up to see its traceback):
Failed to import diffusers.models.autoencoders.autoencoder_kl because of the following error (look up to see its traceback):

I don’t understand this - I tried deleting and re-installing pytorch etc but none of them helped. Could anyone point me in the right direction?

Which Pytorch version are you using? You can check it e.g. via print(torch.__version__) inside your script. I guess you might be using an older release and would need to update.

Hello! I have the same problem. I’m using torch 2.2.2, and I can’t upgrade it for some reason. I’m also using python3.11. What python version works, and with what torch version? Any ideas?

Thanks!

What kind of error are you seeing and which diffusers version are you using? If you need to use an older PyTorch release you might need to stick to an older diffusers release as well, which was compatible with your PyTorch binary.

pytorch 2.3.0 diffuser 0.35.1 from diffusers.pipelines.pipeline_utils import DiffusionPipeline occurs error module ‘torch.library’ has no attribute ‘custom_op’

I solve it by updating pytorch to 2.5.0

1 Like

So I marked jhon_how’s answer as upgrading pytorch was my only way to get rid of this error also. However, I have to try running everything via docker as mentioned on this post Building PyTorch 2.6.0 from source on macOS x86_64 (Intel) As my workstation is Intel-based macOS, I had to take an extra step described in the above link.

Thank you so much for the inputs everyone :slight_smile: