Skip to content

[Bug]: Setting device to mps does not work #361

@s4m13337

Description

@s4m13337

fastsdcpu Version

cd60fd3

Bug Description

I set export DEVICE=mps and star the application, but it gives the following error:

  warnings.warn(
FastSD CPU -  v1.0.0 beta 281
Running on Darwin platform
OS: macOS-14.8.3-arm64-arm-64bit
Processor: arm
Using device : mps
Output path : /Users/s4m13337/Developer/fastsdcpu/results
Found 6 LCM models in config/lcm-models.txt
Found 7 stable diffusion models in config/stable-diffusion-models.txt
Found 4 LCM-LoRA models in config/lcm-lora-models.txt
Found 10 OpenVINO LCM models in config/openvino-lcm-models.txt
/Users/s4m13337/Developer/fastsdcpu/env/lib/python3.11/site-packages/controlnet_aux/segment_anything/modeling/tiny_vit_sam.py:654: UserWarning: Overwriting tiny_vit_5m_224 in registry with controlnet_aux.segment_anything.modeling.tiny_vit_sam.tiny_vit_5m_224. This is because the name being registered conflicts with an existing name. Please check if this is not expected.
  return register_model(fn_wrapper)
/Users/s4m13337/Developer/fastsdcpu/env/lib/python3.11/site-packages/controlnet_aux/segment_anything/modeling/tiny_vit_sam.py:654: UserWarning: Overwriting tiny_vit_11m_224 in registry with controlnet_aux.segment_anything.modeling.tiny_vit_sam.tiny_vit_11m_224. This is because the name being registered conflicts with an existing name. Please check if this is not expected.
  return register_model(fn_wrapper)
/Users/s4m13337/Developer/fastsdcpu/env/lib/python3.11/site-packages/controlnet_aux/segment_anything/modeling/tiny_vit_sam.py:654: UserWarning: Overwriting tiny_vit_21m_224 in registry with controlnet_aux.segment_anything.modeling.tiny_vit_sam.tiny_vit_21m_224. This is because the name being registered conflicts with an existing name. Please check if this is not expected.
  return register_model(fn_wrapper)
/Users/s4m13337/Developer/fastsdcpu/env/lib/python3.11/site-packages/controlnet_aux/segment_anything/modeling/tiny_vit_sam.py:654: UserWarning: Overwriting tiny_vit_21m_384 in registry with controlnet_aux.segment_anything.modeling.tiny_vit_sam.tiny_vit_21m_384. This is because the name being registered conflicts with an existing name. Please check if this is not expected.
  return register_model(fn_wrapper)
/Users/s4m13337/Developer/fastsdcpu/env/lib/python3.11/site-packages/controlnet_aux/segment_anything/modeling/tiny_vit_sam.py:654: UserWarning: Overwriting tiny_vit_21m_512 in registry with controlnet_aux.segment_anything.modeling.tiny_vit_sam.tiny_vit_21m_512. This is because the name being registered conflicts with an existing name. Please check if this is not expected.
  return register_model(fn_wrapper)
Starting web UI mode
Traceback (most recent call last):
  File "/Users/s4m13337/Developer/fastsdcpu/src/app.py", line 317, in <module>
    start_webui(
  File "/Users/s4m13337/Developer/fastsdcpu/src/frontend/webui/ui.py", line 103, in start_webui
    webui = get_web_ui()
            ^^^^^^^^^^^^
  File "/Users/s4m13337/Developer/fastsdcpu/src/frontend/webui/ui.py", line 58, in get_web_ui
    f"**Processor :  {get_device_name()}**",
                      ^^^^^^^^^^^^^^^^^
  File "/Users/s4m13337/Developer/fastsdcpu/src/backend/device.py", line 18, in get_device_name
    default_gpu_index = torch.cuda.current_device()
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/s4m13337/Developer/fastsdcpu/env/lib/python3.11/site-packages/torch/cuda/__init__.py", line 1071, in current_device
    _lazy_init()
  File "/Users/s4m13337/Developer/fastsdcpu/env/lib/python3.11/site-packages/torch/cuda/__init__.py", line 403, in _lazy_init
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled
/Users/s4m13337/Developer/fastsdcpu/env/lib/python3.11/site-packages/torch/onnx/_internal/registration.py:162: OnnxExporterWarning: Symbolic function 'aten::scaled_dot_product_attention' already registered for opset 14. Replacing the existing function with new function. This is unexpected. Please report it on https://github.com/pytorch/pytorch/issues.
  warnings.warn(
/Users/s4m13337/Developer/fastsdcpu/env/lib/python3.11/site-packages/openvino/runtime/__init__.py:10: DeprecationWarning: The `openvino.runtime` module is deprecated and will be removed in the 2026.0 release. Please replace `openvino.runtime` with `openvino`.
  warnings.warn(

I traced the error to the file that was causing this and hardcoded device as mps but then got this error:

Error in generating images: Placeholder storage has not been allocated on MPS device!
Traceback (most recent call last):
  File "/Users/s4m13337/Developer/fastsdcpu/src/context.py", line 62, in generate_text_to_image
    images = self.lcm_text_to_image.generate(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/s4m13337/Developer/fastsdcpu/src/backend/lcm_text_to_image.py", line 607, in generate
    result_images = self.pipeline(
                    ^^^^^^^^^^^^^^
  File "/Users/s4m13337/Developer/fastsdcpu/env/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 120, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/s4m13337/Developer/fastsdcpu/env/lib/python3.11/site-packages/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py", line 998, in __call__
    latents = self.prepare_latents(
              ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/s4m13337/Developer/fastsdcpu/env/lib/python3.11/site-packages/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py", line 708, in prepare_latents
    latents = randn_tensor(shape, generator=generator, device=device, dtype=dtype)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/s4m13337/Developer/fastsdcpu/env/lib/python3.11/site-packages/diffusers/utils/torch_utils.py", line 81, in randn_tensor
    latents = torch.randn(shape, generator=generator, device=rand_device, dtype=dtype, layout=layout).to(device)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Placeholder storage has not been allocated on MPS device!

How can this be resolved?

Steps to Reproduce

  1. Run export DEVICE=mps
  2. Start the script with ./start-webui.sh
  3. See error

Expected Behavior

It is supposed to run faster with mps device

Logs / Error Output

Operating System

MacOS 14

Hardware / CPU

Apple M1

Checklist

  • I searched existing issues
  • I am using a supported environment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions