How to install Pytorch with cuda support through CondaPkg

Hi All,

I would like to ask, if anyone knows how to install pytorch with cuda support through CondaPkg. It has to happen that I need to call some language models and I have opted to use transformers from HuggingFace, as sad as it can be. But I have spent quite few days figuring out, how to install pytorch with cuda support, because if I do just ] conda add pytorch, it CondaPkg will install torch without CUDA support. I have ended manually editing .CondaPkg/pixi.toml, add line

[system-requirements]
cuda = "12.4"

and than invoking

~/.julia/artifacts/cefba4912c2b400756d043a2563ef77a0088866b/bin/pixi add pytorch transformers accelerate

in the .CondaPkg directory. Ugly hack indeed it is, but it made it work at least. But if possible, I would like to know the correct solution.

Thanks for answer.
Best wishes.

There’s nothing in CondaPkg for this directly, no.

Looks like those settings are implemented as conda virtual packages. I wonder if you can add a virtual package in the same way, try CondaPkg.add("__cuda", version="12.4")?

If that doesn’t work, we could easily enough add settings to CondaPkg for CUDA versions etc.

You can set the environment variable CONDA_OVERRIDE_CUDA=12.1 which appears to be supported by conda, mamba AND pixi.

You can also just add the pytorch-gpu package to your project I think.

Hi,

thankfor answer. I have tried pytorch-gpu, but that did not work. I will try to other solutions.

Hi, has any solution for installing Pytorch with CUDA support been found?

Hi,

I have succeeded and it was such a hack that I have even written short memo, how to do it. My goal was to run vllm though pythoncall, but then I abandoned this and used vllm as a server. Nevertheless I have dug the notes and they were like this.

I think the whole trick was somehow install PythonCall (with its related CondaPkg), and not install anything through the CondaPkd (in other words exit julia).

Before installing anything, pixi requires to have following line
in file .CondaPkg/pixi.toml

[system-requirements]
cuda = "12.4"

which somehow tells the pixi to install conda

Then I have installed the packages I wanted by manually running pixi from command line as

~/.julia/artifacts/cefba4912c2b400756d043a2563ef77a0088866b/bin/pixi add pytorch transformers accelerate sentence-transformers sentencepiece
~/.julia/artifacts/cefba4912c2b400756d043a2563ef77a0088866b/bin/pixi add pytorch-gpu

and I think that after this, I had a working system. Though this was super ugly.

Not sure this helps.

Hi, thanks for the reply!

That was the path I was following initially as well, but in the meantime I found that installing PyTorch as a Pip package with a forced wheel (instead of a Conda package) works. For example:

CondaPkg.add_pip("torch", version="@https://download-r2.pytorch.org/whl/cu126/torch-2.8.0%2Bcu126-cp312-cp312-manylinux_2_28_x86_64.whl")
CondaPkg.add_pip("torchvision")

Later, I had to install another pip package that required local compilation, so I ended up fiddling with pixi and uv manually anyway :smiley:

Glad you. make it work.
I was sure my notes above are not going to work.

This should be fixed by Fix Pixi platform detection for CUDA environments - Pull Request #238 - JuliaPy/CondaPkg.jl - GitHub.

Please give it a try and let me know:

pkg> add CondaPkg#main
pkg> conda add pytorch-gpu