How to install the nvidia driver 525.78.01 + CUDA 12 to run the Automatic 1111 WebUI for Stable Diffusion using Ubuntu instead of CentOS

Hello to everyone.

I've installed the nvidia driver 525.78.01 + CUDA 12 to run the Automatic 1111 webui for Stable Diffusion using Ubuntu instead of CentOS.

Based on :







--> Clean Up Existing Drivers

Code:
# sudo kldunload nvidia-modeset
# sudo kldunload nvidia
# sudo pkg remove -y nvidia-driver nvidia-settings nvidia-xconfig

--> Upgrading nvidia-driver and linux-nvidia-libs to 525.78.01 directly from ports

Code:
# cd /usr/ports/x11/nvidia-driver
# mv Makefile Makefile.orig
# cp Makefile.orig Makefile
# mv distinfo distinfo.orig

# nano Makefile

DISTVERSION?=   525.78.01

# make makesum
# make
# make install

# cd /usr/ports/x11/linux-nvidia-libs
# mv Makefile Makefile.orig
# cp Makefile.orig Makefile
# mv distinfo distinfo.orig

# nano Makefile

DISTVERSION?=   525.78.01

# make makesum
# cp /compat/ubuntu/usr/lib/x86_64-linux-gnu/libnvidia-egl-wayland.so.1.1.9 /usr/ports/x11/linux-nvidia-libs/work/NVIDIA-Linux-x86_64-525.78.01
# make reinstall clean

# Remove nvidia stuff from /boot/loader.conf
sudo sed -i '/nvidia/d' /boot/loader.conf

# Load nvidia modules via /etc/rc.conf
echo 'kld_list+=" nvidia-modeset nvidia "' | sudo tee /etc/rc.conf

# No need to reboot, just load the new drivers
sudo kldload nvidia-modeset

--> Setup Hardware Acceleration

Code:
sudo pkg install libva-utils libva-vdpau-driver vdpauinfo mesa-demos vulkan-tools

--> Setup Ubuntu

Code:
sudo touch /usr/local/etc/rc.d/ubuntu && chmod +x /usr/local/etc/rc.d/ubuntu

# Make it have this content:

#!/bin/sh
#
# PROVIDE: ubuntu
# REQUIRE: archdep mountlate
# KEYWORD: nojail
#
# This is a modified version of /etc/rc.d/linux
# Based on the script by mrclksr:
# https://github.com/mrclksr/linux-browser-installer/blob/main/rc.d/ubuntu.in
#
. /etc/rc.subr

name="ubuntu"
desc="Enable Ubuntu chroot, and Linux ABI"
rcvar="ubuntu_enable"
start_cmd="${name}_start"
stop_cmd=":"

unmounted()
{
    [ `stat -f "%d" "$1"` == `stat -f "%d" "$1/.."` -a \
      `stat -f "%i" "$1"` != `stat -f "%i" "$1/.."` ]
}

ubuntu_start()
{
    local _emul_path _tmpdir

    load_kld -e 'linux(aout|elf)' linux
    case `sysctl -n hw.machine_arch` in
    amd64)
        load_kld -e 'linux64elf' linux64
        ;;
    esac
    if [ -x /compat/ubuntu/sbin/ldconfigDisabled ]; then
        _tmpdir=`mktemp -d -t linux-ldconfig`
        /compat/ubuntu/sbin/ldconfig -C ${_tmpdir}/ld.so.cache
        if ! cmp -s ${_tmpdir}/ld.so.cache /compat/ubuntu/etc/ld.so.cache; then
            cat ${_tmpdir}/ld.so.cache > /compat/ubuntu/etc/ld.so.cache
        fi
        rm -rf ${_tmpdir}
    fi

    # Linux uses the pre-pts(4) tty naming scheme.
    load_kld pty

    # Handle unbranded ELF executables by defaulting to ELFOSABI_LINUX.
    if [ `sysctl -ni kern.elf64.fallback_brand` -eq "-1" ]; then
        sysctl kern.elf64.fallback_brand=3 > /dev/null
    fi

    if [ `sysctl -ni kern.elf32.fallback_brand` -eq "-1" ]; then
        sysctl kern.elf32.fallback_brand=3 > /dev/null
    fi
    sysctl compat.linux.emul_path=/compat/ubuntu

    _emul_path="/compat/ubuntu"
    unmounted "${_emul_path}/dev" && (mount -o nocover -t devfs devfs "${_emul_path}/dev" || exit 1)
    unmounted "${_emul_path}/dev/fd" && (mount -o nocover,linrdlnk -t fdescfs fdescfs "${_emul_path}/dev/fd" || exit 1)
    unmounted "${_emul_path}/dev/shm" && (mount -o nocover,mode=1777 -t tmpfs tmpfs "${_emul_path}/dev/shm" || exit 1)
    unmounted "${_emul_path}/home" && (mount -t nullfs /home "${_emul_path}/home" || exit 1)
    unmounted "${_emul_path}/proc" && (mount -o nocover -t linprocfs linprocfs "${_emul_path}/proc" || exit 1)
    unmounted "${_emul_path}/sys" && (mount -o nocover -t linsysfs linsysfs "${_emul_path}/sys" || exit 1)
    unmounted "${_emul_path}/tmp" && (mount -t nullfs /tmp "${_emul_path}/tmp" || exit 1)
    unmounted /dev/fd && (mount -o nocover -t fdescfs fdescfs /dev/fd || exit 1)
    unmounted /proc && (mount -o nocover -t procfs procfs /proc || exit 1)
    true
}

load_rc_config $name
run_rc_command "$1"

sysrc ubuntu_enable=YES

# Create necessary mount points for a working Linuxulator:
mkdir -p {/compat/ubuntu/dev/fd,/compat/ubuntu/dev/shm,/compat/ubuntu/home,/compat/ubuntu/tmp,/compat/ubuntu/proc,/compat/ubuntu/sys}

# Start Ubuntu service:
service ubuntu start

# Install needed packages:
pkg install debootstrap pulseaudio

# Install Ubuntu 20.04 into /compat/ubuntu:
debootstrap --arch=amd64 --no-check-gpg focal /compat/ubuntu

# Restart Ubuntu service to make sure everything is properly mounted:
service ubuntu restart

# Fix broken symlink:
cd /compat/ubuntu/lib64/ && rm ./ld-linux-x86-64.so.2 ; ln -s ../lib/x86_64-linux-gnu/ld-2.31.so ld-linux-x86-64.so.2

# Chroot into your Linux environment:
chroot /compat/ubuntu /bin/bash

# Set correct timezone inside your chroot:
printf "%b\n" "0.0 0 0.0\n0\nUTC" > /etc/adjtime
sudo dpkg-reconfigure tzdata # For some reason sudo is necessary here, otherwise it fails.

# Fix APT package manager:
printf "APT::Cache-Start 251658240;" > /etc/apt/apt.conf.d/00aptitude

# Enable more repositories:
printf "deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse" > /etc/apt/sources.list

# Install required programs:
apt update ; apt install -y apt-transport-https curl fonts-symbola gnupg pulseaudio build-essential

--> Setup Nvidia Drivers in Linuxulator

Code:
# First setup 32-bit support
dpkg --add-architecture i386
apt update && sudo apt -y upgrade

# Next install NVIDIA drivers using the installation script
mkdir -p /home/user/TMP && rm -rf /home/user/TMP/*
cd /home/user

wget -q "https://us.download.nvidia.com/XFree86/Linux-x86_64/525.78.01/NVIDIA-Linux-x86_64-525.78.01.run"

chmod +x NVIDIA-Linux-x86_64-525.78.01.run

# Install the NVIDIA libraries, binaries, and drivers but skip the kernel modules.

TMPDIR=/home/user/TMP ./NVIDIA-Linux-x86_64-525.78.01.run \
    --install-compat32-libs \
    --no-nvidia-modprobe --no-backup --no-kernel-module \
    --no-x-check --no-nouveau-check \
    --no-cc-version-check --no-kernel-module-source \
    --no-check-for-alternate-installs \
    --install-libglvnd --skip-depmod --no-systemd

# Next install some 64-bit, and 32-bit libraries and tools
apt-get install -y vainfo vdpauinfo vulkan-tools mesa-utils libva2:i386 libvulkan1:i386 libvdpau1:i386

# Lastly we need to download vdpau-va-driver manually from a previous version of Ubuntu because it was removed from Ubuntu 20.x.
# We need this for the vdpau backend for libva

apt-get install -y gdebi
wget -q 'http://archive.ubuntu.com/ubuntu/pool/universe/v/vdpau-video/vdpau-va-driver_0.7.4-6ubuntu1_amd64.deb'
gdebi vdpau-va-driver_0.7.4-6ubuntu1_amd64.deb

wget -q 'http://archive.ubuntu.com/ubuntu/pool/universe/v/vdpau-video/vdpau-va-driver_0.7.4-6ubuntu1_i386.deb'
gdebi vdpau-va-driver_0.7.4-6ubuntu1_i386.deb

# Exit out of chroot
exit

# Fix x86_64-linux-gnu libraries path between ubuntu and freebsd
cp -r /compat/ubuntu/usr/lib/x86_64-linux-gnu /lib

--> Test 64-bit from your normal FreeBSD user account (not root and not inside chroot) inside an X session.

Code:
/compat/ubuntu/usr/bin/nvidia-smi
/compat/ubuntu/usr/bin/glxinfo
/compat/ubuntu/usr/bin/vdpauinfo
/compat/ubuntu/usr/bin/vainfo
/compat/ubuntu/usr/bin/vulkaninfo


--> Test 32-bit


sudo pkg install -y libc6-shim

with-glibc-shim /libexec/ld-elf.so.1 /compat/ubuntu/usr/bin/nvidia-smi
with-glibc-shim /libexec/ld-elf.so.1 /compat/ubuntu/usr/bin/glxinfo
with-glibc-shim /libexec/ld-elf.so.1 /compat/ubuntu/usr/bin/vdpauinfo
with-glibc-shim /libexec/ld-elf.so.1 /compat/ubuntu/usr/bin/vainfo
with-glibc-shim /libexec/ld-elf.so.1 /compat/ubuntu/usr/bin/vulkaninfo


--> Installing PyTorch and Stable Diffusion on FreeBSD

Code:
# pkg install linux-c7-devtools

# fetch https://gist.githubusercontent.com/shkhln/40ef290463e78fb2b0000c60f4ad797e/raw/f640983249607e38af405c95c457ce4afc85c608/uvm_ioctl_override.c

# /compat/ubuntu/bin/gcc --sysroot=/compat/ubuntu -m64 -std=c99 -Wall -ldl -fPIC -shared -o dummy-uvm.so uvm_ioctl_override.c

# pkg install linux-miniconda-installer
# miniconda-installer
# bash
# source /home/marietto/miniconda3/etc/profile.d/conda.sh
# conda activate

(base) # conda activate pytorch

(pytorch) # LD_PRELOAD=/compat/dummy-uvm.so python3 -c 'import torch; print(torch.cuda.is_available())'
True

(pytorch) # LD_PRELOAD=/compat/dummy-uvm.so python3 -c 'import torch; print(torch.cuda.get_device_name(0))'
NVIDIA GeForce RTX 2080 Ti

(pytorch) # conda activate

(base) # conda activate

(base) # git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui

Cloning into 'stable-diffusion-webui'...
remote: Enumerating objects: 16079, done.
remote: Total 16079 (delta 0), reused 0 (delta 0), pack-reused 16079
Receiving objects: 100% (16079/16079), 27.20 MiB | 8.62 MiB/s, done.
Resolving deltas: 100% (11292/11292), done.

(base) # cd /compat/ubuntu/home/marietto/stable-diffusion-webui

(base) # conda env update --file environment-wsl2.yaml --prune

Retrieving notices: ...working... done
Collecting package metadata (repodata.json): done
Solving environment: done

Downloading and Extracting Packages

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate automatic
#
# To deactivate an active environment, use
#
#     $ conda deactivate

(base) # conda activate automatic

(automatic) # which python3
/home/marietto/miniconda3/envs/automatic/bin/python3

(automatic) # conda install git
Collecting package metadata (current_repodata.json): done
Solving environment: done

(automatic) # LD_PRELOAD=/compat/dummy-uvm.so  python3 launch.py

Python 3.10.9 (main, Jan 11 2023, 15:21:40) [GCC 11.2.0]
Commit hash: ea9bd9fc7409109adcd61b897abc2c8881161256
Cloning Stable Diffusion into repositories/stable-diffusion-stability-ai...
Cloning Taming Transformers into repositories/taming-transformers...
Cloning K-diffusion into repositories/k-diffusion...
Cloning CodeFormer into repositories/CodeFormer...
Cloning BLIP into repositories/BLIP...
Installing requirements for Web UI
Launching Web UI with arguments:
No module 'xformers'. Proceeding without it.
/home/marietto/miniconda3/envs/automatic/lib/python3.10/site-packages/psutil/_pslinux.py:513: RuntimeWarning: shared, active, inactive memory stats couldn't be determined and were set to 0
  warnings.warn(msg, RuntimeWarning)
==============================================================================
You are running torch 1.12.1.
The program is tested to work with torch 1.13.1.
To reinstall the desired version, run with commandline flag --reinstall-torch.
Beware that this will cause a lot of large files to be downloaded, as well as
there are reports of issues with training tab on the latest version.

Use --skip-version-check commandline argument to disable this check.
==============================================================================
Calculating sha256 for /compat/ubuntu/home/marietto/stable-diffusion-webui/models/Stable-diffusion/model.ckpt: cc6cb27103417325ff94f52b7a5d2dde45a7515b25c255d8e396c90014281516
Loading weights [cc6cb27103] from /compat/ubuntu/home/marietto/stable-diffusion-webui/models/Stable-diffusion/model.ckpt
Creating model from config: /compat/ubuntu/home/marietto/stable-diffusion-webui/configs/v1-inference.yaml
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Downloading: 100%|█████████████████████████████████████████████████████████| 961k/961k [00:00<00:00, 1.20MB/s]
Downloading: 100%|█████████████████████████████████████████████████████████| 525k/525k [00:00<00:00, 1.10MB/s]
Downloading: 100%|████████████████████████████████████████████████████████████| 389/389 [00:00<00:00, 220kB/s]
Downloading: 100%|████████████████████████████████████████████████████████████| 905/905 [00:00<00:00, 506kB/s]
Downloading: 100%|███████████████████████████████████████████████████████| 4.52k/4.52k [00:00<00:00, 2.38MB/s]
Applying cross attention optimization (Doggettx).
Textual inversion embeddings loaded(0):
Model loaded in 18.6s (calculate hash: 7.4s, load weights from disk: 1.2s, create model: 7.9s, apply weights to model: 0.8s, apply half(): 0.5s, load VAE: 0.1s, move model to device: 0.5s, load textual inversion embeddings: 0.3s).
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
 
Last edited:
Why
# mv Makefile Makefile.orig
# cp Makefile.orig Makefile
and not
# cp Makefile Makefile.orig
?

Installing nvidia driver 525 also fixes wine
 
Back
Top