python-poetry / python-poetry/poetry

Example in the Documentation does not work for Torch and TorchVision

Open
#10,349 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/bug status/triage
Dominant language
Python
Stars
34.3k
Forks
2.5k
Avg merge
2d 19h
Merged PRs (30d)
30

Description

Description

My pyproject.toml file (based on documentation )

[project]
authors = [{ name = "rohanmohapatra", email = "censored" }]
description = ""
name = "censored"
readme = "README.md"
requires-python = ">=3.10,<3.13"
version = "0.0.1"

[tool.poetry]
package-mode = false

[project.optional-dependencies]
cpu = ["torch (==2.4.1+cpu)", "torchvision (==0.19.1+cpu)"]
cuda = ["torch (==2.4.1+cu124)", "torchvision (==0.19.1+cu124)"]

[[tool.poetry.source]]
name = "pytorch-cpu"
priority = "explicit"
url = "https://download.pytorch.org/whl/cpu"

[[tool.poetry.source]]
name = "pytorch-cu124"
priority = "explicit"
url = "https://download.pytorch.org/whl/cu124"


[tool.poetry.dependencies]
torch = [
    { markers = "extra == 'cpu' and extra != 'cuda'", version = "2.4.1+cpu", source = "pytorch-cpu" },
    { markers = "extra == 'cuda' and extra != 'cpu'", version = "2.4.1+cu124", source = "pytorch-cu124" },
]
torchvision = [
    { markers = "extra == 'cpu' and extra != 'cuda'", version = "0.19.1+cpu", source = "pytorch-cpu" },
    { markers = "extra == 'cuda' and extra != 'cpu'", version = "0.19.1+cu124", source = "pytorch-cu124" },
]

When I run poetry install --extras "cuda", It shows 2 updates which is exactly what I want

Package operations: 0 installs, 2 updates, 0 removals

  - Updating torch (2.4.1+cpu -> 2.4.1+cu124)
  - Updating torchvision (0.19.1+cpu -> 0.19.1+cu124)

But when I run poetry install --extras "cpu", it shows only 1 update

Package operations: 0 installs, 1 update, 0 removals

  - Downgrading torch (2.4.1+cu124 -> 2.4.1+cpu)

This does not makes sense? Am I doing something wrong?

Workarounds

No workaround yet.

Poetry Installation Method

pip

Operating System

Ubuntu 22.04

Poetry Version

2.1.2

Poetry Configuration
cache-dir = "~/.cache/pypoetry"
data-dir = "~/.local/share/pypoetry"
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
installer.re-resolve = true
keyring.enabled = true
python.installation-dir = "{data-dir}/python" 
repositories.pytorch-cpu.url = "https://download.pytorch.org/whl/cpu"
repositories.pytorch-cu124.url = "https://download.pytorch.org/whl/cu124"
requests.max-retries = 0
solver.lazy-wheel = true
system-git-client = false
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs"
virtualenvs.prompt = "{project_name}-py{python_version}"
virtualenvs.use-poetry-python = false
Python Sysconfig
sysconfig.log
Paste the output of 'python -m sysconfig', over this line.
Example pyproject.toml
[project]
authors = [{ name = "rohanmohapatra", email = "censored" }]
description = ""
name = "censored"
readme = "README.md"
requires-python = ">=3.10,<3.13"
version = "0.0.1"

[tool.poetry]
package-mode = false

[project.optional-dependencies]
cpu = ["torch (==2.4.1+cpu)", "torchvision (==0.19.1+cpu)"]
cuda = ["torch (==2.4.1+cu124)", "torchvision (==0.19.1+cu124)"]

[[tool.poetry.source]]
name = "pytorch-cpu"
priority = "explicit"
url = "https://download.pytorch.org/whl/cpu"

[[tool.poetry.source]]
name = "pytorch-cu124"
priority = "explicit"
url = "https://download.pytorch.org/whl/cu124"


[tool.poetry.dependencies]
torch = [
    { markers = "extra == 'cpu' and extra != 'cuda'", version = "2.4.1+cpu", source = "pytorch-cpu" },
    { markers = "extra == 'cuda' and extra != 'cpu'", version = "2.4.1+cu124", source = "pytorch-cu124" },
]
torchvision = [
    { markers = "extra == 'cpu' and extra != 'cuda'", version = "0.19.1+cpu", source = "pytorch-cpu" },
    { markers = "extra == 'cuda' and extra != 'cpu'", version = "0.19.1+cu124", source = "pytorch-cu124" },
]
Poetry Runtime Logs
poetry-runtime.log
Checking keyring availability: Checking if keyring is available
[keyring:keyring.backend] Loading KWallet
[keyring:keyring.backend] Loading SecretService
[keyring:keyring.backend] Loading Windows
[keyring:keyring.backend] Loading chainer
[keyring:keyring.backend] Loading libsecret
[keyring:keyring.backend] Loading macOS
Backend 'fail Keyring' is not suitable
No valid keyring backend was found
Unavailable
Installing dependencies from lock file

Finding the necessary packages for the current system

Package operations: 0 installs, 1 update, 0 removals, 11 skipped

- Downgrading torch (2.4.1+cu124 -> 2.4.1+cpu): Pending...
Multiple source configurations found for download.pytorch.org - pytorch-cpu, pytorch-cu124
Creating new session for download.pytorch.org
Multiple source configurations found for download.pytorch.org - pytorch-cpu, pytorch-cu124
[urllib3:urllib3.connectionpool] Starting new HTTPS connection (1): download.pytorch.org:443
[urllib3:urllib3.connectionpool] https://download.pytorch.org:443 "GET /whl/cpu/torch/ HTTP/1.1" 200 162168
Skipping wheel torch-2.4.1+cpu-cp310-cp310-win_amd64.whl as this is not supported by the current environment
Skipping wheel torch-2.4.1+cpu-cp311-cp311-linux_x86_64.whl as this is not supported by the current environment
Skipping wheel torch-2.4.1+cpu-cp311-cp311-win_amd64.whl as this is not supported by the current environment
Skipping wheel torch-2.4.1+cpu-cp312-cp312-linux_x86_64.whl as this is not supported by the current environment
Skipping wheel torch-2.4.1+cpu-cp312-cp312-win_amd64.whl as this is not supported by the current environment
Skipping wheel torch-2.4.1+cpu-cp38-cp38-linux_x86_64.whl as this is not supported by the current environment
Skipping wheel torch-2.4.1+cpu-cp38-cp38-win_amd64.whl as this is not supported by the current environment
Skipping wheel torch-2.4.1+cpu-cp39-cp39-linux_x86_64.whl as this is not supported by the current environment
Skipping wheel torch-2.4.1+cpu-cp39-cp39-win_amd64.whl as this is not supported by the current environment
- Downgrading torch (2.4.1+cu124 -> 2.4.1+cpu): Installing...
- Downgrading torch (2.4.1+cu124 -> 2.4.1+cpu)
- Installing filelock (3.18.0): Pending...
- Installing filelock (3.18.0): Skipped for the following reason: Already installed
- Installing fsspec (2025.3.2): Pending...
- Installing fsspec (2025.3.2): Skipped for the following reason: Already installed
- Installing jinja2 (3.1.6): Pending...
- Installing jinja2 (3.1.6): Skipped for the following reason: Already installed
- Installing mpmath (1.3.0): Pending...
- Installing mpmath (1.3.0): Skipped for the following reason: Already installed
- Installing networkx (3.4.2): Pending...
- Installing networkx (3.4.2): Skipped for the following reason: Already installed
- Installing numpy (2.2.4): Pending...
- Installing numpy (2.2.4): Skipped for the following reason: Already installed
- Installing sympy (1.13.3): Pending...
- Installing sympy (1.13.3): Skipped for the following reason: Already installed
- Installing markupsafe (3.0.2): Pending...
- Installing markupsafe (3.0.2): Skipped for the following reason: Already installed
- Installing pillow (11.2.1): Pending...
- Installing pillow (11.2.1): Skipped for the following reason: Already installed
- Installing typing-extensions (4.13.2): Pending...
- Installing typing-extensions (4.13.2): Skipped for the following reason: Already installed
- Installing torchvision (0.19.1+cpu): Pending...
- Installing torchvision (0.19.1+cpu): Skipped for the following reason: Already installed

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the dependency specification documentation linked in the issue and reproduce the listed poetry install --extras "cpu" and cuda commands using the provided pyproject.toml. Compare the lock-file operations for torch and torchvision; done means the documented example selects and installs the matching CPU or CUDA variants consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
documentation, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.