User Tools

Site Tools


stable-diffusion

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
stable-diffusion [2025/02/21 00:03] – [Prerequisites] jianwustable-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 84: 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 Bash>+<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 Bash>+<code Dos>
 C:\Users\%USERNAME%\anaconda3\envs C:\Users\%USERNAME%\anaconda3\envs
 </code> </code>
  
 activate env activate env
-<code Bash>+<code Dos>
 E:\> conda activate webui_env E:\> conda activate webui_env
 </code> </code>
 for reference for reference
-<code Bash>+<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 133: Line 123:
 and maybe followings are needed. and maybe followings are needed.
 <code Bash> <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 143: Line 133:
 === installing stablediffusion === === installing stablediffusion ===
 installing stablediffusion using requirements.txt installing stablediffusion using requirements.txt
-<code Bash>+<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 151: Line 141:
 </code> </code>
  
-<note important> + 
-[IMPORTANT]\\ +:!: if you got following error 
-if you got following error +
       ...       ...
       running build_rust       running build_rust
Line 160: 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 171: Line 159:
  
 and execute following command and execute following command
-<code Bash>+<code Dos>
 (webui_env) E:\stable_diffusion\stablediffusion> conda install cudatoolkit (webui_env) E:\stable_diffusion\stablediffusion> conda install cudatoolkit
 </code> </code>
Line 190: Line 178:
  
 It says It says
-<code Bash+<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,
Line 197: Line 185:
 (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 Bash>+
 (webui_env) E:\stable_diffusion\stablediffusion> python (webui_env) E:\stable_diffusion\stablediffusion> python
 >>> import torch >>> import torch
Line 213: Line 196:
 </code> </code>
 for reference for reference
-<code Bash>+<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 224: 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 Bash>+
 (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 234: Line 215:
  
 === Installing diffusers === === Installing diffusers ===
-<code Bash>+<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 252: 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 Bash>+<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 Bash>+<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 273: Line 251:
 [[https://github.com/AUTOMATIC1111/stable-diffusion-webui|stable-diffusion-webui]] [[https://github.com/AUTOMATIC1111/stable-diffusion-webui|stable-diffusion-webui]]
  
-<code Bash>+<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 283: Line 261:
  
 ''webui-user.bat'': ''webui-user.bat'':
-<code Bash>+<code Dos>
 @echo off @echo off
  
Line 294: 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 Bash>+<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 311: Line 286:
  
 for reference for reference
-<code Bash>+<code Dos>
 (webui_env) E:\webui\stable-diffusion-webui>python (webui_env) E:\webui\stable-diffusion-webui>python
 >>> import torch >>> import torch
Line 320: Line 295:
 >>> exit() >>> exit()
 </code> </code>
-<code Bash>+<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 333: Line 308:
  
 followings are checked by programs followings are checked by programs
-<code Bash>+<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 341: Line 316:
 </code> </code>
 maybe not correnponding maybe not correnponding
-<code Bash>+<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 363: 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 373: 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 Bash>+<code Dos>
 stable-diffusion-webui\venv stable-diffusion-webui\venv
 </code> </code>
stable-diffusion.1740063835.txt.gz · Last modified: 2025/02/21 00:03 by jianwu