PyTorch RISC-V support

Hi, it’s Alex from SiFive.

We’ve successfully built PyTorch v2.4.0 for RISC-V on Ubuntu QEMU and have run some AI models. We have some demo snapshots for Stable Diffusion.

Stable Diffusion on RISC-V QEMU:

We’re planning to contribute PyTorch support for RISC-V by submitting patches that include test scripts for CI, Docker images, build scripts, and documentation to guide users in building RISC-V PyTorch.

Any feedback or suggestions for PyTorch RISC-V support?

Hi Alex,

I am interesting in testing this out on keystone riscv. Can you share your build process?

Hi SDK,

The related patches are ongoing. I will update this thread with any updates.

Hi SDK,
Unfortunately, the PR#140816 was closed, and we are looking for an alternative way.

hey @AlexChiang I checked the PR and there are only additions to CI, no patch to source code itself. Does that mean that PyTorch can be built to riscv64 without any patches? Or do you have uncommitted patches?

Thanks

Hi @tuler, you absolutely can build PyTorch without any patches, natively on riscv and even run the benchmark test. I follow steps 4 and 5 of this GitHub repo that also releases prebuilt whl packages (I build my own) GitHub - KumaTea/pytorch-riscv64: PyTorch wheels for linux riscv64. I have tested this on 2.5.1, the 2.6-rc series and on main as well.

Here you can see the output of the benchmark, having to modify the value of timeout in env.

(I tried to add another screenshot of how btop looks on my milkv pioneer with 64 cores, but I can only do one image per post. Anyway, it was only eye candy.)

Any other tests that I can run agains PyTorch on riscv that could help out?

Hi @tuler,
Sorry for the late reply.

As @fede2cr mentioned, we can build PyTorch without any patches on RISC-V.

You can report the issue, if you encounter any problem when building it.

1 Like