Pytorch and Pytorchvision Compatibility in a Stable Diffusion

Thanks in advance for any help. I’m using Ubuntu 22.04 for this.

The error I’m getting is Couldn’t load custom C++ ops. This can happen if your PyTorch and torchvision versions are incompatible, or if you had errors while compiling torchvision from source. For further information on the compatible versions, check GitHub - pytorch/vision: Datasets, Transforms and Models specific to Computer Vision for the compatibility matrix.

Been trying to fix this for a couple of days with no luck.

Torch is 3.1.2+Cuda12.1
Torchvision is 0.16.2+Cuda12.1
Python is 3.10.12

Compatibility Matrix shows this should work. Nvidia Drivers:

NVRM version: NVIDIA UNIX x86_64 Kernel Module 535.154.05 Thu Dec 28 15:37:48 UTC 2023
GCC version: gcc version 12.3.0 (Ubuntu 12.3.0-1ubuntu1~22.04)

Is there other information needed to help solve this? I’m relatively new to all of this.

Could you describe which custom C++ ops you are trying to use and ideally post a minimal and executable code snippet to reproduce the issue?

You might mean 2.1.2+cu121.

I don’t see any CUDA/NVIDIA driver issue in the error message but a potential version mismatch between PyTorch and torchvision.

Thanks for the responding, sorry for taking so long to get back, was on vacation.

I’m pretty new to all of this, so I’m sure I won’t answer your question properly, but I do think I found the problem, I just don’t know how to fix it. I’m trying to run Automatic 1111 (stable diffusion) and I believe I’ve installed it in a virtual environment (at least I think that’s what venv means). The torch and torchvision models in the venv folder I’ve discovered are incompatible. I have torchvision 0.15.2+cu118 and torch is 2.1.2+cu121, so I’m hoping this is my problem.

I think what I did is install the correct versions of the cuda, torch and torchvision inside Ubuntu, but didn’t realize I needed the correct ones in this virtual environment. Before I screw something up, could you maybe point me in the right direction for updating everything inside this virtual environment, providing you think this is my actual problem?

Thank you!

You don’t need to install a CUDA toolkit unless you want to build a custom CUDA extension or PyTorch from source.
However, it’s still unclear if that’s the case.

If you want to install matching torch and torchvision versions, use the install commands from here.

1 Like

Got it! Problem is fixed. Thank you so much!

1 Like