Go back

Step by step guide to setup Stable Diffusion on Azure

This section describes how to install Stable Diffusion with API and Automatic1111 on Azure.


  1. Open Azure Stable Diffusion:API & AUTOMATIC1111 UI VM listing on Azure Marketplace

/img/azure/stable-diffusion/marketplace_2.png

  1. Click on Get It Now. If you are not already logged in, it will navigate you to the Login Page. Login with your credentials and Click on Continue option.

  2. Next it shows the products details page where you can see multiple option to choose from. Please click on Create button.

/img/azure/stable-diffusion/create.png

  • Select a Resource group for your virtual machine
  • Select a Region where you want to launch the VM(such as East US)

/img/azure/stable-diffusion/basics-page-01.png

  • Note: If you see “This image is not compatible with selected security type. To keep trusted launch virtual machines, select a compatible image. Otherwise change your security type back to Standard” error message below the Image name as shown in the screenshot below then please change the Security type to Standard.

/img/azure/stable-diffusion/image-mismatch-error.png /img/azure/stable-diffusion/standard-security-type.png

  • Make sure to select “Standard” from the dropdown for “Security type”.
  • Optionally change the number of cores and amount of memory (size).
  • For optimal performance, Stable Diffusion requires significant processing power, which is best achieved with a GPU instance. However, if the cost of a GPU instance is prohibitive, a CPU instance with higher processing capacity may be used as an alternative.

Below are the recommended VM configuration:

  • GPU VM : Standard_NC4as_T4_v3 (4 vcpu 28GB memory 1NVIDIA GPU)
  • CPU VM : Standard_B8ms (8vcpu, 32gb ram)

For CPU, its the minimum spec but more cpu is preferred.

NOTE: While deploying the instance on GPU, if you encounter the quota exhaust error or you are unable to deploy the instance on GPU VM then please refer to our Request Quota on Azure Cloud Platform Page.

  • Select the Authentication type as Password and enter Username as ubuntu and Password of your choice.

/img/azure/stable-diffusion/basics-page-02.png

  • Optionally change the OS disk type.

/img/azure/stable-diffusion/disk.png

  • Select the default Networking configuration. Default Networking configuration comes with the ports 22 (for ssh), 3389 (for RDP), 443 (for HTTPS) and 80 (for HTTP) exposed.

/img/azure/stable-diffusion/default-network.png

/img/azure/stable-diffusion/default-nsg-rule.png

  • Optionally go to the Management, Advanced and Tags tabs for any advance settings you want for the VM.
  • Click on Review + create and then click on Create when you are done.
    Virtual Machine will begin deploying.
  1. A summary page displays when the virtual machine is successfully created. Click on Go to resource link to go to the resource page. It will open an overview page of virtual machine.

/img/azure/stable-diffusion/vm-overview.png

  1. After VM launch for the first time, GPU instances will take 5-10 minutes and CPU instances will take 15-30 minutes to launch the app in the browser.

    Wait for 5-10 or 15-30 minutes depending on if your VM is GPU or CPU based and then access the Stable Diffusion GUI via browser by copying the public IP of the VM from the VM’s overview page and paste it in the browser and then hit enter. If SD WebUI does not appear even after 30 minutes, then please reboot the VM and check again.

    You can access the SD WebUI using http://VM_Public_IP or https://VM_Public_IP.

    Note: If you are using https in the URL when accessing AUTOMATIC1111 interface in browser, for eg. https://VM_Public_IP , then your browser will show the certificate warning. Accept the certificate warning and Continue.

/img/azure/stable-diffusion/public-ip.png

/img/aws/stable-diffusion/ssl-certificate-warning.png

  1. The Stable Diffusion GUI comes with lots of options and settings. The first window shows text to image page. Provide the Prompt and click on Generate button and wait till it finishes.

/img/azure/stable-diffusion/stable-diffusion-gui-2.png

  1. Output Images can be seen in the Image Browser tab. Click on Image browser and click on first page to load the images.

/img/azure/stable-diffusion/image-browser-gallery-2.png

  1. In Image Browser, click on any image to see the details of it.

/img/azure/stable-diffusion/image-browser-2.png

  1. To change any settings, go to Settings tab.

/img/azure/stable-diffusion/settings-2.png

  1. Web UI also provides you the option to add extensions. Navigate to extensions tab, go to available and select load from URL. It will list all the available extensions.

/img/azure/stable-diffusion/extensions-2.png

  1. You can also see the list of installed extensions under installed tab. /img/azure/stable-diffusion/extensions-installed.png

  2. For more information on how to use the GUI, Go to Stable Diffusion Web UI

  3. The images created from GUI are stored under /home/ubuntu/stable-diffusion/output/ directory on the VM. To access this directory, follow below steps: /img/azure/stable-diffusion/output-directory.png

  4. Connect to the VM’s desktop environment from any local windows machine using RDP protocol .

  5. If for any reason you don’t remember your VM’s password then you can reset it. In the left pane, scroll down to Help section and click on Reset password. Enter ‘Username’ as ubuntu and ‘Password’ of your choice. Click on Update button to save the changes.

/img/azure/stable-diffusion/reset-passwd.png

  1. To connect using RDP via Windows Machine, first note the public IP address of the VM from VM details page as highlighted below

/img/azure/stable-diffusion/public-ip.png

  1. Then From you local windows machine, goto “start” menu, in the search box type and select “Remote desktop connection”. In the “Remote Desktop connection” wizard, copy the public IP address and click connect

/img/azure/desktop-linux/rdp.png

  1. This will connect you to the VM’s desktop environment. Provide the username as ubuntu and the password provided during the VM creation to authenticate. Click OK

/img/azure/stable-diffusion/rdp-login.png

  1. Now you are connected to the out of box Azure Stable Diffusion:API & AUTOMATIC1111 UI environment via Windows Machine.

/img/azure/stable-diffusion/rdp-desktop.png

  1. From VM’s Desktop, you can access the Output Images by navigating to /home/ubuntu/stable-diffusion/outputs/ directory.

/img/azure/stable-diffusion/output-directory.png

  1. You can also access the sourcecode of the Stable Diffusion. It is available under sourcecode folder on Desktop.

/img/gcp/stable-diffusion/source-code-folder-on-desktop.png

/img/gcp/stable-diffusion/source-code.png

  1. To SSH to the VM, Open putty and paste the IP address and click on Open.

/img/aws/ethereum-fullnode/putty-01.png

  1. login as ubuntu and provide the password for ‘ubuntu’ user

/img/azure/stable-diffusion/ssh.png

  1. This VM is pre-configured for Stable Diffusion with an enabled API (Application Programming Interface). To access the preinstalled API’s, follow below steps:
  • open VM’s url using http://vmip/docs. Here you can find the list of API’s.

Note: Please use http://vmip/docs and not https://vmip/docs to access the API page

/img/azure/stable-diffusion/docs.png

  • Search for txt2img API, then click on the arrow at the right end of the searched api line, it gives an example of a payload to send to the API. Click on the try it out button.

/img/azure/stable-diffusion/txt2imgapi.png

  • This will enable the Request Body and Execute button. Try with the below code snippet in request body and click on Execute button.

e.g

{
“prompt”: “duck flying in sky”,
“steps”: 5
}

/img/azure/stable-diffusion/execute-api.png

  • After clicing on “Execute” button, You can observe the progress in the terminal by running-
tail -f /var/log/cloud-init-output.log

/img/azure/stable-diffusion/api-logs.png

  • Once image processing is complete, in the API webconsole, it will show “200” as response code and the response field will have response in json format with image in “images:” field of json. /img/azure/stable-diffusion/response.png
  1. Please note that APIs are exposed on public internet and you must add necessary security controls to secure the API.
  2. If you want to disable the API or want to make any further configuration changes then please update line 20 and line 23 of /var/lib/cloud/scripts/per-boot/sd-per-boot.sh file as per the Stable Diffusion Wiki documentation.
sudo vi /var/lib/cloud/scripts/per-boot/sd-per-boot.sh

/img/azure/stable-diffusion/update-sd-per-boot.png

Credits:

Go back