0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

高火力 DOKの「ノートブック」機能を使ってStable Diffusion WebUIをngrokで接続する

Posted at

はじめに

Stable Diffusion WebUI(AUTOMATIC1111)を高火力 DOKの「ノートブック」機能を利用し、ngrokを使って接続できるようにするメモです。

今回は高火力 DOKを使用します。
高火力 DOKは、さくらインターネットが提供するコンテナ型GPUサービスです。
https://www.sakura.ad.jp/koukaryoku-dok/

この記事は「高火力 DOK+Jupyter NotebookでStable Diffusion WebUIをngrokで接続する」の「ノートブック」機能バージョンです。
一部、無理やりな部分もありますので、元記事とあわせてご覧いただくのがおすすめです👇

前提

ngrokのトークンを取得

ngrokを利用するには、トークンが必要です。以下の手順で取得します。

https://dashboard.ngrok.com/ にアクセスし、サイドバーのYour Authtokenを選択します。
中央にあるYour Authtokenをメモしておきましょう。
ngrok token.png

高火力DOK

「ノートブック」の起動

ノートブックの利用方法を参考にノートブック(JupyterLab)を起動し外部から接続できるようにします。

高火力 DOKのダッシュボードにアクセスし、
サイドバーから「ノートブック」を選択したのち「起動」を選択します。
dok tasks.png

「起動」を選択し、JupyterLabが起動するまで待ちます。

「開く」を選択するとJupyterLabにアクセスできます。
※起動するまで3分程度かかる場合があるようです。
jupyterlab open.png

Jupyter NotebookにアクセスできたらNotebookのPython 3(ipykernel)を選択します
dok notebook.png

Stable Diffusion WebUIの起動

以下コードを順番に実行します。

  • stable-diffusion-webuiをgitからDL
!git clone --depth 1 https://github.com/AUTOMATIC1111/stable-diffusion-webui
  • ディレクトリの移動と成果物保存場所の変更
%cd stable-diffusion-webui
!ln -vs /opt/artifact ./outputs

スクリーンショット 2025-02-06 22.52.36.png

  • 必要なパッケージのインストール
    issue: #16445
    ※結構時間かかりますが、気長に待ちまs
!curl https://sh.rustup.rs -sSf | sh -s -- -y
!~/.cargo/bin/rustup install 1.81.0
!~/.cargo/bin/rustup install 1.71.1

!conda install -y -c conda-forge pkg-config openssl

!export PATH="$HOME/.cargo/bin:$PATH" && RUSTUP_TOOLCHAIN=1.71.1 pip3 install -v transformers==4.15.0 timm==0.4.12 fairscale==0.4.4
!export PATH="$HOME/.cargo/bin:$PATH" && RUSTFLAGS='-A invalid_reference_casting' RUSTUP_TOOLCHAIN=1.81.0 pip3 install -r requirements.txt
  • 暫定的な修正①
    issue:#11458
!git clone https://github.com/Stability-AI/stablediffusion.git repositories/stable-diffusion-stability-ai \
  && cd repositories/stable-diffusion-stability-ai \
  && git checkout cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf
!sed -i 's|pytorch_lightning\.utilities\.distributed|pytorch_lightning.utilities.rank_zero|g' repositories/stable-diffusion-stability-ai/ldm/models/diffusion/ddpm.py extensions-builtin/LDSR/sd_hijack_ddpm_v1.py
  • 暫定的な修正②
    issue:#11853
!/opt/conda/bin/python -m pip install "pydantic<2"

以下のconflictsエラーが発生しますが、今回は無視します
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. jupyterhub 5.2.1 requires pydantic>=2, but you have pydantic 1.10.21 which is incompatible.

  • stable-diffusion-webuiを起動
!COMMANDLINE_ARGS="--ngrok (ngrokで取得したトークン) --ngrok-region jp" REQS_FILE="requirements.txt" python launch.py --skip-python-version-check

起動すると
ngrok connected to localhost:7860! URL: https://xxxx.ngrok-free.app
と表示されるので、モデルのダウンロードが完了したらURLをクリックします。
dok ngrok.png

URLに飛んだら「Visit site」をクリックします。
dok visit.png

Stable Diffusion WebUIが開きます Yatta!!!
dok web ui.png

終わるとき

停止を忘れると従量課金されていくので忘れずに停止しましょう

高火力 DOKのダッシュボードにアクセスし、
サイドバーから「ノートブック」を選択したのち、「終了」を選択します。

ポップアップにて「終了」を選択します。

成果物について

生成した画像などの成果物は高火力 DOKのダッシュボードからダウンロードすることもできます。(期限付き)
dok artifact.png

まとめ

この記事では、高火力 DOKの「ノートブック」機能を使ってStable Diffusion WebUIをngrokで接続する手順を説明しました。

ここまで読んでいただきありがとうございました

参考文献

高火力 DOK ドキュメント

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?