ml-stable-diffusion: diffusers==0.16.0 not working with PyTorch default v2.0.0

Hi team, I got an error when executing python -m python_coreml_stable_diffusion.torch2coreml, it seems diffusers==0.16.0 not working on PyTorch v2.0.0. Use diffusers==0.15.1 works. See following threads.

    convert_nodes(self.context, self.graph)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/coreml_stable_diffusion/lib/python3.8/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 83, in convert_nodes
    raise RuntimeError(
RuntimeError: PyTorch convert function for op 'scaled_dot_product_attention' not implemented.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

There is a PR that I think fixes this issue here: https://github.com/apple/coremltools/pull/2021

Another workaround is to add the following line after the pipeline has been loaded:

pipe.vae.set_default_attn_processor()

Oh, that’s probably because scaled dot-product attention is enabled by default if torch 2 is in use. pipe.unet.set_default_attn_processor() should work. I can test and submit a PR in a few hours.

Edit: The same behaviour (enabling SDPA by default) was already present in 0.15.1 so we might indeed have a regression. I’ll take a closer look.

If your job completes successfully, that seems to mean that diffusers 0.16.0 introduced a software regression that is causing the error for both of us. Perhaps revise the title of this thread and hopefully the issue can get fixed?