Stable Diffusion の最も重要な側面のひとつはオープンソース性です。コードとモデル重みが公開されており、必要なハードウェアがあれば自分のコンピュータで実行できます。この高いアクセス性は、多くのプロプライエタリな AI 画像生成サービスと一線を画しており、広く普及した大きな理由となっています。ローカルでモデルを実行できることにより、オンラインプラットフォームにありがちなコンテンツ制限や利用料金に縛られることなく、創作の自由と作業の完全なコントロールを得られます。
OS: 上級ユーザーには Linux(Ubuntu 系)が便利。GUI パッケージは Windows 10/11 で完全サポート。サーバー用途には Docker が機能します。
Software prerequisites
Python 3.10+ または Conda 環境。
GPU を使う場合は CUDA Toolkit/NVIDIA ドライバと一致する PyTorch ホイール(CPU のみも可能ですが非常に遅い)。
Git、Git LFS(一部モデルのダウンロードに必要)、および必要に応じて Hugging Face アカウント(ライセンス同意が必要なモデルのダウンロード用)。
Important—license & safety: 多くの Stable Diffusion のチェックポイントは Stability AI のコミュニティライセンスまたは個別のモデルライセンスの下で提供され、ダウンロード前の同意が必要です。Hugging Face にホストされたモデルは、Hugging Face アカウントへのログインと明示的な同意を要求することが多く、承認なしの自動ダウンロードは失敗します。
How Do I Install Stable Diffusion (Step-by-Step Guide)?
以下に 3 つの実用的なインストール経路を示します。用途に合うものを選んでください。
Path A — Full GUI: AUTOMATIC1111 Stable Diffusion WebUI(対話的な利用に最適、コミュニティ製プラグイン多数)。
Path B — Programmatic: Hugging Face diffusers パイプライン(統合やスクリプト化に最適)。
Path C — Cloud / Docker: ローカル GPU がない場合はクラウド VM またはコンテナを使用。
How Do I Download Model Weights and Accept Licenses?
Stable Diffusion のモデル重みは次の方法で配布されています。
Official Stability AI releases — Stability は中核モデルを公開し、主要リリース(3.x、SDXL など)を告知します。これらのモデルは Stability のサイトや Hugging Face から入手できることが多いです。
Hugging Face model cards — 多くの公式・コミュニティのチェックポイントが Hugging Face にホストされています。公開されている SD のチェックポイントの多くは、ダウンロード前にログインとライセンス同意が必要です。diffusers API はこのフローに対応しています。
Community hubs (Civitai, GitHub, etc.) — コミュニティ製のチェックポイント、埋め込み、LoRA などが配布されています。各アセットのライセンスを確認してください。
# clone the WebUI
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
cd stable-diffusion-webui
# On Windows, the provided batch scripts will handle dependencies.
# Use the following to fetch everything and launch:
.\webui-user.bat
# or, in older releases:
# .\run.bat
スクリプトが Python パッケージをインストールし、必要なコンポーネントをダウンロードして、既定で http://127.0.0.1:7860 に Web UI を開きます。プロジェクトからモデルファイルを要求された場合は、後述のモデルダウンロード手順を参照してください。
3) Clone and launch (Linux)
推奨: virtualenv か conda 環境を作成。
# system prerequisites: Python3, git, wget (example: Ubuntu)
sudo apt update && sudo apt install -y git python3-venv
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
cd stable-diffusion-webui
# Create a venv and activate
python3 -m venv venv
source venv/bin/activate
# Launch (the launcher will install requirements)
python launch.py
Linux では GPU 加速のために、起動前に適切な CUDA 対応の PyTorch をインストールする必要がある場合がよくあります。
Where to place model weights: モデルの .ckpt、.safetensors、または SDXL のファイルを models/Stable-diffusion/ に配置します(必要に応じてフォルダを作成)。WebUI は重みを自動検出します。
How Do I Install Stable Diffusion with Hugging Face Diffusers ?
python -m venv sdenv
source sdenv/bin/activate
pip install --upgrade pip
# Core packages (example - adjust CUDA wheel for your system per PyTorch's site)
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118
pip install diffusers transformers accelerate safetensors transformers[torch] huggingface-hub
Tip: 公式の PyTorch インストールページを使って、お使いの CUDA バージョンに合った PyTorch ホイールをインストールしてください。diffusers のドキュメントに互換パッケージの組み合わせが記載されています。
2) Authenticate and download models (Hugging Face)
Hugging Face 上の多くの Stable Diffusion チェックポイントは、ログインとライセンス同意が必要です。ターミナルで:
pip install huggingface_hub
huggingface-cli login
# you will be prompted to paste your token (get it from your Hugging Face account settings)
プログラムからモデルを読み込む例(Hugging Face にホストされたチェックポイント):
from diffusers import StableDiffusionPipeline
import torch
model_id = "stabilityai/stable-diffusion-3-5" # example; replace with the model you agreed to
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, use_safetensors=True)
pipe = pipe.to("cuda")
image = pipe("A professional photograph of a mountain at sunrise", num_inference_steps=25).images[0]
image.save("output.png")
# pull a community image (verify authenticity before use)
docker pull automatic1111/stable-diffusion-webui:latest
# run (bind port 7860)
docker run --gpus all -p 7860:7860 -v /local/models:/data/models automatic1111/stable-diffusion-webui:latest
クラウド事業者は時間課金が一般的です。プロダクションやチーム利用では、Hugging Face Inference Endpoints や Stability の API などのマネージドサービスを検討するとよいでしょう。有償ですが運用負荷を低減できます。
Troubleshooting and Performance Tips
Common issues
Installation fails on torch or CUDA mismatch. PyTorch ホイールがシステムの CUDA(ドライバ)バージョンと一致しているか確認してください。公式の PyTorch インストーラで正しい pip コマンドを生成しましょう。
Model download blocked / 403. Hugging Face にログインし、モデルライセンスに同意したか確認してください。一部モデルは Git LFS が必要です。
OOM (out of memory). 生成解像度を下げる、半精度(torch_dtype=torch.float16)に切り替える、または WebUI で xformers/省メモリアテンションを有効化します。
Performance tuning
xformers(対応している場合)を導入して省メモリなアテンションを有効化。
安定性に応じて --precision full と --precision fp16 のフラグを使い分ける。