LOCAL RIG INSTALL? HERE WE GO!
So far I’ve spent a lot of time experimenting with Stable Diffusion, but as you said (thanks glowfly79), I haven’t explained how to get to the actual experimenting within StableDiffusion part.
With this post I aim to remedy that. I have just formatted my render-rig (ex-monero miner) so we are starting with a completely blank slate. The rig has 4 x 1080ti gfx cards in it, but we will only be using a single card. However I aim to try and figure out a way to incorporate the others in the near future. From what I have read online it should be possible to run a local install of SD on a rig with a 4GB or higher GFX card. It is possible to run on CPU as there are options inside the software for this but I recommend trying to get your hands on a GFX card if you don’t already have one.
That being said, this guide will work step by step with Ubuntu running and Nvidia GFX card over 4GB.
Here is a link to a post on GitHub for more info regarding GFX card requirements.
Remember this user to be a Monero miner in the not too distant past and is by no means the fastest of rigs, but as SD is where all the fun is nowadays I consider myself lucky it runs so well on it.
- Motherboard: BTC-T37 V1.1
- CPU: Intel(R) Celeron(R) CPU 1037U @ 1.80GHz
- RAM: 8GB DDR3 1600
- HDD: KUIJIA DK500/256G SSD
- GFX0: EVGA SC2 NVIDIA GeForce GTX 1080 Ti
- GFX1: EVGA SC NVIDIA GeForce GTX 1080 Ti
- GFX2: MSI AERO NVIDIA GeForce GTX 1080 Ti
- GFX3: PALIT NVIDIA GeForce GTX 1080 Ti
- PSU: Senlifang 95 Gold 2000W Switching PSU
Right up until I formatted the rig I had been running SD on Ubuntu 22.04 Desktop, and everything worked well (usually). However the software documentation mentions that SD was developed and tested on Debian 11. I did try running with Debian 11 for a couple of days but ran into problems which I never had with Ubuntu. So I am going to stick with Ubuntu for this rig. So let’s start with downloading our operating system:
UBUNTU 22.04 DESKTOP DOWNLOAD LINK.
Once the Ubuntu image has downloaded I use balenaEtcher to prime the USB stick. This process for this is self explanatory.
Insert memory stick into USB slot of the render-rig and make sure the BIOS is set to boot from USB. Accessing the BIOS is dependant on which motherboard you are using. For my motherboard I hold onto the “delete” button as the machine is booting. Set BIOS to make sure “boot from USB” is top of the boot list. Save settings and reboot, with the USB memory stick now loading our Ubuntu installation.
INFO ON UBUNTU 22.04 INSTALLATION
I am not going to explain how to install Ubuntu as again you can’t really go wrong just following the prompts. I chose minimal install with updates and third party drivers getting downloaded during operating system installation. Takes longer to install but once it is finished that should be us good to setup prerequisites.
Reboot, remove USB, and we are booted into our lovely fresh Ubuntu 22.04 install.
Before I start the terminal or SSH in I head over to “power settings” and turn off “automatic suspend“, this way the system doesn’t go into hibernation if you leave it sitting idle for 10 minutes. I just cheated and used the Desktop environment to do this, but if you want to be a purist legend and get it done in Terminal then this article should help out a whole lot…
How to Disable Suspend and Hibernation Modes In Linux
At long last we are now ready for the customary update/upgrade ritual, without which biscuits turn soggy in airtight containers (ouch).
stoke@render-rig:~$ sudo apt update -y && sudo apt upgrade -y && sudo apt autoremove
My render-rig only has 8GB memory so a large swapfile comes in very handy. As a huge precaution and because it is only SD running on this rig I am going for a 16GB swapfile. So first we stop all swap processes and then define the size of our new swapfile…
stoke@render-rig:/$ sudo swapoff -a stoke@render-rig:/$ sudo dd if=/dev/zero of=/swapfile bs=1G count=16 16+0 records in 16+0 records out 17179869184 bytes (17 GB, 16 GiB) copied, 351.084 s, 48.9 MB/s
It might look as though nothing is happening at first but 16GB are in the process of getting squirreled away (and yes, I do believe that is the technical term) for emergency use should the need arise.
stoke@render-rig:/$ sudo mkswap /swapfile mkswap: /swapfile: insecure permissions 0644, 0600 suggested. Setting up swapspace version 1, size = 16 GiB (17179865088 bytes) no label, UUID=c118d875-e670-41fe-87fd-f814e20c847a
Next we need to set acceptable permissions as we were so graciously warned about in previous step…
stoke@render-rig:/$ sudo chmod 600 /swapfile stoke@render-rig:/$ sudo swapon /swapfile
What use is all of this if you are a lazy git like myself. We don’t want to be setting swapfile space every reboot, and that is why the next stage is…
To make sure your swap file is available after a reboot, add it to the “/etc/fstab” file. You can use any text editor you prefer, but I’ll show the process using the Nano text editor.
stoke@render-rig:/$ sudo nano /etc/fstab
The line we need to add to make this happen is added right at the bottom of the file…
/swapfile none swap sw 0 0
…as highlighted in yellow in the image below.
GFX CARD: 1080ti DRIVER INSTALL
Without getting too too excited about installing SD there is the fact that we still do not have our GFX drivers installed. Before we do this however I like to install some monitoring software so I can better see what is happening behind the scenes.
To install our monitoring software for use further down the line, for those time you think the system isn’t doing anything but behind the scenes is almost melting with computational repetitive strain…
stoke@render-rig:~$ sudo apt install htop nvtop
Once installed we can use “htop” to see what resources our system is using and what processes are running, and “nvtop” is used when we want to see what is happening with our GFX card/s.
Running these couldn’t be easier, just open up another terminal window and enter:
Now time to find out some information about our GFX card…
stoke@render-rig:~$ ubuntu-drivers devices == /sys/devices/pci0000:00/0000:00:1c.4/0000:04:00.0 == modalias : pci:v000010DEd00001B06sv00003842sd00006393bc03sc00i00 vendor : NVIDIA Corporation model : GP102 [GeForce GTX 1080 Ti] driver : nvidia-driver-450-server - distro non-free driver : nvidia-driver-510-server - distro non-free driver : nvidia-driver-390 - distro non-free driver : nvidia-driver-418-server - distro non-free driver : nvidia-driver-520 - distro non-free driver : nvidia-driver-470 - distro non-free driver : nvidia-driver-515 - distro non-free recommended driver : nvidia-driver-510 - distro non-free driver : nvidia-driver-515-server - distro non-free driver : nvidia-driver-470-server - distro non-free driver : xserver-xorg-video-nouveau - distro free builtin
In the image above I have highlighted the “recommended” drivers, and as I am happy with this recommendation I can install with…
stoke@render-rig:~$ sudo ubuntu-drivers autoinstall
OPTIONAL: APT INSTALL OTHER DRIVER
If for some reason I am not happy with this recommendation I can install whichever driver from the list just by using apt…
Nvidia Drivers 510:
stoke@render-rig:~$ sudo apt install nvidia-driver-510
Nvidia Drivers 520:
stoke@render-rig:~$ sudo apt install nvidia-driver-520
GIT & PYTHON
Now our basic system is up to date we need to take care of our prerequisites for StableDiffusion. These include Git, Anaconda, and Python. We should already have Python installed, and can check with…
stoke@render-rig:~/Downloads$ python3 --version && python --version Python 3.9.2 -bash: python: command not found
…as we can see Python3 is already installed. I always like to place a symlink for Python to Python3, but for ease of use and brevity, we can achieve this with a simple little package called “python-is-python3“…
stoke@render-rig:~$ sudo apt install python-is-python3
Now time to install Git and the Venv module (for virtual environments), which is as easy as…
stoke@render-rig:~$ sudo apt install git python3-venv
Then just let them install. Easy.
Now time to install Anaconda. A lot of repos use the smaller Miniconda but I have run into problems whereas Anaconda maybe larger but works for me every time. To download Anaconda we want to goto the Downloads folder and download our desired file.
stoke@render-rig:~ cd home/stoke/Downloads/ stoke@render-rig:~/Downloads$ wget https://repo.anaconda.com/archive/Anaconda3-2022.10-Linux-x86_64.sh
Now we want to make our file executable with…
stoke@render-rig:~/Downloads$ chmod +x Anaconda3-2022.10-Linux-x86_64.sh
…so that we can run it by typing…
When Anaconda is installing just agree to everything and type “yes” at the end when asked about “init” file. Close the shell you are working in, reopen it and log in. Now you should be presented with the “base” prefix showing us that all has went well.
Now time to make the Directory we will be working from and installing to…
(base) stoke@render-rig:~$ cd (base) stoke@render-rig:~$ mkdir StableDiffusionInstalls (base) stoke@render-rig:~/StableDiffusionInstalls$ cd StableDiffusionInstalls
Finally time to clone our StableDiffusion repository…
(base) stoke@render-rig:~/StableDiffusionInstalls$ git clone https://github.com/Sygil-Dev/sygil-webui.git Cloning into 'sygil-webui'...
Now to make the script able to run, we use the trusty “chmod” command.
(base) stoke@render-rig:~/StableDiffusionInstalls$ cd sygil-webui/ (base) stoke@render-rig:~/StableDiffusionInstalls/sygil-webui$ chmod +x webui.sh
After all of that the following command is the one you have been waiting on. If you have got this far then good on you, hours of fun and intrigue await. Warning however, the first time this script is run it will take a long time. Good news however is that it only takes that long the very first time. Phew!
(base) stoke@render-rig:~/StableDiffusionInstalls/sygil-webui$ ./webui.sh
When the script is installing it will ask you to choose between two different interfaces – 1: Gradio, 2: Streamlit
GRADIO: This interface will not be getting anymore updates, however it does have a whole range of features. I also didn’t find this interface as stable as Streamlit, as I would leave the rig running with 100 renders during the night and most of the time Gradio crashed before finishing the list. I would still recommend it for experimenting with settings though.
If you are using the Gradio interface the one command that was so simple yet took me ages to discover was how to get a shareable URL? When starting the script just pass the share command…
(base) stoke@render-rig:~/StableDiffusionInstalls/sygil-webui$ ./webui.sh --share
STREAMLIT: This is the current interface that is getting updated on a regular basis. I have found this interface to be so much more stable than Gradio. I can leave Streamlit running StableDiffusion for days no problem, only shutting it down to see if there have been updates. While Gradio might have more settings available off the bat, Streamlit is under constant development, the interface looks so much nicer, and is as stable as I need it to be.
I learned on Gradio at first, as all the screenshots and videos I had seen were the same, but please get used to using Streamlit straight away. You will be glad you did as you can discover all the new features as and when they get added. Be the tip of the spear.
This is the longest guide I have done so far, so if it worked for you let me know in the comments. In fact if it didn’t work for you let me know in the comments to see if any remedy is available.
Hopefully I meet you somewhere on the quest to find the legendary perfect prompt. Happy hunting.
*** UPDATE ABOUT GRADIO ***
After writing this post I done a reinstall of StableDiffusion following this guide to make sure everything worked as was meant. When I chose which SD interface I chose Gradio for the first time in a few weeks, and boy was I wrong in what I said above.
For an interface that wasn’t to be updated anymore, they have done a fantastic job updating it 😀 The interface is a lot better laid out now, runs so much more reliably with previous crashing issues taken care of. A huge improvement.
However I still would recommend Streamlit, but I prefer Gradio for the likes of batch enlarging and batch operations in general. Both interfaces are reliable and well laid out now, but I’d imagine Streamlit will be updated a lot more often from now on going forth.
Oh and before I forget. –share no longer seems to work when loading Gradio script. Once I find out how to overcome this I will update post as needed. This is the only negative I have to say about Gradio update, and it will be something that I have missed I am trying wrong. Any help most welcome on this.