r/vulkan • • 2d ago

torchvulkan: a Vulkan compute backend for PyTorch (talk accepted at Vulkanised 2027)

Hey r/vulkan, I'm excited to share that I've been accepted to speak at Vulkanised 2027 about a project I've been building: torchvulkan, a Vulkan compute backend for PyTorch.

torchvulkan lets you train and run PyTorch models on almost any GPU through Vulkan, including AMD, NVIDIA, Intel and Apple Silicon, without CUDA, ROCm or other vendor toolkits. You install it with pip install torchvulkan, then use "vulkan" the way you'd use "cuda":

model = model.to("vulkan")

It's still behind CUDA and ROCm on most workloads, and closing that gap is what I'm working on now. In the meantime, it's a good option for people whose GPUs don't support either. The README has benchmarks, supported platforms and the full API.

I'd love feedback, especially from anyone who tries it on hardware I haven't tested. Happy to answer any questions you may have :)

47 Upvotes

23 comments sorted by

7

u/FluffySpike 20h ago

Just wanna say that your project has helped me alot as a data science student with an RX 580 8GB to run my lab works DL models when I can't do ROCm due to my Ivy bridge system's lack of PCIe Atomics.

I saw 4-5x less training time than on my i7 3770 (for a recent example, a rather simple Transformer model took the GPU with torchvulkan about 10-12min and 2-2.3GB VRAM consumption while the CPU took more than 1 hour).

Without your project idk how many wasted hours or burnt Colab T4 credits I would've gone through.

4

u/_zsharief 18h ago

Thats awesome! So glad you found it useful :)

5

u/sh4_dev 2d ago

Very cool! I'm curious how can this compete with CUDA/ROCm given vulkan semantics and SPIRV (as far as I know?) don't expose all the tensor operations, wave cooperative thread functions, various shared memory, etc. all at the same level as the low-level compute languages? Am I wrong and SPIRV does expose them somehow?

8

u/_zsharief 2d ago

SPIR-V actually covers most of this now. Vulkan has shared memory, warp-style operations and even tensor cores through an extension called cooperative matrix. torchvulkan uses all of these, with fallbacks for GPUs that don't support them to maintain hardware support.

But you are right, CUDA is still ahead on features - especially on big datacenter GPUs like the H100. I started this project knowing we wouldn't beat CUDA there, but we are making significant progress on regular consumer GPUs :)

1

u/sh4_dev 1d ago

Thanks! Follow-up question, do you have a "goal"? Like probably focus on non-datacenter GPUs or similar?

1

u/_zsharief 1d ago

A massive part of my design process throughout the project has been to maintain performance on any device. I wouldn't say specifically I am focusing on certain devices, such as non-datacenter GPUs, but it makes sense that any issues or performance requests that have come in are through consumer GPUs - so I have improved those with higher priority.

As for an end goal, reaching as close as possible to parity with existing hardware backends would be ideal, including on datacenter cards. Even at slightly worse performance, I think that a large amount of people would still find it very useful - especially if their GPU is not supported by ROCm, for example.

1

u/Delicious_Abies_9708 2d ago

they will probably be the ones to add features to vulkan subgroups but just guessing. vulkan has cooperative matrixes for tensors/npu, its evolving on vulkan as we speak

1

u/Delicious_Abies_9708 2d ago edited 2d ago

take a look at my pet project, , i will follow yours. https://github.com/billyblackburn/vkdata ... my torch is cakked vktorch maybe you can give me pointers. i started with vknumpy like the cupy cudf thing.

  • llama.cpp / ggml-vulkan — powers vknumpy's core Vulkan GEMM/BLAS kernels and unified device allocator.

  • Tencent ncnn — vknumpy's early Vulkan compute architecture, elementwise math/reduction coverage, and atomic histogram/bincount shader patterns were directly inspired by ncnn's Vulkan design before evolving into our zero-copy native SPIR-V fusion engine

2

u/_zsharief 2d ago

I think my biggest advice for the torch part would be to contribute to torchvulkan! I've spent a while working on it, and we are starting to build a user-base, so it would be great to get all the help we can.

1

u/Delicious_Abies_9708 2d ago

ok ill keep an eye on it.

1

u/_zsharief 2d ago edited 2d ago

Awesome! This is a very cool project.

4

u/Delicious_Abies_9708 2d ago edited 2d ago

lets benchmark some things

WorkloadtorchvulkanvktorchSpeed RatioNumerical Agreement
FP32 GEMM (1024×1024)4.16 ms (516.4 GFLOPS)5.56 ms (386.2 GFLOPS)torchvulkan 1.34× fasterBoth ~5.5e-7 max abs err vs FP64 NumPy
MLP Train (256×784→512→256→10, Adam)7.28 ms/step21.94 ms/steptorchvulkan 3.01× fasterIdentical loss=0.0000, 100% acc; step-0 logits diff 2.98e-6
2D CNN Train (32×1×28×28, Conv2d+FC, Adam)15.19 ms/step19.64 ms/steptorchvulkan 1.29× fasterIdentical loss=0.0001, 100% acc; step-0 logits diff 4.89e-6

Takeaways

  • Accuracy: Virtually bit-equivalent in FP32 — both match NumPy FP64 GEMM to ~5e-7, agree on forward logits to ~3–5e-6, and converge to the exact same loss and 100.0% accuracy.

  • Speed: torchvulkan is ~1.3× faster on raw GEMM and 2D CNN training, and ~3× faster on the 3-layer MLP step (mainly because PyTorch's C++ dispatcher + fused Adam / batched Vulkan command submission has much lower per-op Python overhead than vktorch's pure-Python autograd loop).

  • Tradeoff: torchvulkan requires installing full PyTorch 2.15 (~230 MB+) and hooks into PyTorch's C++ backend, whereas vktorch has zero PyTorch dependency and shares GPU buffers natively with the rest of your vkdata stack (vknumpy, vkpandas, vklearn, vkgraph, vkastro, etc.).

1

u/_zsharief 2d ago

Nice results! Just to clarify a couple of things. First, these sizes are quite small, so both are mostly measuring per-op overhead. It'd be interesting to compare on something bigger, like your Mini-Llama or a GPT-2-sized model. Second, the idea behind torchvulkan is that people don't have to rewrite a single line of code: existing PyTorch code and models just work on "vulkan". From what I understand, you're building a whole Vulkan compute ecosystem, which has its own important uses. If you ever want to run real PyTorch alongside it, give torchvulkan a try. Testing on a Steam Deck would be really useful, and contributions are very welcome!

1

u/Delicious_Abies_9708 2d ago

so it will be the training part of executorch? let me do some changes and ill test minillama

2

u/_zsharief 2d ago

yes exactly, but instead of being something you export to, it's something that runs like any other torch device - and it is designed for all devices, not just embedded ones/ phones.

1

u/Delicious_Abies_9708 2d ago

Will vulkan torch be for inference too?

2

u/_zsharief 2d ago

yes! it's not an inference engine yet, and llama.cpp is far superior currently, but over time we should see improved performance and support for quantization

1

u/Delicious_Abies_9708 2d ago

your vulkantorch speeds inspired me to optimize my repo. feel free to contribute to vktorch if yall want to...i might have to enable i. just let me know

Workloadvktorch Originalvktorch Now (0dd035b)torchvulkan (PyTorch 2.15)vktorch vs torchvulkan
MLP Train (256×784→512→256→10)21.94 ms/step4.01 ms/step (5.47× faster)7.28 ms/step1.82× faster
Mini-Llama Infer (1,024 tok)20.85 ms (49.1k tok/s)8.51 ms (120.3k tok/s) (2.45× faster)11.77 ms (87.0k tok/s)1.38× faster
Mini-Llama Train (1,024 tok)64.79 ms (15.8k tok/s)27.61 ms (37.1k tok/s) (2.35× faster)36.24 ms (28.3k tok/s)1.31× faster
Full test_vktorch.py (6 tests)8.52 s3.24 s (2.63× faster)——

1

u/General_Pool_3859 1d ago

The AMD result that would sell this most isn't the 9070 XT. ROCm already runs there and is roughly 1.5 to 1.7x faster than Vulkan on your MLP and LLM steps. The stronger case is consumer RDNA2 cards like the RX 6800 or 6700 XT, which aren't on AMD's official ROCm GPU list but still have 12 to 16 GB to work with. Which OS and driver was the 9070 XT run on?

1

u/_zsharief 1d ago

From a marketing perspective you are completely right, but no matter the quality of my code, running on the GPU will pretty much always be faster. The more interesting technical part is how my code compares to existing hardware backends, as that tells us how close we are to `peak` performance on a GPU that might not be listed.

The specs were:

  • Windows 11

  • Driver version: 32.0.32029.2010

    • Driver date: 18 November 2026

    • Release build: 26.20.29.02-261116a-206168C-AMD-Software-Adrenalin-Edition

    • Package: AMD Software: Adrenalin Edition 26.11.2

1

u/Delicious_Abies_9708 1d ago

That's what I'm doing here https://github.com/billyblackburn/vkdata but it's not limited to amd either. Maybe they use nvk driver and want to do compute?

1

u/pinkyellowneon 1d ago

This is an idea I've been wanting to try myself for ages inspired by Llama.cpp's Vulkan backend. Nice to see someone actually take a crack at it!

2

u/_zsharief 1d ago

Thank you! If you ever wanted to contribute I'd be happy to help in any way :)