1

I'm trying to set up a Python project using uv and pyproject.toml on Windows. I want to install the CUDA-enabled PyTorch, but after installing, when I check the version, it shows CPU-only.

Here’s my pyproject.toml setup:

[project]
name = "transformerpractice"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
    "en-core-web-sm",
    "ko-core-news-sm",
    "openpyxl>=3.1.5",
    "pandas>=2.3.3",
    "spacy>=3.8.8",
    "torchtext==0.16.0",
    "torch==2.1.0",
]

[tool.uv.sources]
en-core-web-sm = { url = "https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.8.0/en_core_web_sm-3.8.0.tar.gz" }
ko-core-news-sm = { path = "tokenizer/ko_core_news_sm-3.8.0-py3-none-any.whl" }
torch = [
  { index = "pytorch-cu121", marker = "sys_platform == 'win_amd64'" },
]

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

After installing, I run:

import torch

print(torch.__version__)
print(torch.version.cuda)

And the output is:

2.1.0+cpu
None

It seems like the CPU version is installed, not the CUDA version.

What I tried:

  1. Specifying the PyTorch version with torch==2.1.0 in [project.dependencies].

  2. Adding a custom PyTorch index with CUDA support using [tool.uv.index].

  3. Checking that I'm on Windows 64-bit (sys_platform == 'win_amd64').

Question:

How can I configure pyproject.toml with uv so that it installs the CUDA-enabled PyTorch (2.1.0+cu121) on Windows?

Any guidance on how uv handles extra indices and platform markers for PyTorch would be helpful.

New contributor
wonone11 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
6
  • This is a wild guess: (1) The marker sys_platform is equivalent to sys.platform at runtime (see here). (2) Apparently, sys.platform is always "win32" on Windows, both on 32bit and 64bit systems (see this answer). So I would assume you need to change "win_amd64" to "win32" in sys_platform. Unfortunately, I cannot test this myself, since I am on a Linux system. Maybe check what print(sys.platform) shows on your system, to confirm my guess. Commented Nov 25 at 9:27
  • This would also explain why it doesn't work in your case: Since your actual platform (namely, "win32") differs from the one you specify for using the "pytorch-cu121" index (namely, "win_amd64") the index is not used and the standard PyTorch package (which is the CPU version) is installed instead. Commented Nov 25 at 9:33
  • Alternatively, if you do not plan to use your project's pyproject.toml with different operating systems, anyway, I guess you could skip the marker entry altogether, only keeping the index entry for torch. Commented Nov 25 at 10:09
  • I tried removing the marker or changing it to "win32", but then I got the following error: error: Distribution triton==2.1.0 @ registry+https://pypi.org/simple can't be installed because it doesn't have a source distribution or wheel for the current platform hint: You're on Windows (win_amd64), but triton (v2.1.0) only has wheels for the following platforms: manylinux_2_17_x86_64, manylinux2014_x86_64; consider adding "sys_platform == 'win32' and platform_machine == 'AMD64'" to tool.uv.required-environments to ensure uv resolves to a version with compatible wheels Commented Nov 25 at 11:18
  • So even with the marker fixed, the triton dependency is not available for Windows wheels, and uv fails to install PyTorch with CUDA. Commented Nov 25 at 11:19

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.