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:
Specifying the PyTorch version with
torch==2.1.0in[project.dependencies].Adding a custom PyTorch index with CUDA support using
[tool.uv.index].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.
sys_platformis equivalent tosys.platformat runtime (see here). (2) Apparently,sys.platformis 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" insys_platform. Unfortunately, I cannot test this myself, since I am on a Linux system. Maybe check whatprint(sys.platform)shows on your system, to confirm my guess.pyproject.tomlwith different operating systems, anyway, I guess you could skip themarkerentry altogether, only keeping theindexentry fortorch.triton==2.1.0 @ registry+https://pypi.org/simplecan't be installed because it doesn't have a source distribution or wheel for the current platform hint: You're on Windows (win_amd64), buttriton(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'" totool.uv.required-environmentsto ensure uv resolves to a version with compatible wheels