底辺SE奮闘記

年収300万SEブログ

【AUTOMATIC1111 / stable-diffusion-webui】Intel MacでのHandRefiner時エラーを無理やり修正

現象

Intel MacでStableDiffusionWebUIのHandRefinerを実行しようすると下記エラーが発生し、手の修正が行われない。

NotImplementedError: Could not run 'aten::empty.memory_format' with arguments from the 'SparseMPS' backend. This could be because the operator doesn't exist for this backend, or was omitted during the selective/custom build process (if using custom build).

注意 Attention

正当な方法はおそらくWebUIおよびControlNetのバージョンアップです。

ControlNetの最新のリポジトリを確認すると、下記コードと違うようでしたのでたぶん修正されているのではないでしょうか(確認していません)。バージョンアップで様子見するのがおそらく一番良いです。

下記修正を採用される際は自己責任でお願いします。

なお、下記修正はControlNet内のコードを直接編集するため、ControlNetのバージョンアップをするとリセットされます。

環境

スペック
ハード MacBook Pro 16-inch 2019
CPU 2.6 GHz 6コアIntel Core i7
グラフィック AMD Radeon Pro 5300M 4 GB Intel UHD Graphics 630 1536 MB
メモリ 16 GB 2667 MHz DDR4
OS macOS Ventura 13.3.1
Python 3.10.8
Stable Difussion WebUI v1.6.0
sd-webui-controlnet 更新日:2024-01-29 08:15:41

修正

extensions/sd-webui-controlnet/scripts/processor.pyの835行目付近HandRefinerModelクラスのinitメソッドを下記のように修正します。

class HandRefinerModel:
    def __init__(self):
        self.model = None
        self.device = devices.get_device_for("controlnet")
        # 下記を追記
        if self.device.type == "mps" :
            self.device = torch.device("cpu")

    # __init__ ここまで
    def load_model(self):
        # 後続のコード...