Live data from Hacker News

How I solved PyTorch's cross-platform nightmare

svana.name

11–20 of 30 posts

Re: How I solved PyTorch's cross-platform nightmare

#11
post #4

> Cross-Platform cpu = [ "torch @ ; python_version == '3.12'", "torch @ ; python_version == '3.13'", ] :-/ It reminds me of Microsoft calling their thing "cross platform" because it works on several copies of Windows In all seriousness, I get the impression that pytorch is such a monster PITA to manage because it cares so much about the target hardware. It'd be like a blog post saying "I solved the assembly language…

https://github.com/pypa/manylinux is for building cross-platform wheels.

Re: How I solved PyTorch's cross-platform nightmare

#12

> Setting up a Python project that relies on PyTorch, so that it works across different accelerators and operating systems, is a nightmare. I would like to add some anecdata to this. When I was a PhD student, I already had 12 years of using and administrating Linuxes as my personal OS, and I'd already had my share of package manager and dependency woes. But managing Python, PyTorch, and CUDA dependencies were relativ…

Wake up, lynndotpy

Re: How I solved PyTorch's cross-platform nightmare

#14
https://pypi.org/p/torchruntime might help here, it's designed precisely for this purpose.

`pip install torchruntime`

`torchruntime install torch`

It figures out the correct torch to install on the user's PC, factoring in the OS (Win, Linux, Mac), the GPU vendor (NVIDIA, AMD, Intel) and the GPU model (especially for ROCm, whose configuration varies per generation and ROCm version).

And it tries to support quite a number of older GPUs as well, which are pinned to older versions of torch.

It's used by a few cross-platform torch-based consumer apps, running on quite a number of consumer installations.

Re: How I solved PyTorch's cross-platform nightmare

#15
post #11
post #4

> Cross-Platform cpu = [ "torch @ ; python_version == '3.12'", "torch @ ; python_version == '3.13'", ] :-/ It reminds me of Microsoft calling their thing "cross platform" because it works on several copies of Windows In all seriousness, I get the impression that pytorch is such a monster PITA to manage because it cares so much about the target hardware. It'd be like a blog post saying "I solved the assembly language…

https://github.com/pypa/manylinux is for building cross-platform wheels.

> Python wheels that work on any linux (almost)

So, you're doubling down on OP's misnomer of "cross platform means whatever platforms I use", eh?

Re: How I solved PyTorch's cross-platform nightmare

#16
post #4

> Cross-Platform cpu = [ "torch @ ; python_version == '3.12'", "torch @ ; python_version == '3.13'", ] :-/ It reminds me of Microsoft calling their thing "cross platform" because it works on several copies of Windows In all seriousness, I get the impression that pytorch is such a monster PITA to manage because it cares so much about the target hardware. It'd be like a blog post saying "I solved the assembly language…

I think a more charitable interpretation of TFA would be: "I Have Come Up With A Recipe for Solving PyTorch's Cross-Platform Nightmare"

That is: there's nothing stopping the author from building on the approach he shares to also include Windows/FreeBSD/NetBSD/whatever.

It's his project (FileChat), and I would guess he uses Linux. It's natural that he'd solve this problem for the platforms he uses, and for which wheels are readily available.

Re: How I solved PyTorch's cross-platform nightmare

#17
I maintain a package that provides some PyTorch operators that are written in C/C++/CUDA. I have tried various approaches over the years (including the ones endorsed by PyTorch), but the only solution I have found that seems to work flawlessly for everyone who uses it is to have no Python or PyTorch dependence in the compiled code, and to load the compiled libraries using ctypes. I use an old version of nvcc to compile the CUDA, use manylinux2014 for the Linux builds, and ask users to install PyTorch themselves before installing my package.

Re: How I solved PyTorch's cross-platform nightmare

#18
post #7
post #4

> Cross-Platform cpu = [ "torch @ ; python_version == '3.12'", "torch @ ; python_version == '3.13'", ] :-/ It reminds me of Microsoft calling their thing "cross platform" because it works on several copies of Windows In all seriousness, I get the impression that pytorch is such a monster PITA to manage because it cares so much about the target hardware. It'd be like a blog post saying "I solved the assembly language…

Torch simply has to work this way because it cares about performance on a combination of multiple systems and dozens of GPUs. The complexity leaks into packaging. If you do not care about performance and would rather have portability, use an alternative like tinygrad that does not optimize for every accelerator under the sun. This need for hardware-specific optimization is also why the assembly language analogy is a…

> Torch simply has to work this way because it cares about performance on a combination of multiple systems and dozens of GPUs

Or, looked at a different way, Torch has to work this way because Python packaging has too narrow of an understanding of platforms which treats many things that are materially different platforms as the same platform.

Re: How I solved PyTorch's cross-platform nightmare

#19

> Setting up a Python project that relies on PyTorch, so that it works across different accelerators and operating systems, is a nightmare. I would like to add some anecdata to this. When I was a PhD student, I already had 12 years of using and administrating Linuxes as my personal OS, and I'd already had my share of package manager and dependency woes. But managing Python, PyTorch, and CUDA dependencies were relativ…

Wake up, lynndotpy

Follow the white rabbit.

Re: How I solved PyTorch's cross-platform nightmare

#20
post #15
post #11

Earlier quoted context omitted.

https://github.com/pypa/manylinux is for building cross-platform wheels.

> Python wheels that work on any linux (almost) So, you're doubling down on OP's misnomer of "cross platform means whatever platforms I use", eh?

I do not know what you are objecting to. I have successfully packaged wheels for MacOS and Ubuntu with manylinux. I presume it works with some others too, but that is what I can personally attest to. Alpine is catered to by the musllinux project.

You should be specific about which distributions you have in mind.

Post reply on HN