lshqqytiger / stable-diffusion-webui-amdgpu

Stable Diffusion web UI
GNU Affero General Public License v3.0
1.79k stars 185 forks source link

[Bug]: NotImplementedError: No operator found for `memory_efficient_attention_forward` #444

Closed patritha closed 5 months ago

patritha commented 5 months ago

Checklist

What happened?

just installed this so i could hopefully use my amd gpu for sd. running with --xformers yields "NotImplementedError: No operator found for memory_efficient_attention_forward" and using it without --xformers yields "import of xformers halted; None in sys.modules" i just cant win

Steps to reproduce the problem

1: install sd webui directml 2: run a generation 2: watch it not work

What should have happened?

completed the generation instead of erroring

What browsers do you use to access the UI ?

Mozilla Firefox

Sysinfo

sysinfo-2024-04-16-06-10.json

Console logs

venv "A:\Stupid Folder\stable-diffusion-webui-directml\venv\Scripts\Python.exe"
fatal: detected dubious ownership in repository at 'A:/Stupid Folder/stable-diffusion-webui-directml'
'A:/Stupid Folder/stable-diffusion-webui-directml' is owned by:
        BUILTIN/Administrators (S-1-5-32-544)
but the current user is:
        DESKTOP-J5427GK/gabe (S-1-5-21-786191698-4050043721-1864713261-1001)
To add an exception for this directory, call:

        git config --global --add safe.directory 'A:/Stupid Folder/stable-diffusion-webui-directml'
fatal: detected dubious ownership in repository at 'A:/Stupid Folder/stable-diffusion-webui-directml'
'A:/Stupid Folder/stable-diffusion-webui-directml' is owned by:
        BUILTIN/Administrators (S-1-5-32-544)
but the current user is:
        DESKTOP-J5427GK/gabe (S-1-5-21-786191698-4050043721-1864713261-1001)
To add an exception for this directory, call:

        git config --global --add safe.directory 'A:/Stupid Folder/stable-diffusion-webui-directml'
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Version: 1.9.0
Commit hash: <none>
WARNING:xformers:WARNING[XFORMERS]: xFormers can't load C++/CUDA extensions. xFormers was built for:
    PyTorch 2.1.2+cu121 with CUDA 1201 (you have 2.0.0+cpu)
    Python  3.10.11 (you have 3.10.6)
  Please reinstall xformers (see https://github.com/facebookresearch/xformers#installing-xformers)
  Memory-efficient attention, SwiGLU, sparse and more won't be available.
  Set XFORMERS_MORE_DETAILS=1 for more details
A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\pytorch_lightning\utilities\distributed.py:258: LightningDeprecationWarning: `pytorch_lightning.utilities.distributed.rank_zero_only` has been deprecated in v1.8.1 and will be removed in v2.0.0. You can import it from `pytorch_lightning.utilities` instead.
  rank_zero_deprecation(
Launching Web UI with arguments: --skip-torch-cuda-test --use-directml --no-half --precision full --xformers
ONNX: selected=CUDAExecutionProvider, available=['DmlExecutionProvider', 'CPUExecutionProvider']
==============================================================================
You are running torch 2.0.0+cpu.
The program is tested to work with torch 2.1.2.
To reinstall the desired version, run with commandline flag --reinstall-torch.
Beware that this will cause a lot of large files to be downloaded, as well as
there are reports of issues with training tab on the latest version.

Use --skip-version-check commandline argument to disable this check.
==============================================================================
Loading weights [6ce0161689] from A:\Stupid Folder\stable-diffusion-webui-directml\models\Stable-diffusion\v1-5-pruned-emaonly.safetensors
Creating model from config: A:\Stupid Folder\stable-diffusion-webui-directml\configs\v1-inference.yaml
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 3.8s (prepare environment: 5.5s, initialize shared: 0.8s, load scripts: 0.6s, create ui: 0.3s, gradio launch: 0.3s).
Couldn't find VAE named None; using None instead
Applying attention optimization: InvokeAI... done.
Model loaded in 2.4s (load weights from disk: 0.4s, create model: 0.3s, apply weights to model: 1.6s).
100%|██████████████████████████████████████████████████████████████████████████████████| 20/20 [00:33<00:00,  1.67s/it]
*** Error completing request███████████████████████████████████████████████████████████| 20/20 [00:31<00:00,  1.65s/it]
*** Arguments: ('task(tc3tiwioy3xieu0)', <gradio.routes.Request object at 0x000001BFD5A8F730>, 'test', '', [], 1, 1, 7, 512, 512, False, 0.7, 2, 'Latent', 0, 0, 0, 'Use same checkpoint', 'Use same sampler', 'Use same scheduler', '', '', [], 0, 20, 'DPM++ 2M', 'Automatic', False, '', 0.8, -1, False, -1, 0, 0, 0, False, False, 'positive', 'comma', 0, False, False, 'start', '', 1, '', [], 0, '', [], 0, '', [], True, False, False, False, False, False, False, 0, False) {}
    Traceback (most recent call last):
      File "A:\Stupid Folder\stable-diffusion-webui-directml\modules\call_queue.py", line 57, in f
        res = list(func(*args, **kwargs))
      File "A:\Stupid Folder\stable-diffusion-webui-directml\modules\call_queue.py", line 36, in f
        res = func(*args, **kwargs)
      File "A:\Stupid Folder\stable-diffusion-webui-directml\modules\txt2img.py", line 109, in txt2img
        processed = processing.process_images(p)
      File "A:\Stupid Folder\stable-diffusion-webui-directml\modules\processing.py", line 847, in process_images
        res = process_images_inner(p)
      File "A:\Stupid Folder\stable-diffusion-webui-directml\modules\processing.py", line 1087, in process_images_inner
        x_samples_ddim = decode_latent_batch(p.sd_model, samples_ddim, target_device=devices.cpu, check_for_nans=True)
      File "A:\Stupid Folder\stable-diffusion-webui-directml\modules\processing.py", line 634, in decode_latent_batch
        sample = decode_first_stage(model, batch[i:i + 1])[0]
      File "A:\Stupid Folder\stable-diffusion-webui-directml\modules\sd_samplers_common.py", line 76, in decode_first_stage
        return samples_to_images_tensor(x, approx_index, model)
      File "A:\Stupid Folder\stable-diffusion-webui-directml\modules\sd_samplers_common.py", line 58, in samples_to_images_tensor
        x_sample = model.decode_first_stage(sample.to(model.first_stage_model.dtype))
      File "A:\Stupid Folder\stable-diffusion-webui-directml\modules\sd_hijack_utils.py", line 18, in <lambda>
        setattr(resolved_obj, func_path[-1], lambda *args, **kwargs: self(*args, **kwargs))
      File "A:\Stupid Folder\stable-diffusion-webui-directml\modules\sd_hijack_utils.py", line 32, in __call__
        return self.__orig_func(*args, **kwargs)
      File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
        return func(*args, **kwargs)
      File "A:\Stupid Folder\stable-diffusion-webui-directml\repositories\stable-diffusion-stability-ai\ldm\models\diffusion\ddpm.py", line 826, in decode_first_stage
        return self.first_stage_model.decode(z)
      File "A:\Stupid Folder\stable-diffusion-webui-directml\repositories\stable-diffusion-stability-ai\ldm\models\autoencoder.py", line 90, in decode
        dec = self.decoder(z)
      File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
        return forward_call(*args, **kwargs)
      File "A:\Stupid Folder\stable-diffusion-webui-directml\repositories\stable-diffusion-stability-ai\ldm\modules\diffusionmodules\model.py", line 631, in forward
        h = self.mid.attn_1(h)
      File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
        return forward_call(*args, **kwargs)
      File "A:\Stupid Folder\stable-diffusion-webui-directml\repositories\stable-diffusion-stability-ai\ldm\modules\diffusionmodules\model.py", line 258, in forward
        out = xformers.ops.memory_efficient_attention(q, k, v, attn_bias=None, op=self.attention_op)
      File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\xformers\ops\fmha\__init__.py", line 223, in memory_efficient_attention
        return _memory_efficient_attention(
      File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\xformers\ops\fmha\__init__.py", line 321, in _memory_efficient_attention
        return _memory_efficient_attention_forward(
      File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\xformers\ops\fmha\__init__.py", line 337, in _memory_efficient_attention_forward
        op = _dispatch_fw(inp, False)
      File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\xformers\ops\fmha\dispatch.py", line 120, in _dispatch_fw
        return _run_priority_list(
      File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\xformers\ops\fmha\dispatch.py", line 63, in _run_priority_list
        raise NotImplementedError(msg)
    NotImplementedError: No operator found for `memory_efficient_attention_forward` with inputs:
         query       : shape=(1, 4096, 1, 512) (torch.float32)
         key         : shape=(1, 4096, 1, 512) (torch.float32)
         value       : shape=(1, 4096, 1, 512) (torch.float32)
         attn_bias   : <class 'NoneType'>
         p           : 0.0
    `decoderF` is not supported because:
        max(query.shape[-1] != value.shape[-1]) > 128
        device=privateuseone (supported: {'cuda'})
        attn_bias type is <class 'NoneType'>
        operator wasn't built - see `python -m xformers.info` for more info
    `flshattF@0.0.0` is not supported because:
        max(query.shape[-1] != value.shape[-1]) > 256
        device=privateuseone (supported: {'cuda'})
        dtype=torch.float32 (supported: {torch.float16, torch.bfloat16})
        operator wasn't built - see `python -m xformers.info` for more info
    `tritonflashattF` is not supported because:
        max(query.shape[-1] != value.shape[-1]) > 128
        device=privateuseone (supported: {'cuda'})
        dtype=torch.float32 (supported: {torch.float16, torch.bfloat16})
        operator wasn't built - see `python -m xformers.info` for more info
        triton is not available
    `cutlassF` is not supported because:
        device=privateuseone (supported: {'cuda'})
        operator wasn't built - see `python -m xformers.info` for more info
    `smallkF` is not supported because:
        max(query.shape[-1] != value.shape[-1]) > 32
        device=privateuseone (supported: {'cuda'})
        operator wasn't built - see `python -m xformers.info` for more info
        unsupported embed per head: 512

---

Additional information

using command line args --skip-torch-cuda-test --use-directml --no-half --precision full --xformers

lshqqytiger commented 5 months ago

xformers only supports CUDA-enabled platform. Remove --xformers.

patritha commented 5 months ago

without the flag it complains about not having it should i fresh install?

venv "A:\Stupid Folder\stable-diffusion-webui-directml\venv\Scripts\Python.exe"
fatal: detected dubious ownership in repository at 'A:/Stupid Folder/stable-diffusion-webui-directml'
'A:/Stupid Folder/stable-diffusion-webui-directml' is owned by:
        BUILTIN/Administrators (S-1-5-32-544)
but the current user is:
        DESKTOP-J5427GK/gabe (S-1-5-21-786191698-4050043721-1864713261-1001)
To add an exception for this directory, call:

        git config --global --add safe.directory 'A:/Stupid Folder/stable-diffusion-webui-directml'
fatal: detected dubious ownership in repository at 'A:/Stupid Folder/stable-diffusion-webui-directml'
'A:/Stupid Folder/stable-diffusion-webui-directml' is owned by:
        BUILTIN/Administrators (S-1-5-32-544)
but the current user is:
        DESKTOP-J5427GK/gabe (S-1-5-21-786191698-4050043721-1864713261-1001)
To add an exception for this directory, call:

        git config --global --add safe.directory 'A:/Stupid Folder/stable-diffusion-webui-directml'
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Version: 1.9.0
Commit hash: <none>
WARNING:xformers:WARNING[XFORMERS]: xFormers can't load C++/CUDA extensions. xFormers was built for:
    PyTorch 2.1.2+cu121 with CUDA 1201 (you have 2.0.0+cpu)
    Python  3.10.11 (you have 3.10.6)
  Please reinstall xformers (see https://github.com/facebookresearch/xformers#installing-xformers)
  Memory-efficient attention, SwiGLU, sparse and more won't be available.
  Set XFORMERS_MORE_DETAILS=1 for more details
A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\pytorch_lightning\utilities\distributed.py:258: LightningDeprecationWarning: `pytorch_lightning.utilities.distributed.rank_zero_only` has been deprecated in v1.8.1 and will be removed in v2.0.0. You can import it from `pytorch_lightning.utilities` instead.
  rank_zero_deprecation(
Launching Web UI with arguments: --skip-torch-cuda-test --use-directml --no-half --precision full
Traceback (most recent call last):
  File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\diffusers\utils\import_utils.py", line 718, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
  File "C:\Users\gabe\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\diffusers\models\autoencoders\__init__.py", line 1, in <module>
    from .autoencoder_asym_kl import AsymmetricAutoencoderKL
  File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\diffusers\models\autoencoders\autoencoder_asym_kl.py", line 23, in <module>
    from .vae import DecoderOutput, DiagonalGaussianDistribution, Encoder, MaskConditionDecoder
  File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\diffusers\models\autoencoders\vae.py", line 24, in <module>
    from ..attention_processor import SpatialNorm
  File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\diffusers\models\attention_processor.py", line 33, in <module>
    import xformers
ModuleNotFoundError: import of xformers halted; None in sys.modules

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\diffusers\utils\import_utils.py", line 718, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
  File "C:\Users\gabe\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\diffusers\pipelines\pipeline_utils.py", line 44, in <module>
    from ..models import AutoencoderKL
  File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist
  File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\diffusers\utils\import_utils.py", line 708, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\diffusers\utils\import_utils.py", line 720, in _get_module
    raise RuntimeError(
RuntimeError: Failed to import diffusers.models.autoencoders.autoencoder_kl because of the following error (look up to see its traceback):
import of xformers halted; None in sys.modules

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "A:\Stupid Folder\stable-diffusion-webui-directml\launch.py", line 48, in <module>
    main()
  File "A:\Stupid Folder\stable-diffusion-webui-directml\launch.py", line 44, in main
    start()
  File "A:\Stupid Folder\stable-diffusion-webui-directml\modules\launch_utils.py", line 696, in start
    import webui
  File "A:\Stupid Folder\stable-diffusion-webui-directml\webui.py", line 13, in <module>
    initialize.imports()
  File "A:\Stupid Folder\stable-diffusion-webui-directml\modules\initialize.py", line 36, in imports
    shared_init.initialize()
  File "A:\Stupid Folder\stable-diffusion-webui-directml\modules\shared_init.py", line 62, in initialize
    initialize_onnx()
  File "A:\Stupid Folder\stable-diffusion-webui-directml\modules\onnx_impl\__init__.py", line 232, in initialize
    from .pipelines.onnx_stable_diffusion_pipeline import OnnxStableDiffusionPipeline
  File "A:\Stupid Folder\stable-diffusion-webui-directml\modules\onnx_impl\pipelines\__init__.py", line 19, in <module>
    from modules.onnx_impl.utils import extract_device, move_inference_session, check_diffusers_cache, check_pipeline_sdxl, check_cache_onnx, load_init_dict, load_submodel, load_submodels, patch_kwargs, load_pipeline, get_base_constructor, get_io_config
  File "A:\Stupid Folder\stable-diffusion-webui-directml\modules\onnx_impl\utils.py", line 45, in <module>
    def check_pipeline_sdxl(cls: Type[diffusers.DiffusionPipeline]) -> bool:
  File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\diffusers\utils\import_utils.py", line 709, in __getattr__
    value = getattr(module, name)
  File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\diffusers\utils\import_utils.py", line 708, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "A:\Stupid Folder\stable-diffusion-webui-directml\venv\lib\site-packages\diffusers\utils\import_utils.py", line 720, 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):
import of xformers halted; None in sys.modules
Press any key to continue . . .
patritha commented 5 months ago

yeah a fresh install runs but it throws RuntimeError: mat1 and mat2 must have the same dtype

lshqqytiger commented 5 months ago

What gpu are you using?

patritha commented 5 months ago

amd radeon 7900XTX

lshqqytiger commented 5 months ago

Why are you trying DirectML? ZLUDA is much better on RX 7900 XTX. You don't have to add --no-half --precision full that slows down the generation on ZLUDA. You can follow a guide of vladmandic/automatic.

patritha commented 5 months ago

i didnt even know that existed, thanks! i will now close this issue