Skip to content

Adding UV installation instructions to README #6349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

dsantiago
Copy link

As UV gains traction as a package management tool, I'm adding instructions to READ.me for those who have the interest to install and better control the package usage.

@robinjhuang
Copy link
Collaborator

uv is great.

uv init might error out after this PR goes in since pyproject.toml already exists: #6386

Also, I believe simply adding the requirements is not enough if you want CUDA or RoCM torch? Have you tried setting any of this stuff up in pyproject.toml?

https://docs.astral.sh/uv/guides/integration/pytorch/

Would be great to have something like:

  • cuda index for windows or linux by default
  • cpu nightly index for macos

@dsantiago
Copy link
Author

Hi there, thanks to asking... I did not stress the command because I don't have an easy way to do it (multiple SOs).

About pyproject.toml file, I checked the current options but I don't think both can co-exist. There's also a config file called uv.toml but I understood it works on the system level... I need to think of an option, but of couse you guys can propose if it's of interest to have an easy fresh install option with UV....

@dsantiago
Copy link
Author

@robinjhuang I updated the READ.me as I tested with the other PR #6386 pyproject.toml file. It was just needed to don't call uv init as uv reutilizes the pyproject.toml file without conflicts. You can use uv add .... normaly as it will generate the dependency entry in the file so it is good to go.

@robinjhuang
Copy link
Collaborator

robinjhuang commented Feb 13, 2025

@dsantiago
Thanks this looks good! I have one suggestion:

What are your thoughts on adding the pytorch as optional dependencies? uv supports configuring accelerator-specific dependencies like this.

Now you can install ComfyUI simply by running:

uv sync --extra cu126 
uv sync --extra rocm
[project]
name = "ComfyUI"
version = "0.3.12"
readme = "README.md"
license = { file = "LICENSE" }
requires-python = ">=3.9"
dependencies = [
    "torchsde",
    "numpy>=1.25.0",
    "einops",
    "transformers>=4.28.1",
    "tokenizers>=0.13.3",
    "sentencepiece",
    "safetensors>=0.4.2",
    "aiohttp",
    "pyyaml",
    "Pillow",
    "scipy",
    "tqdm",
    "psutil",
    # Optional dependencies
    "kornia>=0.7.1",
    "spandrel",
    "soundfile",
]

[project.optional-dependencies]
cpu = [
  "torch",
  "torchvision",
  "torchaudio",
]

cu126 = [
  "torch",
  "torchvision",
  "torchaudio",
]

cu124 = [
  "torch",
  "torchvision",
  "torchaudio",
]

cu118 = [
  "torch",
  "torchvision",
  "torchaudio",
]

rocm = [
  "torch",
  "torchvision",
  "torchaudio",
]

xpus = [
  "torch",
  "torchvision",
  "torchaudio",
]

[tool.uv]
conflicts = [
  [
    { extra = "cpu" },
    { extra = "cu126" },
    { extra = "cu124" },
    { extra = "cu118" },
    { extra = "rocm" },
    { extra = "xpus" },
  ],
]


[project.urls]
homepage = "https://www.comfy.org/"
repository = "https://github.com/comfyanonymous/ComfyUI"
documentation = "https://docs.comfy.org/"

[tool.ruff]
lint.select = [
  "S307", # suspicious-eval-usage
  "S102", # exec
  "T",    # print-usage
  "W",
  # The "F" series in Ruff stands for "Pyflakes" rules, which catch various Python syntax errors and undefined names.
  # See all rules here: https://docs.astral.sh/ruff/rules/#pyflakes-f
  "F",
]
exclude = ["*.ipynb"]


[tool.uv.sources]
torch = [
  { index = "pytorch-cu126", extra = "cu126" },
  { index = "pytorch-cu124", extra = "cu124" },
  { index = "pytorch-cu118", extra = "cu118" },
  { index = "pytorch-cpu", extra = "cpu" },
  { index = "pytorch-rocm", extra = "rocm" },
  { index = "pytorch-xpu", extra = "xpus" },
]
torchvision = [
    { index = "pytorch-cu126", extra = "cu126" },
    { index = "pytorch-cu124", extra = "cu124" },
    { index = "pytorch-cu118", extra = "cu118" },
    { index = "pytorch-cpu", extra = "cpu" },
    { index = "pytorch-rocm", extra = "rocm" },
    { index = "pytorch-xpu", extra = "xpus" },
]
torchaudio = [
  { index = "pytorch-cu126", extra = "cu126" },
  { index = "pytorch-cu124", extra = "cu124" },
  { index = "pytorch-cu118", extra = "cu118" },
  { index = "pytorch-cpu", extra = "cpu" },
  { index = "pytorch-rocm", extra = "rocm" },
  { index = "pytorch-xpu", extra = "xpus" },
]

[[tool.uv.index]]
name = "pytorch-cu126"
url = "https://download.pytorch.org/whl/cu126"
explicit = true

[[tool.uv.index]]
name = "pytorch-cu124"
url = "https://download.pytorch.org/whl/cu124"
explicit = true

[[tool.uv.index]]
name = "pytorch-cu118"
url = "https://download.pytorch.org/whl/cu118"
explicit = true

[[tool.uv.index]]
name = "pytorch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true

[[tool.uv.index]]
name = "pytorch-rocm"
url = "https://download.pytorch.org/whl/rocm6.2"
explicit = true

[[tool.uv.index]]
name = "pytorch-xpu"
url = "https://download.pytorch.org/whl/xpu"
explicit = true

@dsantiago
Copy link
Author

@dsantiago Thanks this looks good! I have one suggestion:

What are your thoughts on adding the pytorch as optional dependencies? uv supports configuring accelerator-specific dependencies like this.

Now you can install ComfyUI simply by running:

uv sync --extra cu126 
uv sync --extra rocm
[project]
name = "ComfyUI"
version = "0.3.12"
readme = "README.md"
license = { file = "LICENSE" }
requires-python = ">=3.9"
dependencies = [
    "torchsde",
    "numpy>=1.25.0",
    "einops",
    "transformers>=4.28.1",
    "tokenizers>=0.13.3",
    "sentencepiece",
    "safetensors>=0.4.2",
    "aiohttp",
    "pyyaml",
    "Pillow",
    "scipy",
    "tqdm",
    "psutil",
    # Optional dependencies
    "kornia>=0.7.1",
    "spandrel",
    "soundfile",
]

[project.optional-dependencies]
cpu = [
  "torch",
  "torchvision",
  "torchaudio",
]

cu126 = [
  "torch",
  "torchvision",
  "torchaudio",
]

cu124 = [
  "torch",
  "torchvision",
  "torchaudio",
]

cu118 = [
  "torch",
  "torchvision",
  "torchaudio",
]

rocm = [
  "torch",
  "torchvision",
  "torchaudio",
]

xpus = [
  "torch",
  "torchvision",
  "torchaudio",
]

[tool.uv]
conflicts = [
  [
    { extra = "cpu" },
    { extra = "cu126" },
    { extra = "cu124" },
    { extra = "cu118" },
    { extra = "rocm" },
    { extra = "xpus" },
  ],
]


[project.urls]
homepage = "https://www.comfy.org/"
repository = "https://github.com/comfyanonymous/ComfyUI"
documentation = "https://docs.comfy.org/"

[tool.ruff]
lint.select = [
  "S307", # suspicious-eval-usage
  "S102", # exec
  "T",    # print-usage
  "W",
  # The "F" series in Ruff stands for "Pyflakes" rules, which catch various Python syntax errors and undefined names.
  # See all rules here: https://docs.astral.sh/ruff/rules/#pyflakes-f
  "F",
]
exclude = ["*.ipynb"]


[tool.uv.sources]
torch = [
  { index = "pytorch-cu126", extra = "cu126" },
  { index = "pytorch-cu124", extra = "cu124" },
  { index = "pytorch-cu118", extra = "cu118" },
  { index = "pytorch-cpu", extra = "cpu" },
  { index = "pytorch-rocm", extra = "rocm" },
  { index = "pytorch-xpu", extra = "xpus" },
]
torchvision = [
    { index = "pytorch-cu126", extra = "cu126" },
    { index = "pytorch-cu124", extra = "cu124" },
    { index = "pytorch-cu118", extra = "cu118" },
    { index = "pytorch-cpu", extra = "cpu" },
    { index = "pytorch-rocm", extra = "rocm" },
    { index = "pytorch-xpu", extra = "xpus" },
]
torchaudio = [
  { index = "pytorch-cu126", extra = "cu126" },
  { index = "pytorch-cu124", extra = "cu124" },
  { index = "pytorch-cu118", extra = "cu118" },
  { index = "pytorch-cpu", extra = "cpu" },
  { index = "pytorch-rocm", extra = "rocm" },
  { index = "pytorch-xpu", extra = "xpus" },
]

[[tool.uv.index]]
name = "pytorch-cu126"
url = "https://download.pytorch.org/whl/cu126"
explicit = true

[[tool.uv.index]]
name = "pytorch-cu124"
url = "https://download.pytorch.org/whl/cu124"
explicit = true

[[tool.uv.index]]
name = "pytorch-cu118"
url = "https://download.pytorch.org/whl/cu118"
explicit = true

[[tool.uv.index]]
name = "pytorch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true

[[tool.uv.index]]
name = "pytorch-rocm"
url = "https://download.pytorch.org/whl/rocm6.2"
explicit = true

[[tool.uv.index]]
name = "pytorch-xpu"
url = "https://download.pytorch.org/whl/xpu"
explicit = true

It's a great idea @robinjhuang. I was just thinking in something easy for a fresh install but this one should be even better if we explain it well in the docs...

@sansmoraxz
Copy link

FYI uv does not contain pip by default, so you may need to include pip as optional dependency as some third party extensions use calls such as python -m pip install mydependency.

Or shim the pip to call uv pip.

Here's how I am presently doing this:

~\uv_pip_shim\pip\__main__.py

import sys
import subprocess

sys.exit(subprocess.call(['uv', 'pip'] + sys.argv[1:]))

Then register it to python by setting env var PYTHONPATH to ~\uv_pip_shim

Please note that since not all pip features are available in uv's pip which may break if someone is using pip specific flags viz. --prefer-binary.

@polarathene
Copy link

some third party extensions use calls such as python -m pip install mydependency.

Could you provide an example for reference? Is that part of automated install or just instructions for manual install?


What are your thoughts on adding the pytorch as optional dependencies? uv supports configuring accelerator-specific dependencies like this.

It is nice, but IIRC it is not always compatible due to how PyTorch publishes their wheels. IIRC +cpu on AMD64 provides CPU packaged PyTorch, while on PyPi not using that suffix would get the nvidia package (but on PyTorch wheels without the suffix it might default to CPU).

The issue with PyTorch wheels IIRC was notable with CPU package difference between AMD64 and ARM64 platforms. They were inconsistent. UV also was a bit limited (at least at the time) when it came to installing these packages from PyTorch, you could not as easily set version constraints when specifiers were involved, but not using specifiers would also have related torch packages resolve the wrong torch package.

I guess they've possible fixed that concern, but you might still have an issue with ARM64 compatibility. If so adding a disclaimer might be needed 😅

@sansmoraxz
Copy link

some third party extensions use calls such as python -m pip install mydependency.

Could you provide an example for reference? Is that part of automated install or just instructions for manual install?

Comyui model manager auto installs packages using pip

https://github.com/hayden-fr/ComfyUI-Model-Manager/blob/main/__init__.py#L16-L29

Of course a lot of people who uses it tend to rely on these tools to manage their dependencies rather than doing manually.

@sansmoraxz
Copy link

sansmoraxz commented Jun 9, 2025

Btw there's a flag for uv to auto-resolve pytorch.

https://docs.astral.sh/uv/guides/integration/pytorch/#automatic-backend-selection

Experimental though.

@polarathene
Copy link

polarathene commented Jun 10, 2025

Comyui model manager auto installs packages using pip

Awesome thanks! :)

Btw there's a flag for uv to auto-resolve pytorch.

This is unlikely to work in environments like building containers, especially when the build host is not equipped with a GPU (such as GH Actions). Relying upon that would need to communicate why the install method fails in such environments where it'd be unsupported.

EDIT: Oh you can set an explicit version. It'd still need to be clear it's only for CUDA, not AMD/Intel equivalent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants