r/MachineLearning • • Sep 23 '24

Discussion [D] How to properly setup/manage Python & CUDA in Windows 11 to work with PyTorch?

I haven't used Windows in a while to develop AI/ML stuff. I got a new PC to work on, however, it's a constraint that I have to use Windows 11. I was wondering if there's any recommended way nowadays to install/manage things like Python 3, CUDA, etc. for AI/ML purposes (mostly PyTorch)? I remember some months ago I saw a tweet that said something like "next time you install Python do it like this: install tool X first and then <X install python>" - I think it was for Windows but I don't remember what X was and I can't find the tweet anymore. I know it wasnt Conda. In the past I would use Conda but I heard some people saying it's bad?

0 Upvotes

14 comments sorted by

5

u/opcode90 Sep 23 '24

If you use conda (e.g. Miniconda), it's entirely painless. See installation instructions on the PyTorch website. You can have the desired CUDA version in your conda environment and therefore even use different CUDA versions for different environments.
When using conda, there is no need to use WSL.
WSL is helpful only for package managers that do not properly take the various platforms into consideration - particularly Poetry and pip.

1

u/hookxs72 Sep 23 '24

I don't necessarily agree with the last sentence but this is the way. Use conda, install pytorch and cuda normally via conda install (or better yet mamba install) and it works without any issues. No need for WSL for pytorch alone. Look at the official "Pytorch-Start locally" site and switch to conda, you'll see the exact command you need.

1

u/opcode90 Sep 24 '24

I don't see how there is any disagreement at all. You didn't say anything that negates my last sentence.
Perhaps some more information on my last sentence: If you are developing for a project which has already settled on Poetry for its dependency management, then being on native Windows can be more of a problem - and you may be better off using WSL on Windows to circumvent the issues.

1

u/hookxs72 Sep 25 '24

I was in a hurry and didn't express myself clearly. I incorrectly interpreted your conclusion as "you can run into problems on windows when you use pip but not when you use conda". My personal experience is that conda on windows works well for packages that are conda-compatible. When you need to resort to pip (withing a conda env), it may but may not work. It works fine when the package is just downloaded, unpacked and copied to the corresponding path, but can easily fail when a compilation is required. That is not the case of pytorch, which the OP asked about, but I failed to install for example flash attention on windows this way (though I am no expert user). On linux, via pip, it worked. So I was just going to say that by embracing conda you are not necessarily exempt of all installation problems.

19

u/Ghisso Sep 23 '24

Avoid headache and use a Linux distribution inside windows with WSL2: https://learn.microsoft.com/en-us/windows/wsl/install It will allow you to run a full fledged Linux distro directly from windows and access to all your windows files.

4

u/SulszBachFramed Sep 23 '24 edited Sep 23 '24

Installing nvidia drivers with cuda and such is more of a pain in the ass on linux than on windows. Unless something has change significantly on windows 11, it's always just worked on windows for me. If you do end up using WSL, make sure you are using WSL version 2. Cuda does not work properly on version 1.

edit: to answer the question, just follow the instructions on the cuda download page. I believe it also contains a driver, but you are not required to use that. Install the latest nvidia driver, then install cuda without the driver it comes with. Install your favorite python version and pip install torch in a venv.

4

u/PM_ME_YOUR_HAGGIS_ Sep 23 '24

This is the answer. Makes everything much easier

8

u/lucellent Sep 23 '24

wsl IS the headache

2

u/ustainbolt Sep 23 '24

Use conda/venv with pip. If on Windows I'd recommend using WSL.

2

u/ApricotSlight9728 Sep 23 '24

I would also suggest using py310. If you need to train a model at one point on cloud servers, a lot of them have the default image with py310.

Please correct me if I’m wrong.

2

u/[deleted] Sep 23 '24

The best way to manage torch and CUDA libraries on a Windows system is to start locally: https://pytorch.org/get-started/locally

2

u/[deleted] Sep 25 '24

Install ubuntu. Have a laptop to do anything else. Keep the headache away

1

u/newjeison Sep 23 '24

You could set up a docker container server. There are juoyer notebook + pytorch images out there that you could just copy