2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AMD GPU Mac で stable-diffusion-webui

Last updated at Posted at 2022-09-15

概要

Macでmpsを使ってstable-diffusion-webuiを動かせたのでメモ

環境

手順

weightの配置

wikiにはStable Diffusionのweightの配置場所はin the base directoryと書いてあったが、デフォルトだとrepositories/stable-diffusion/models/ldm/stable-diffusion-v1/model.ckptを参照するようだ。
別の場所に置いている場合やwaifu版など別のを使いたい場合は実行時の--ckptオプションで指定すればよいだろう。

仮想環境を用意

conda create -n sdw python=3.8.5
conda activate sdw
conda install pytorch torchvision -c pytorch-nightly

CUDA向けのコード等を書き換える

  1. launch.py

    -run_python("import torch; assert torch.cuda.is_available(), 'Torch is not able to use GPU'")
    
  2. repositories/CodeFormer/facelib/detection/yolov5face/face_detector.py

    -IS_HIGH_VERSION = tuple(map(int, torch.__version__.split('+')[0].split('.'))) >= (1, 9, 0)
    +IS_HIGH_VERSION = True
    
  3. repositories/stable-diffusion/ldm/models/diffusion/plms.py

    -            if attr.device != torch.device("cuda"):
    -                attr = attr.to(torch.device("cuda"))
    +            if attr.device != torch.device("mps"):
    +                attr = attr.to(torch.float32).to(torch.device("mps")).contiguous()
    

実行

PYTORCH_ENABLE_MPS_FALLBACK=1 python launch.py --precision full --no-half 

Sampling methodによってはうまくいかないようだ。全て試してはいないが、PLMSは安定している。

実行中の様子

一応GPUを使えているようだ。
スクリーンショット 2022-09-15 23.51.11.png

参考

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?