Skip to content

Instantly share code, notes, and snippets.

@sgeraldes
Last active June 7, 2024 16:54
Show Gist options
  • Save sgeraldes/be9d8dfc672ccf491caaacc9ba5beb37 to your computer and use it in GitHub Desktop.
Save sgeraldes/be9d8dfc672ccf491caaacc9ba5beb37 to your computer and use it in GitHub Desktop.
Setup ComfyUI / Automatic1111 properly

How to properly install ComfyUI / Stable Diffusion UI / Automatic1111 (including dependencies and requirements)

Certain ComfyUI or Automatic1111 extensions require different version of CUDA than the latest. You probably have 12.x installed, since it is the latest available. Unfortunately, the backwards compatibility is poor.

We'll be installing PyTorch for CUDA 11.8, independently, and we can change PyTorch versions without installing the full CUDA toolkit.

PreRequisites

  • Latest NVidia GPU Drivers installed
  • Python 3.10.11 (at the time of writing this, the best version) - Optional, we can do this later

How to check current status

If Python is installed and on the system path:

python -c "import torch; print(torch.version); print(torch.version.cuda)"

you might see something like:

2.1.1+cu121 12.1

Setting Up a Python Virtual Environment

  1. Install Python (you can download it from the official website)

  2. Open PowerShell and navigate to your project directory

    cd path\to\ComfyUI

  3. Create a Virtual Environment:

    python -m venv myenv

    You can replace myenv with any name you want for your virtual environment.

  4. Activate the Environment: Within the same directory, run the following command

    .\myenv\Scripts\activate

    Your command prompt should now indicate that you're in the virtual environment.

Installing PyTorch for CUDA 11.8

We can now install PyTorch built for the specific CUDA version we need to support our ComfyUI requirements. Run the following commands in the same Powershell window/directory:

.\myenv\Scripts\activate

  1. Uninstall Current PyTorch Version: (skip this if first time setting up virtual environment)

    pip uninstall torch torchvision torchaudio

  2. Install PyTorch for CUDA 11.8:

    pip install torch==2.1.1+cu118 torchvision==0.16.1+cu118 torchaudio==2.1.1+cu118 -f https://download.pytorch.org/whl/torch_stable.html

  3. Verify PyTorch Installation:

    python -c "import torch; print(torch.version); print(torch.version.cuda)"

If everything worked correctly, you should see the following print in the terminal window:

> 2.1.1+cu118
> 11.8

Installing ONNX Runtime

Finally, now that we have the right environment & dependencies, we can install onnxruntime-gpu:

> pip install onnxruntime-gpu
(or if you've installed the portable version ComfyUI)
> python_embeded\python.exe -m pip install onnxruntime-gpu
...and to verify everything is working correctly, run ComfyUI and observe the following terminal output:
> DWPose: Onnxruntime with acceleration providers detected

(Congratulations if you followed along and made it this far 🎉)

Installing ComfyUI / Automatic1111 requirements

.\myenv\Scripts\activate python -m pip install --upgrade pip python -m pip -r requirements.txt

Installing SUPIR requirements

Supir requires Python 3.8, at the time of publishing this, but there are workarounds I figured out to install with Python 3.10.11:

  1. Clone repo

git clone https://github.com/Fanghua-Yu/SUPIR.git cd SUPIR Install dependent packages

  1. Modify requirements.txt

a. Comment or remove the following lines

"# fsspec==2023.4.0"

"# triton==2.1.0"

b. Edit the following line to: "fastapi==0.111.0"

  1. Create the virtual environment and install requirements

python -m venv myenv .\myenv\Scripts\activate python -m pip install --upgrade pip pip install -r requirements.txt pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 pip install onnxruntime-gpu

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