Skip to content
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

Poetry torch cpu-only or gpu-only installation fails. #9565

Closed
masoudghaffarinia opened this issue Jul 19, 2024 · 7 comments
Closed

Poetry torch cpu-only or gpu-only installation fails. #9565

masoudghaffarinia opened this issue Jul 19, 2024 · 7 comments
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@masoudghaffarinia
Copy link

masoudghaffarinia commented Jul 19, 2024

Description

I want to install torch cpu-only package using poetry.

With pip3 I am able to install it with cpu-only dependencies:

pip3 install torch --index-url https://download.pytorch.org/whl/cpu

However using poetry I cannot. Here is more detail on my approach.

Poetry documentation has an example for torch gpu installation by defining explicit source:

> poetry source add --priority=explicit pytorch-gpu-src https://download.pytorch.org/whl/cu118
> poetry add --source pytorch-gpu-src torch torchvision torchaudio

Using version ^2.3.1+cu118 for torch

Updating dependencies
Resolving dependencies... (4.6s)

Package operations: 1 install, 0 updates, 0 removals

  - Installing torch (2.3.1+cu118): Failed

  RuntimeError

  Unable to find installation candidates for torch (2.3.1+cu118)

  at ~/.local/pipx/venvs/poetry/lib/python3.12/site-packages/poetry/installation/chooser.py:74 in choose_for
       70│ 
       71│             links.append(link)
       72│ 
       73│         if not links:
    →  74│             raise RuntimeError(f"Unable to find installation candidates for {package}")
       75│ 
       76│         # Get the best link
       77│         chosen = max(links, key=lambda link: self._sort_key(package, link))
       78│ 

Cannot install torch.

And it fails. I tried a similiar approach for torch-cpu and it doesn't work neither with the same error:

> poetry source add --priority=explicit pytorch-cpu-src https://download.pytorch.org/whl/cpu
> poetry add --source pytorch-cpu-src torch

Using version ^2.3.1+cpu for torch

Updating dependencies
Resolving dependencies... (1.9s)

Package operations: 1 install, 0 updates, 0 removals

  - Installing torch (2.3.1+cpu): Failed

  RuntimeError

  Unable to find installation candidates for torch (2.3.1+cpu)

  at ~/.local/pipx/venvs/poetry/lib/python3.12/site-packages/poetry/installation/chooser.py:74 in choose_for
       70│ 
       71│             links.append(link)
       72│ 
       73│         if not links:
    →  74│             raise RuntimeError(f"Unable to find installation candidates for {package}")
       75│ 
       76│         # Get the best link
       77│         chosen = max(links, key=lambda link: self._sort_key(package, link))
       78│ 

Cannot install torch.

There are some older threads on the same issue but none of them helped me out here.

Workarounds

No.

Poetry Installation Method

pipx

Operating System

MacOS Sonoma 14.5

Poetry Version

1.8.3

Poetry Configuration

cache-dir = "/Users/XXX/Library/Caches/pypoetry"
experimental.system-git-client = false
installer.max-workers = null
installer.modern-installation = true
installer.no-binary = null
installer.parallel = true
keyring.enabled = true
repositories.XXXX-internal-packages.url = "https://XXXX"
repositories.XXXX.url = "XXXX"
repositories.pytorch-cpu-src.url = "https://download.pytorch.org/whl/cpu"
solver.lazy-wheel = true
virtualenvs.create = true
virtualenvs.in-project = true
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs"  # /Users/XXX/Library/Caches/pypoetry/virtualenvs
virtualenvs.prefer-active-python = true
virtualenvs.prompt = "{project_name}-py{python_version}"
warnings.export = true

Python Sysconfig

No response

Example pyproject.toml

[tool.poetry]
name = "my-cool-app"
version = "0.1.12"
description = "Sample"
authors = []
readme = "README.md"
packages = [
    {include = "api", from = "src"},
]


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"


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


[tool.poetry.dependencies]
python = "^3.12.0"

Poetry Runtime Logs

Using version ^2.3.1+cpu for torch

Updating dependencies
Resolving dependencies... (1.9s)

Package operations: 1 install, 0 updates, 0 removals

  - Installing torch (2.3.1+cpu): Failed

  RuntimeError

  Unable to find installation candidates for torch (2.3.1+cpu)

  at ~/.local/pipx/venvs/poetry/lib/python3.12/site-packages/poetry/installation/chooser.py:74 in choose_for
       70│ 
       71│             links.append(link)
       72│ 
       73│         if not links:
    →  74│             raise RuntimeError(f"Unable to find installation candidates for {package}")
       75│ 
       76│         # Get the best link
       77│         chosen = max(links, key=lambda link: self._sort_key(package, link))
       78│ 

Cannot install torch.

NOTE:

  • I already tried other torch versions and they fail too.
  • Installing torch package fully works fine: poetry add torch with no explicit source. But this installs gpu dependencies which I don't want.
@masoudghaffarinia masoudghaffarinia added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jul 19, 2024
@masoudghaffarinia masoudghaffarinia changed the title Torch 2.3.1 Cpu only cannot be installed Poetry torch 2.3.1 cpu-only or gpu-only installation fails. Jul 19, 2024
@masoudghaffarinia masoudghaffarinia changed the title Poetry torch 2.3.1 cpu-only or gpu-only installation fails. Poetry torch cpu-only or gpu-only installation fails. Jul 19, 2024
@dimbleby
Copy link
Contributor

duplicate pytorch/pytorch#110004, please report it to pytorch

@dimbleby
Copy link
Contributor

Also duplicate of #9524, please close

@david-waterworth
Copy link

Note the first issue you linked was closed by torch in February (i.e. well before you linked to it) - they don't see this as a torch issue it would appear. Possibly because the m-series mac's have integrated GPU's that support ML so there's no seperate CPU/GPU version of torch for macos unlike linux/windows.

@dimbleby
Copy link
Contributor

PyTorch should work well with poetry in 2.1 and above. If this is not the case, please do not hesitate to file a separate issue

Sounds to me as though the torch folk are willing to engage on this, you won't know if you don't try

@masoudghaffarinia
Copy link
Author

So, this is a torch issue and not poetry? Torch with pip3 works fine though.

@dimbleby
Copy link
Contributor

poetry and pip are not doing the same thing. If pip is working for you - great! - use pip!

this is a duplicate of lots of issues both open and closed, please close

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

3 participants