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

Casey_KimScripts: <p>First time posting here - the context:</p>
<p>I just wanted to try the below sourcecode from HuggingFace</p>
<pre><code class="lang-auto">#%matplotlib inline
</code></pre>
<pre><code class="lang-auto">import torch
</code></pre>
<pre><code class="lang-auto">
</code></pre>
<pre><code class="lang-auto">from diffusers.pipelines import DiffusionPipeline
</code></pre>
<pre><code class="lang-auto">from matplotlib import pyplot as plt 
</code></pre>
<pre><code class="lang-auto">model_id = ""
</code></pre>
<pre><code class="lang-auto">
</code></pre>
<pre><code class="lang-auto">ldm = DiffusionPipeline.from_pretrained(model_id)
</code></pre>
<pre><code class="lang-auto">prompt = "PastelPusheen"
</code></pre>
<pre><code class="lang-auto">images = ldm([prompt], num_inference_steps=50, eta=0.3, guidance_scale=6)["sample"]
</code></pre>
<pre><code class="lang-auto">plt.imshow(images[0])
</code></pre>
<p>Once it’s run it threw me this error</p>
<p><code>Traceback (most recent call last):</code><br>
<code>File “/Users/Casey/Desktop/myDevPortFolio/PastelPusheenGenV2/psndf.py”, line 6, in </code><br>
<code>from diffusers.pipelines import DiffusionPipeline</code><br>
<code>File “”, line 1075, in _handle_fromlist</code><br>
<code>File “/Users/Casey/Desktop/myDevPortFolio/PastelPusheenGenV2/my-env/lib/python3.10/site-packages/diffusers/utils/import_utils.py”, line 943, in </code><strong><code>getattr</code></strong><br>
<code>module = self._get_module(self._class_to_module[name])</code><br>
<code>File “/Users/Casey/Desktop/myDevPortFolio/PastelPusheenGenV2/my-env/lib/python3.10/site-packages/diffusers/utils/import_utils.py”, line 955, in _get_module</code><br>
<code>raise RuntimeError(</code><br>
<code>RuntimeError: Failed to import diffusers.pipelines.pipeline_utils because of the following error (look up to see its traceback):</code><br>
<code>Failed to import diffusers.models.autoencoders.autoencoder_kl because of the following error (look up to see its traceback):</code></p>
<p>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?</p>

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

tdiprima: <p>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?</p>
<p>Thanks!</p>

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

jhon_How: <p>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’</p>

jhon_How: <aside class="quote no-group" data-username="Casey_KimScripts" data-post="1" data-topic="222610">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/casey_kimscripts/48/78035_2.png" class="avatar"> Casey_KimScripts:</div>
<blockquote>
<p><code>from diffusers.pipelines import DiffusionPipeline</code></p>
</blockquote>
</aside>
<p>I solve it by updating pytorch to 2.5.0</p>

Casey_KimScripts: <p>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 <a href="https://discuss.pytorch.org/t/building-pytorch-2-6-0-from-source-on-macos-x86-64-intel/216283" class="inline-onebox">Building PyTorch 2.6.0 from source on macOS x86_64 (Intel)</a> As my workstation is Intel-based macOS, I had to take an extra step described in the above link.</p>
<p>Thank you so much for the inputs everyone <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=14" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>