User Tools

Site Tools


stable-diffusion

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
stable-diffusion [2025/02/20 23:58] – created - external edit 127.0.0.1stable-diffusion [2025/02/25 05:09] (current) jianwu
Line 1: Line 1:
-{{navi>navigationmenu}} +[[https://pctresearch.com/|{{:banner_image.jpg?nolink&800|}}]]
-<HTML> +
-<style> +
-  .dokuwiki { +
-    font-size1.200em;  /*it was 0.875 in design.less*/ +
-} +
-</style> +
-</HTML>+
  
 ====== Stable Diffusion Version 2 - Run locally. Abandon if this doesn't work. ====== ====== Stable Diffusion Version 2 - Run locally. Abandon if this doesn't work. ======
Line 40: Line 33:
  
 === git === === git ===
 +<code HTML5>
 <HTML> <HTML>
 <table> <table>
Line 62: Line 56:
 </table> </table>
 </HTML> </HTML>
 +</code>
 === python3.10.6 === === python3.10.6 ===
  
Line 69: Line 63:
 [[https://www.python.org/|python.org]] [[https://www.python.org/|python.org]]
  
-<note important> +:!: python3.10.6 was recommended, nevertheless 2023/09/03 Operation has been confirmed in python3.11.4
-[IMPORTANT]\\ +
-python3.10.6 was recommended, +
-nevertheless 2023/09/03 Operation has been confirmed in python3.11.4 +
-</note>+
  
 [[python-installation|Python Installation]] [[python-installation|Python Installation]]
Line 87: Line 77:
 Make conda environment for stable diffusion Make conda environment for stable diffusion
  
-<note important> +:!: to activate conda environment, you must use ''Anaconda Prompt''.
-[IMPORTANT]\\ +
-to activate conda environment, you must use ''Anaconda Prompt''. +
-</note>+
  
 Here we use environment name ''webui_env''. Here we use environment name ''webui_env''.
-<code>+<code Dos>
 E:\> conda create --name webui_env python==3.10.6 E:\> conda create --name webui_env python==3.10.6
 </code> </code>
 Location of envs are Location of envs are
-<code>+<code Dos>
 C:\Users\%USERNAME%\anaconda3\envs C:\Users\%USERNAME%\anaconda3\envs
 </code> </code>
  
 activate env activate env
-<code>+<code Dos>
 E:\> conda activate webui_env E:\> conda activate webui_env
 </code> </code>
 for reference for reference
-<code>+<code Dos>
 (webui_env) E:> conda list (webui_env) E:> conda list
 # packages in environment at C:\Users\kan\anaconda3\envs\webui_env: # packages in environment at C:\Users\kan\anaconda3\envs\webui_env:
Line 135: Line 122:
 </code> </code>
 and maybe followings are needed. and maybe followings are needed.
-<code> +<code Bash
-conda config --append channels conda-forge +conda config --append channels conda-forge 
-conda config --append channels nvidia+conda config --append channels nvidia
 </code> </code>
  
Line 146: Line 133:
 === installing stablediffusion === === installing stablediffusion ===
 installing stablediffusion using requirements.txt installing stablediffusion using requirements.txt
-<code>+<code Dos>
 (webui_env) E:\> mkdir stable_diffusion (webui_env) E:\> mkdir stable_diffusion
 (webui_env) E:\> cd stable_diffusion (webui_env) E:\> cd stable_diffusion
Line 154: Line 141:
 </code> </code>
  
-<note important> + 
-[IMPORTANT]\\ +:!: if you got following error 
-if you got following error +
       ...       ...
       running build_rust       running build_rust
Line 163: Line 149:
 You need to Install Rust from You need to Install Rust from
 [[https://www.rust-lang.org/tools/install|rust-lang.org]] [[https://www.rust-lang.org/tools/install|rust-lang.org]]
-</note> 
  
 === Installing NVIDIA CUDA Toolkit === === Installing NVIDIA CUDA Toolkit ===
Line 174: Line 159:
  
 and execute following command and execute following command
-<code>+<code Dos>
 (webui_env) E:\stable_diffusion\stablediffusion> conda install cudatoolkit (webui_env) E:\stable_diffusion\stablediffusion> conda install cudatoolkit
 </code> </code>
Line 193: Line 178:
  
 It says It says
-<code> +<code Dos
-pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu121+pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu121
 </code> </code>
 But we execute more precisely, But we execute more precisely,
-<code>+<code Bash>
 (webui_env) E:\stable_diffusion\stablediffusion> pip install --pre torch==2.1.0.dev20230817+cu121 torchvision==0.16.0.dev20230818+cu121 torchaudio==2.1.0.dev20230818+cu121 --index-url https://download.pytorch.org/whl/nightly/cu121 (webui_env) E:\stable_diffusion\stablediffusion> pip install --pre torch==2.1.0.dev20230817+cu121 torchvision==0.16.0.dev20230818+cu121 torchaudio==2.1.0.dev20230818+cu121 --index-url https://download.pytorch.org/whl/nightly/cu121
 </code> </code>
-<note important> +:!: This is one of the most important checkpoints. At this point torch.cuda should be available. Check it! 
-[IMPORTANT]\\ +<code Dos>
-This is one of the most important checkpoints.  +
-At this point torch.cuda should be available.  +
-Check it! +
-</note> +
-<code>+
 (webui_env) E:\stable_diffusion\stablediffusion> python (webui_env) E:\stable_diffusion\stablediffusion> python
 >>> import torch >>> import torch
Line 216: Line 196:
 </code> </code>
 for reference for reference
-<code>+<code Dos>
 (webui_env) E:\stable_diffusion\stablediffusion> conda list | findstr torch (webui_env) E:\stable_diffusion\stablediffusion> conda list | findstr torch
 open-clip-torch           2.7.0                    pypi_0    pypi open-clip-torch           2.7.0                    pypi_0    pypi
Line 227: Line 207:
  
 === Installing xFormers === === Installing xFormers ===
-<note> +:!: You don't need to do this, if you only use with webui. 
-You don't need to do this, if you only use with webui. +<code Dos>
-</note> +
-<code>+
 (webui_env) E:\stable_diffusion\stablediffusion> pip install git+https://github.com/facebookresearch/xformers (webui_env) E:\stable_diffusion\stablediffusion> pip install git+https://github.com/facebookresearch/xformers
 Successfully installed xformers-0.0.22+cfad52d.d2023090 Successfully installed xformers-0.0.22+cfad52d.d2023090
Line 237: Line 215:
  
 === Installing diffusers === === Installing diffusers ===
-<code>+<code Dos>
 (webui_env) E:\stable_diffusion\stablediffusion> pip install git+https://github.com/huggingface/transformers (webui_env) E:\stable_diffusion\stablediffusion> pip install git+https://github.com/huggingface/transformers
       Successfully uninstalled transformers-4.19.2       Successfully uninstalled transformers-4.19.2
Line 255: Line 233:
 download ''v2-1_768-ema-pruned.ckpt'' download ''v2-1_768-ema-pruned.ckpt''
 from [[https://huggingface.co/stabilityai/stable-diffusion-2-1/blob/main/v2-1_768-ema-pruned.ckpt|stabilityai/stable-diffusion-2-1]] from [[https://huggingface.co/stabilityai/stable-diffusion-2-1/blob/main/v2-1_768-ema-pruned.ckpt|stabilityai/stable-diffusion-2-1]]
-<code>+<code Dos>
 (webui_env) E:\stable_diffusion\stablediffusion> python scripts/txt2img.py --prompt "a professional photograph of an astronaut riding a horse" --ckpt "E:\difwork\SD2.1-v\v2-1_768-ema-pruned.ckpt" --config "E:\stable_diffusion\stablediffusion\configs\stable-diffusion\v2-inference-v.yaml" --H 768 --W 768 --device cuda (webui_env) E:\stable_diffusion\stablediffusion> python scripts/txt2img.py --prompt "a professional photograph of an astronaut riding a horse" --ckpt "E:\difwork\SD2.1-v\v2-1_768-ema-pruned.ckpt" --config "E:\stable_diffusion\stablediffusion\configs\stable-diffusion\v2-inference-v.yaml" --H 768 --W 768 --device cuda
 </code> </code>
-<note warning> +:!: txt2img.py makes 9 images. So it takes so much time and large memory. [[stable-diffusion#Out of memory|''Trouble shooting of Out of memory'']]. If you can't fix this error,skip this.
-[WARNING] +
-txt2img.py makes 9 images. So it takes so much time and large memory. [[stable-diffusion#Out of memory|''Trouble shooting of Out of memory'']]. If you can't fix this error,skip this. +
-</note>+
  
 === scripts/img2img.py === === scripts/img2img.py ===
  
 we need to download [[https://huggingface.co/stabilityai/stable-diffusion-2-1-base/blob/main/v2-1_512-ema-pruned.ckpt|SD2.1-base\v2-1_512-ema-pruned.ckpt]] we need to download [[https://huggingface.co/stabilityai/stable-diffusion-2-1-base/blob/main/v2-1_512-ema-pruned.ckpt|SD2.1-base\v2-1_512-ema-pruned.ckpt]]
-<code>+<code Dos>
 (webui_env) E:\stable_diffusion\stablediffusion> python scripts/img2img.py --prompt "To create a commentary on modern technology and classical art, use an art style like Pop Art that often addresses cultural themes. Clearly mention the juxtaposition of elements. Pop Art painting of a modern smartphone with classic art pieces appearing on the screen." --init-img "E:\difwork\SD2.1-base\sample.png" --strength 0.8 --ckpt "E:\difwork\SD2.1-base\v2-1_512-ema-pruned.ckpt" (webui_env) E:\stable_diffusion\stablediffusion> python scripts/img2img.py --prompt "To create a commentary on modern technology and classical art, use an art style like Pop Art that often addresses cultural themes. Clearly mention the juxtaposition of elements. Pop Art painting of a modern smartphone with classic art pieces appearing on the screen." --init-img "E:\difwork\SD2.1-base\sample.png" --strength 0.8 --ckpt "E:\difwork\SD2.1-base\v2-1_512-ema-pruned.ckpt"
 outputs/img2img-samples outputs/img2img-samples
Line 276: Line 251:
 [[https://github.com/AUTOMATIC1111/stable-diffusion-webui|stable-diffusion-webui]] [[https://github.com/AUTOMATIC1111/stable-diffusion-webui|stable-diffusion-webui]]
  
-<code>+<code Dos>
 (webui_env) E:\stable_diffusion\stablediffusion> cd .. (webui_env) E:\stable_diffusion\stablediffusion> cd ..
 (webui_env) E:\stable_diffusion> git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git (webui_env) E:\stable_diffusion> git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
Line 286: Line 261:
  
 ''webui-user.bat'': ''webui-user.bat'':
-<code>+<code Dos>
 @echo off @echo off
  
Line 297: Line 272:
 call webui.bat call webui.bat
 </code> </code>
-<note important> +:!: We need to install xformers for webui.And It should be 0.0.20 not 0.0.22 at current condition.
-[IMPORTANT] +
-We need to install xformers for webui.And It should be 0.0.20 not 0.0.22 at current condition. +
-</note>+
  
 then execute ''webui-user.bat'' then execute ''webui-user.bat''
-<code>+<code Dos>
 (webui_env) E:\stable_diffusion\stable-diffusion-webui> webui-user.bat (webui_env) E:\stable_diffusion\stable-diffusion-webui> webui-user.bat
               Running on local URL:  http://127.0.0.1:7860               Running on local URL:  http://127.0.0.1:7860
Line 314: Line 286:
  
 for reference for reference
-<code>+<code Dos>
 (webui_env) E:\webui\stable-diffusion-webui>python (webui_env) E:\webui\stable-diffusion-webui>python
 >>> import torch >>> import torch
Line 323: Line 295:
 >>> exit() >>> exit()
 </code> </code>
-<code>+<code Dos>
 (webui_env) E:\webui\stable-diffusion-webui>conda list | findstr torch (webui_env) E:\webui\stable-diffusion-webui>conda list | findstr torch
 open-clip-torch           2.7.0                    pypi_0    pypi open-clip-torch           2.7.0                    pypi_0    pypi
Line 336: Line 308:
  
 followings are checked by programs followings are checked by programs
-<code>+<code Dos>
 CUDA_HOME = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2 CUDA_HOME = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2
 CUDA_PATH = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8 CUDA_PATH = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8
Line 344: Line 316:
 </code> </code>
 maybe not correnponding maybe not correnponding
-<code>+<code Dos>
 CUDA_PATH_V11_8 = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8 CUDA_PATH_V11_8 = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8
 CUDA_PATH_V12_2 = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2 CUDA_PATH_V12_2 = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2
Line 354: Line 326:
  
 If you got error like following, If you got error like following,
-<code>+<code Bash>
 torch.cuda.OutOfMemoryError: CUDA out of memory. torch.cuda.OutOfMemoryError: CUDA out of memory.
 </code> </code>
 edit windows system environment variables edit windows system environment variables
-<code>+<code Bash>
 set PYTORCH_NO_CUDA_MEMORY_CACHING=1 set PYTORCH_NO_CUDA_MEMORY_CACHING=1
  
Line 366: Line 338:
 </code> </code>
  
-<note> +:!: About ''max_split_size_mb''
-About ''max_split_size_mb''+
  
 ''max_split_size_mb'' prevents the native allocator from splitting blocks larger than this size (in MB). ''max_split_size_mb'' prevents the native allocator from splitting blocks larger than this size (in MB).
Line 376: Line 347:
  
 That can ensure the feasibility of running large images while maximizing performance. That can ensure the feasibility of running large images while maximizing performance.
-</note> 
  
 ==== venv folder ==== ==== venv folder ====
  
 If you change some environments and use the same directory, you should delete the ''venv'' folder completely. If you change some environments and use the same directory, you should delete the ''venv'' folder completely.
-<code>+<code Dos>
 stable-diffusion-webui\venv stable-diffusion-webui\venv
 </code> </code>
stable-diffusion.1740063491.txt.gz · Last modified: 2025/02/20 23:58 by 127.0.0.1