Article directory
1. Environment construction
For convenience, here directly select the Ubuntu 22.04 system provided by Vultr with Anaconda installed.
If your own computer has enough video memory, you can also build it on your own computer, because my computer only has 2GB video memory and 8GB running memory, so it is not enough at all, so I choose to build on the cloud.
If you also want to build quickly, you can also choose to build on the cloud. Here I recommend two good GPU platforms that I know, one is AutoDL and the other is Vultr . Among them, AutoDL is domestic, it is relatively cheap, and the known minimum is 0.78/h, and there are many optional configurations. Of course, there are also disadvantages. The disadvantage is that the port cannot be opened. Although it is a root account, there are many restrictions. Vultr is a foreign supplier. Its cost is relatively expensive, but its advantage is its high degree of freedom.
Here's a demonstration using Vultr.
1.1, GPU server selection
We choose Cloud GPU, Nvidia A100 is selected by default.
Then the default location is enough, of course, you can also choose your favorite location.
Then it is recommended to choose Anaconda or Miniconda image for Server image. Be careful not to choose the CentOS system. There will be many environmental problems when using the CentOS system, and the system is not officially recommended here.
The next step is to choose the size of the GPU, here I choose 8GB of video memory.
Finally, remember to cancel Auto Backups to reduce unnecessary deductions.
Finally click Deploy Now.
1.2. Configure the server environment
Execute the following two commands
apt-get update
apt-get upgrade
2. Source code and model download
Create a directory to store source code
cd /opt
mkdir sd
cd sd
Clone the source code to the server
Click here to jump to the source code
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
Download the model to the specified location, download it to the models/Stable diffusion directory of the stable diffusion webui source code here.
Click here to jump to the model download
Just download it here v1-5-pruned-emaonly.safetensors
.
cd /opt/sd/stable-diffusion-webui/models/Stable-diffusion
wget -c https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors
3. Install dependent library files
Create a virtual environment
cd /opt/sd/stable-diffusion-webui
conda create -n ChatGLM python=3.10
Activate the virtual environment
conda activate ChatGLM
We install dependent libraries in a virtual environment.
Edited requirements.txt
, added at the end xformers
.
vim requirements.txt
Execute the following command
pip install -r requirements_versions.txt
pip install -r requirements.txt
There may be errors reported during the execution of the above command, just ignore it.
Modify the webui.sh file, because the root user is not allowed to run by default, so here I modify it to allow the root user to allow the webui.sh script.
vim webui.sh
before fixing
can_run_as_root=0
after modification
can_run_as_root=1
Of course, if you are running on a non-Linux system, then you do not need to modify the webui.sh script file. If you are running on a Windows system, the webui.bat script is executed.
Installcuda-toolkit
conda install -c "nvidia/label/cuda-11.8.0" cuda-toolkit
python3 -m pip install nvidia-cudnn-cu11==8.7.0.84
mkdir -p $CONDA_PREFIX/etc/conda/activate.d
echo 'CUDNN_PATH=$(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_PREFIX/lib/:$CUDNN_PATH/lib' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
source $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
4. Run the project
Finally, we can use the following command to start the project. By default, port 7860 is used to start by the following command, so you need to open port 7860 in advance.
ufw allow 7860/tcp
./webui.sh --listen
You can also use the following command to start the project.
./webui.sh --share
Through the above method, a domain name will be automatically returned to you, which can be copied and accessed directly in the browser.
5. Video Tutorial
If you like to watch the video then you can click here .