Skip to content

Explaining odd behavior with dependency locking and installation. #9701

@NellyWhads

Description

@NellyWhads

When using the following pyproject.toml, I get some weird behavior:

pyptoject.toml

[project]
name = "dep-test"
version = "0.1.0"
requires-python = ">=3.8,<3.13"

[tool.uv]
environments = ["platform_system == 'Linux'", "platform_system == 'Darwin'"]
# Conflicting groups specified at the project level
conflicts = [[{ group = "mmcv21_torch21" }, { group = "mmcv22_torch24" }]]
# Repo-wide constraints
constraint-dependencies = [
  "torch>=2.1,<2.5",
  "torchvision>=0.16,<0.20",
  "mmcv>=2.1,<2.3",
]

[dependency-groups]
my_group = ["torch", "torchvision"]
mmcv21_torch21 = [
  "mmcv~=2.1.0 ; platform_system == 'Linux' and python_version >= '3.8' and python_version < '3.12'",
  # Specific dependencies which are not encoded in the wheel
  "torch~=2.1.0",
  "torchvision~=0.16.0",
  "setuptools",
]
mmcv22_torch24 = [
  "mmcv~=2.2.0 ; platform_system == 'Linux' and python_version >= '3.8' and python_version < '3.13'",
  # Specific dependencies which are not encoded in the wheel
  "torch~=2.4.0",
  "torchvision~=0.19.0",
  "setuptools",
]

[tool.uv.sources]
torch = [{ index = "torch-cu118", marker = "platform_system == 'Linux'" }]
torchvision = [{ index = "torch-cu118", marker = "platform_system == 'Linux'" }]
mmcv = [
  # mmcv 2.1.0, torch 2.1.x
  { group = "mmcv21_torch21", marker = "platform_system == 'Linux' and python_version >= '3.8' and python_version < '3.9'", url = "https://download.openmmlab.com/mmcv/dist/cu118/torch2.1.0/mmcv-2.1.0-cp38-cp38-manylinux1_x86_64.whl" },
  { group = "mmcv21_torch21", marker = "platform_system == 'Linux' and python_version >= '3.9' and python_version < '3.10'", url = "https://download.openmmlab.com/mmcv/dist/cu118/torch2.1.0/mmcv-2.1.0-cp39-cp39-manylinux1_x86_64.whl" },
  { group = "mmcv21_torch21", marker = "platform_system == 'Linux' and python_version >= '3.10' and python_version < '3.11'", url = "https://download.openmmlab.com/mmcv/dist/cu118/torch2.1.0/mmcv-2.1.0-cp310-cp310-manylinux1_x86_64.whl" },
  { group = "mmcv21_torch21", marker = "platform_system == 'Linux' and python_version >= '3.11' and python_version < '3.12'", url = "https://download.openmmlab.com/mmcv/dist/cu118/torch2.1.0/mmcv-2.1.0-cp311-cp311-manylinux1_x86_64.whl" },
  # mmcv 2.2.0, torch 2.4.x
  { group = "mmcv22_torch24", marker = "platform_system == 'Linux' and python_version >= '3.8' and python_version < '3.9'", url = "https://download.openmmlab.com/mmcv/dist/cu118/torch2.4.0/mmcv-2.2.0-cp38-cp38-manylinux1_x86_64.whl" },
  { group = "mmcv22_torch24", marker = "platform_system == 'Linux' and python_version >= '3.9' and python_version < '3.10'", url = "https://download.openmmlab.com/mmcv/dist/cu118/torch2.4.0/mmcv-2.2.0-cp39-cp39-manylinux1_x86_64.whl" },
  { group = "mmcv22_torch24", marker = "platform_system == 'Linux' and python_version >= '3.10' and python_version < '3.11'", url = "https://download.openmmlab.com/mmcv/dist/cu118/torch2.4.0/mmcv-2.2.0-cp310-cp310-manylinux1_x86_64.whl" },
  { group = "mmcv22_torch24", marker = "platform_system == 'Linux' and python_version >= '3.11' and python_version < '3.12'", url = "https://download.openmmlab.com/mmcv/dist/cu118/torch2.4.0/mmcv-2.2.0-cp311-cp311-manylinux1_x86_64.whl" },
  { group = "mmcv22_torch24", marker = "platform_system == 'Linux' and python_version >= '3.12' and python_version < '3.13'", url = "https://download.openmmlab.com/mmcv/dist/cu118/torch2.4.0/mmcv-2.2.0-cp312-cp312-manylinux1_x86_64.whl" },
]

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

To verify everything is as expected, I run uv sync --group my_group && uv pip show torch torchvision

I'm befuddled with the outcome.

Installed versions on MacOS

Name: torch
Version: 2.1.2
Location: /Users/neil.wadhvana/workspaces/main/torc-robotics/pytorc/projects/dep_test/.venv/lib/python3.10/site-packages
Requires: filelock, fsspec, jinja2, networkx, sympy, typing-extensions
Required-by: torchvision
---
Name: torch
Version: 2.4.1
Location: /Users/neil.wadhvana/workspaces/main/torc-robotics/pytorc/projects/dep_test/.venv/lib/python3.10/site-packages
Requires: filelock, fsspec, jinja2, networkx, sympy, typing-extensions
Required-by: torchvision
---
Name: torchvision
Version: 0.16.2
Location: /Users/neil.wadhvana/workspaces/main/torc-robotics/pytorc/projects/dep_test/.venv/lib/python3.10/site-packages
Requires: numpy, pillow, torch
Required-by:
---
Name: torchvision
Version: 0.19.1
Location: /Users/neil.wadhvana/workspaces/main/torc-robotics/pytorc/projects/dep_test/.venv/lib/python3.10/site-packages
Requires: numpy, pillow, torch
Required-by:

  • Why (and how) did uv install 2 versions of torch and torchvision on MacOS? Or is this just a readout from the lock file?
    • In the .venv site-packages, I only see one installation of each package (the newer versions).
    • My intuition tells me uv pip show is both parsing the lock file for versions and also reading from the environment, and somehow getting confused.
    • Running the show without installing / after cleaning up the venv yields only the observed, installed versions.
  • I can solve this behavior by specifying the Linux platform for torch and torchvision in the mmcv* groups, but I don't yet understand why it's necessary - should it be?

I understand I'm not using the exact prescribed installation setup described in the docs, but I'm trying to understand the tool's behavior instead of just hard-coding a solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions