Skip to content

Instantly share code, notes, and snippets.

@nviet
Last active April 1, 2024 02:14
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save nviet/a4296bae33cbc8738e274951e0a89d4a to your computer and use it in GitHub Desktop.
Save nviet/a4296bae33cbc8738e274951e0a89d4a to your computer and use it in GitHub Desktop.
Install stable-diffusion-webui on Termux (Android) + PRoot

Install stable-diffusion-webui on Termux (Android) + PRoot

This will guide you on installing AUTOMATIC1111/stable-diffusion-webui on Termux (Android) + PRoot Distro. Make sure that you have a high-end phone to actually make this usable. On my phone with 8GB RAM, launch the webui alone take at least ~ 2 GB RAM, thus making it impossible to load any model and process further.

1. Prerequisites

First you have to install Termux and install PRoot. Then install and login to Ubuntu in PRoot

2. Installing AUTOMATIC1111/stable-diffusion-webui

Run below commands sequentially as root user in Ubuntu

  1. Install basic tools

apt update && apt upgrade -y && apt-get install curl git gcc make build-essential python3 python3-dev python3-distutils python3-pip python3-venv python-is-python3 -y

  1. Install required extensions

apt-get install libgl1 libglib2.0-0 libsm6 libxrender1 libxext6 -y

  1. Clone the repository

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui

  1. Change the current directory

cd stable-diffusion-webui

  1. 'Fix' the issue with Python running in PRoot

export ANDROID_DATA=anything

  1. Install required Python packages

pip install -r requirements.txt

  1. Install xformers. This package is not required, but is recommended to be installed

pip install xformers

  1. Launch the webui. It will take some time to complete first-time installation then everything should be fine

python launch.py --skip-torch-cuda-test --use-cpu interrogate --precision full --no-half --xformers --listen

  1. Navigate to the webui in your browser

http://127.0.0.1:7860

@nviet
Copy link
Author

nviet commented Apr 17, 2023

Is possible to install models from civitai?

All the functionalities are there so it's possible to install models from Civitai. Since stable diffusion is very resource-intensive, try to lower the image resolution and number of sampling steps to as low as possible until you can get any results.

@nyveZz
Copy link

nyveZz commented Jun 19, 2023

you can still use stable diffusion with http://0.0.0.0:7860/

@kroryan
Copy link

kroryan commented Sep 10, 2023

Hi so i did installed everything goes well but when i start it termux crash, i have 6 gb ram and 20 gb swap i dont know why it is happening i think it shouldnt... do you know what it could be?

@nviet
Copy link
Author

nviet commented Sep 11, 2023

Hi so i did installed everything goes well but when i start it termux crash, i have 6 gb ram and 20 gb swap i dont know why it is happening i think it shouldnt... do you know what it could be?

Hi there, if you can pull out some logs then it would be easier to identify the issue. But IMO it's mostly because the phone runs out of memory. If you want to use swap then you should be using chroot not proot, which will requires your phone to be rooted. You can refer to this guide.

If it's just for generating image using Stable Diffusion then there are other faster methods around.

@kroryan
Copy link

kroryan commented Sep 11, 2023

mm im using proot, im root, and the swap is working i can see it on htop, i dont understan why it get close

@Fliegefisch
Copy link

Fliegefisch commented Dec 11, 2023

Hi so i did installed everything goes well but when i start it termux crash, i have 6 gb ram and 20 gb swap i dont know why it is happening i think it shouldnt... do you know what it could be?

Hi there, if you can pull out some logs then it would be easier to identify the issue. But IMO it's mostly because the phone runs out of memory. If you want to use swap then you should be using chroot not proot, which will requires your phone to be rooted. You can refer to this guide.

If it's just for generating image using Stable Diffusion then there are other faster methods around.

Hi, I followed your instructions. With latest ubuntu I got a few python installation errors (this-environment-is-externally-managed) which can be solved by using a venv or --break-system-packages.

Afaik --xformers is only supported on Nvidia gpus. For me sd only works correctly without.

With a resolution of 256x256 generation works and I get about 20s / it on Oneplus Nord 2 with 12 gb Ram. More than 8 are being used.

Screenshot_2023-12-11-09-44-39-87_ae6cd5a5b0621eeb01c09ff06fe027c5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment