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

username: Mario_Marietto
cooked: <p>Hello to everyone.</p>
<p>I’m trying to clone and install the “<strong>Stable Diffusion web UI</strong>” on FreeBSD,following this mini tutorial :</p>
<aside class="onebox allowlistedgeneric" data-onebox-src="https://github.com/AUTOMATIC1111/stable-diffusion-webui">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="32" height="32">

      <a href="https://github.com/AUTOMATIC1111/stable-diffusion-webui" target="_blank" rel="noopener nofollow ugc">GitHub</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/345;"><img src="https://opengraph.githubassets.com/4738fe0d0fde754283d030f189c24b8f8f2613db844ca79858bd4c20a0ee64bf/AUTOMATIC1111/stable-diffusion-webui" class="thumbnail" width="690" height="345"></div>

<h3><a href="https://github.com/AUTOMATIC1111/stable-diffusion-webui" target="_blank" rel="noopener nofollow ugc">GitHub - AUTOMATIC1111/stable-diffusion-webui: Stable Diffusion web UI</a></h3>

  <p>Stable Diffusion web UI. Contribute to AUTOMATIC1111/stable-diffusion-webui development by creating an account on GitHub.</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>This is what I came up with :</p>
<pre><code class="lang-auto">[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
</code></pre>
<p>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).</p>
<p>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…</p>
<p><a href="https://pastebin.com/raw/jTNQ62dM" class="onebox" target="_blank" rel="noopener nofollow ugc">https://pastebin.com/raw/jTNQ62dM</a></p>
<p>Apparently it’s trying to install pytorch but can’t. I don’t know what to do next.</p>

username: pentachris
cooked: <p>Did you try to install pytorch manually on <a href="https://pytorch.org/" rel="noopener nofollow ugc">PyTorch</a> with pip?</p>

username: Mario_Marietto
cooked: <pre><code class="lang-auto">(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
  ╰─&gt; [6 lines of output]
      Traceback (most recent call last):
        File "&lt;string&gt;", line 2, in &lt;module&gt;
        File "&lt;pip-setuptools-caller&gt;", line 34, in &lt;module&gt;
        File "/tmp/pip-install-yfgsmj5x/pytorch_628b1eae21ac41e48637a8e3262676de/setup.py", line 11, in &lt;module&gt;
          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.
╰─&gt; pytorch

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

username: ptrblck
cooked: <p>The desired file if stored at the same URL <a href="https://download.pytorch.org/whl/cu113/torch-1.12.1%2Bcu113-cp39-cp39-linux_x86_64.whl">here</a> so I don’t know why your environment has trouble accessing this wheel, but you might want to manually download and install it instead.</p>

username: Mario_Marietto
cooked: <p>The file you mentioned is called “<strong>torch-1.12.1+cu113-cp39-cp39-linux_x86_64.whl</strong>” and it seems created for linux. But I’m using FreeBSD. The script also need another file,called “<strong>torchvision==0.13.1+cu113</strong>” ; this file is not even present for linux. I see only two files of this kind,one is for macos (<strong>torchvision-0.13.1-cp39-cp39-macosx_10_9_x86_64.whl</strong>) and the other one is for arch64 : (<strong>torchvision-0.13.1-cp39-cp39-manylinux2014_aarch64.whl</strong>). 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.</p>

username: JonathanSum
cooked: <p>Maybe you can use a Linux solution for FreeBSD.<br>
<a href="https://wiki.freebsd.org/LinuxJails" class="onebox" target="_blank" rel="noopener nofollow ugc">https://wiki.freebsd.org/LinuxJails</a></p>

username: Mario_Marietto
cooked: <p>Hello.</p>
<p>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.</p>

username: ptrblck
cooked: <p>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.</p>

username: Mario_Marietto
cooked: <p>I’ve asked to <a href="mailto:ports@freebsd.org">ports@freebsd.org</a>. He told me : " I have tried quickly build the PyTorch on FreeBSD but it did<br>
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.</p>

username: JonathanSum
cooked: <p>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.</p>

username: Mario_Marietto
cooked: <p>Hello again.</p>
<p>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 :</p>
<aside class="onebox allowlistedgeneric" data-onebox-src="https://github.com/verm/freebsd-stable-diffusion">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="32" height="32">

      <a href="https://github.com/verm/freebsd-stable-diffusion" target="_blank" rel="noopener nofollow ugc">GitHub</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/345;"><img src="https://opengraph.githubassets.com/02a11e34d185a18dafc5ea8efec88cb3ba79346e41dbd9b7415d226779c3bd48/verm/freebsd-stable-diffusion" class="thumbnail" width="690" height="345"></div>

<h3><a href="https://github.com/verm/freebsd-stable-diffusion" target="_blank" rel="noopener nofollow ugc">GitHub - verm/freebsd-stable-diffusion: Stable Diffusion on FreeBSD with CUDA...</a></h3>

  <p>Stable Diffusion on FreeBSD with CUDA support. Contribute to verm/freebsd-stable-diffusion development by creating an account on GitHub.</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>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 :</p>
<aside class="onebox githubissue" data-onebox-src="https://github.com/verm/freebsd-stable-diffusion/issues/2">
  <header class="source">

      <a href="https://github.com/verm/freebsd-stable-diffusion/issues/2" target="_blank" rel="noopener nofollow ugc">github.com/verm/freebsd-stable-diffusion</a>
  </header>

  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Issue">
	  <svg width="60" height="60" class="github-icon" viewbox="0 0 14 16" aria-hidden="true"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/verm/freebsd-stable-diffusion/issues/2" target="_blank" rel="noopener nofollow ugc">RuntimeError: Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2023-01-02" data-time="23:35:16" data-timezone="UTC">11:35PM - 02 Jan 23 UTC</span>
      </div>


      <div class="user">
        <a href="https://github.com/Marietto2008" target="_blank" rel="noopener nofollow ugc">
          <img alt="Marietto2008" src="https://avatars.githubusercontent.com/u/755339?v=4" class="onebox-avatar-inline" width="20" height="20">
          Marietto2008
        </a>
      </div>
    </div>

    <div class="labels">
    </div>
  </div>
</div>

  <div class="github-row">
    <p class="github-body-container">Hello.

you say to do :

`# /compat/linux/bin/cc --sysroot=/compat/linux -m6<span class="show-more-container"><a href="" rel="noopener" class="show-more">…</a></span><span class="excerpt hidden">4 -std=c99 -Wall -ldl -fPIC -shared -o dummy-uvm.so uvm_ioctl_override.c`

but in the instructions you haven't included the file **dummy-uvm.so**,but only the file **uvm_ioctl_override.c**

where I can get the missing file ? thanks.</span></p>
  </div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>long story short,this is what happens in my case :</p>
<pre><code class="lang-auto">[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 "&lt;string&gt;", line 1, in &lt;module&gt;
  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
</code></pre>
<p>he suggested to :</p>
<p><strong>“you may need to use the BUS ID”</strong></p>
<p>ok. How ?</p>