The installation of "Stable Diffusion web UI" natively on FreeBSD fails because can't install torch and torchvision

Hello to everyone.

I’m trying to clone and install the “Stable Diffusion web UI” on FreeBSD,following this mini tutorial :

This is what I came up with :

[marietto@marietto ~/Desktop/Files]$ git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui

[marietto@marietto ~/Desktop/Files]$ cd stable-diffusion-webui

[marietto@marietto ~/Desktop/Files/stable-diffusion-webui]$ sudo pkg install py39-pytorchvideo

[marietto@marietto ~/Desktop/Files/stable-diffusion-webui]$ mkdir venv

[marietto@marietto ~/Desktop/Files/stable-diffusion-webui]$ python3 -m venv venv

[marietto@marietto ~/Desktop/Files/stable-diffusion-webui]$ . venv/bin/activate

(venv) [marietto@marietto ~/Desktop/Files/stable-diffusion-webui]$ python3 -m pip install torch torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113

Looking in indexes: https://pypi.org/simple,https:/download.pytorch.org/whl/cu113

ERROR: Could not find a version that satisfies the requirement torch (from versions: none)

ERROR: No matching distribution found for torch

The script works up to a point and then devolves into stuff that I don’t think has much to do with FreeBSD. The venv gets created and the failure doesn’t happen until the very end of the script (where the app would take over).

Also just activating the virtual environment and manually running [launch.py] seems to result in the same error, which really looks to be issues with the world of python…

https://pastebin.com/raw/jTNQ62dM

Apparently it’s trying to install pytorch but can’t. I don’t know what to do next.

Did you try to install pytorch manually on PyTorch with pip?

(venv) [marietto@marietto ~/Desktop/Files/stable-diffusion-webui]$ python3 -m pip install pytorch
Collecting pytorch
  Downloading pytorch-1.0.2.tar.gz (689 bytes)
  Preparing metadata (setup.py) ... done
Installing collected packages: pytorch
  DEPRECATION: pytorch is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
  Running setup.py install for pytorch ... error
  error: subprocess-exited-with-error
  
  × Running setup.py install for pytorch did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-yfgsmj5x/pytorch_628b1eae21ac41e48637a8e3262676de/setup.py", line 11, in <module>
          raise Exception(message)
      Exception: You tried to install "pytorch". The package named for PyTorch is "torch"
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> pytorch

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

The desired file if stored at the same URL here so I don’t know why your environment has trouble accessing this wheel, but you might want to manually download and install it instead.

The file you mentioned is called “torch-1.12.1+cu113-cp39-cp39-linux_x86_64.whl” and it seems created for linux. But I’m using FreeBSD. The script also need another file,called “torchvision==0.13.1+cu113” ; this file is not even present for linux. I see only two files of this kind,one is for macos (torchvision-0.13.1-cp39-cp39-macosx_10_9_x86_64.whl) and the other one is for arch64 : (torchvision-0.13.1-cp39-cp39-manylinux2014_aarch64.whl). It seems no one created the specific files for freebsd. I don’t know who could do that. If the freebsd or the python developers,but I think that’s not good that no one did it.

Maybe you can use a Linux solution for FreeBSD.
https://wiki.freebsd.org/LinuxJails

Hello.

instead of using jails,its a better idea to bootup a bhyve VM based on Linux. Bhyve works great,it’s easier to configure than jails. Anyway I don’t want to use neither Jails nor bhyve. My challenge was to install it natively.

Oh, I didn’t know Linux packages are not compatible with FreeBSD. In this case you might need to try to build PyTorch from source.

I’ve asked to ports@freebsd.org. He told me : " I have tried quickly build the PyTorch on FreeBSD but it did
not build out of the box… that means more work is required to run it here… considering size of the project a person more familiar and interested needs to be found that would create and maintain the PyTorch related ports, sorry, at this point you can try to request a build for FreeBSD on the upstream (but there may be no interest) and use other platform to get things working straight away… you can also spend some time to make it work on FreeBSD what could be a nice learning process :-). So considered that this task requires an high level of programming skills that I don’t have,I think that this is the end of this challenge.

My suggestion is if you do not want to train the model but rather just want to do inferencing. You can try some of the deployment solutions.

Hello again.

in the while I made a lot of progress,asking and asking again I found someone that has gather my solicitations and he decided to write a tutorial about how to install “PyTorch and Stable Diffusion on FreeBSD” and he wrote a tutorial that you can find here :

and I’ve created this thread where I try to fix the problem that I’m having,because I’m not able to replicate the result achieved by the author of the tutorial :

long story short,this is what happens in my case :

[marietto@marietto ~]$ bash
[marietto@marietto ~]$ source /compat/linux/home/marietto/Desktop/stable-diffusion/conda/etc/profile.d/conda.sh
[marietto@marietto ~]$ conda activate
(base) [marietto@marietto ~]$ conda activate pytorch
(pytorch) [marietto@marietto ~]$ LD_PRELOAD=/compat/linux/home/marietto/Desktop/stable-diffusion/dummy-uvm.so python3 -c 'import torch; print(torch.cuda.get_device_name(0))'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/compat/linux/home/marietto/Desktop/stable-diffusion/conda/envs/pytorch/lib/python3.10/site-packages/torch/cuda/__init__.py", line 329, in get_device_name
    return get_device_properties(device).name
  File "/compat/linux/home/marietto/Desktop/stable-diffusion/conda/envs/pytorch/lib/python3.10/site-packages/torch/cuda/__init__.py", line 359, in get_device_properties
    _lazy_init()  # will define _get_device_properties
  File "/compat/linux/home/marietto/Desktop/stable-diffusion/conda/envs/pytorch/lib/python3.10/site-packages/torch/cuda/__init__.py", line 217, in _lazy_init
    torch._C._cuda_init()
RuntimeError: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx

he suggested to :

“you may need to use the BUS ID”

ok. How ?