Skip to content

Instantly share code, notes, and snippets.

@SharkWipf
Last active May 31, 2024 02:38
Show Gist options
  • Save SharkWipf/f8dd6cb0379ec0c6b82d9a734bffde62 to your computer and use it in GitHub Desktop.
Save SharkWipf/f8dd6cb0379ec0c6b82d9a734bffde62 to your computer and use it in GitHub Desktop.
Unofficial start-to-finish instructions on how to install cuda & nerfstudio on AlmaLinux/Rocky Linux/Oracle Linux/RHEL

Unofficial Installation Instructions for NerfStudio on RHEL/AlmaLinux/Rocky Linux/Oracle Linux 9.2+

Tested on AlmaLinux. Should allow you to install NerfStudio on either a squeaky clean install or an existing install. Will not work for Fedora, may work for CentOS (untested), but I wouldn't risk it. Will not work for non-RHEL-based distros.

NerfStudio evolves quickly, and Nvidia is a pain. Instructions work today, they may not work tomorrow. Use at your own risk.

For instructions on how to install Nerfstudio under WSL2 on Windows, see this document instead.

Initial Setup

First, make sure you're on the latest, especially if you just installed. Reboot afterwards to make sure you're running the latest kernel.
Failure to do so may, worst case, result in a broken system at the dkms step.

sudo dnf update
sudo reboot

Install kernel headers, development libraries and git, which we need later.

sudo dnf install kernel-devel kernel-devel-matched kernel-headers git

Install Necessary Packages

Install subscription-manager, needed for the next steps.
Also install the epel 3rd party repo while we're at it, needed for DKMS later.

sudo dnf install subscription-manager epel-release

Install the stream repos Nvidia suggests for cuda.

sudo subscription-manager repos --enable=rhel-9-for-x86_64-appstream-rpms
sudo subscription-manager repos --enable=rhel-9-for-x86_64-baseos-rpms
sudo subscription-manager repos --enable=codeready-builder-for-rhel-9-x86_64-rpms

As per Nvidia's instructions, get rid of their old signing key. Doesn't affect anything on a clean install.

sudo rpm --erase gpg-pubkey-7fa2af80*

Add yet another repo, this time Nvidia's CUDA repo. This'll let us install both the Nvidia drivers and the CUDA packages.

sudo dnf config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel9/x86_64/cuda-rhel9.repo

Make sure we don't have any stale caches that might mess things up.

sudo dnf clean expire-cache

Install the actual Nvidia drivers. Make sure you don't have any Nvidia drivers (other than nouveau) installed if you can.

sudo dnf module install nvidia-driver:latest-dkms

Finally, install CUDA. You can change the 11-8 to other CUDA versions.

sudo dnf install cuda-11-8

You can also opt to install multiple versions, but you'll have to manually specify CUDA_PATH at the very least when building tiny-cuda-nn:

export CUDA_PATH=/usr/local/cuda-11.8

Install development tools that'll allow you to compile/build packages. You need this for some of the nerfstudio dependencies.

sudo dnf groupinstall 'C Development Tools and Libraries' 'Development Libraries' 'Development Tools'

Reboot.

sudo reboot

At this point, you should have working Nvidia drivers and working CUDA.
You can confirm if the Nvidia drivers are working by running nvidia-smi.
Next up is installing NerfStudio.

Installing NerfStudio

First install the system tools you need to install/run nerfstudio.

sudo dnf install conda
conda init bash
source ~/.bashrc

The conda init bash command may throw a lot of scary errors, ngl, no idea why, but it does not seem to affect its functionality.

At this point, follow the steps from the NerfStudio install guide.
I'll copy one version of them here for completeness, but keep in mind the official instructions might change.
My version slightly deviates from the official instructions to hopefully be slightly more robust.

The official documentation suggests python 3.8, so stick with that until you've confirmed everything working.
That said, up to 3.10 worked for me at the time of writing. 3.11 broke tiny-cuda-nn when I tested.

conda create --name nerfstudio -y python=3.8

Always run this command first before doing anything NerfStudio related (including running pip and other conda commands) in a new terminal.

conda activate nerfstudio

Make sure the latest pip and setuptools are installed.

pip install --upgrade pip setuptools ninja

Install PyTorch

pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 --extra-index-url https://download.pytorch.org/whl/cu118
CUDA_PATH=/usr/local/cuda-11.8 pip install git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch

Install NerfStudio. Given how fast it updates, we'll opt for the github version.
We'll put it in ~/src/nerfstudio to keep things organized.

mkdir -p ~/src
git clone https://github.com/nerfstudio-project/nerfstudio.git
cd nerfstudio
pip install -e .

Congrats, you've now installed NerfStudio.
There's one more step to go however: COLMAP. This is an optional dependency, but unless you already have a workflow, you'll probably be using it.
COLMAP is used by nerfstudio to process loose images or videos, it is the "least optimal" method, but also the most compatible method, that works with any videos/images.
This isn't covered in the docs, but installing COLMAP on Linux is pretty easy actually:

conda install -c conda-forge colmap

For COLMAP processing, NerfStudio uses ffmpeg.
Optional but recommended: install rpmfusion for ffmpeg (for COLMAP video processing).
ffmpeg-free is available normally, but it can't process h264/h265 videos, which most videos nowadays are.

sudo dnf install --nogpgcheck https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-$(rpm -E %rhel).noarch.rpm https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-$(rpm -E %rhel).noarch.rpm
sudo dnf install --enablerepo=* ffmpeg

If you do not want to use rpmfusion, you can just run the following instead for the limited ffmpeg:

sudo dnf install ffmpeg-free

There is one more optional (not used by default even if installed) component to COLMAP, hloc. I have not tested this myself yet, so this may not work.

cd ~/src
git clone --recursive https://github.com/cvg/Hierarchical-Localization
cd Hierarchical-Localization
pip install -e .

Now it should be off to the races with you.
Remember to run conda activate nerfstudio once any time you start a new terminal session. Without this, you can't run or even find the NerfStudio commands.

If you need to update nerfstudio from now on (there's currently updates almost daily), you can run:

cd ~/src/nerfstudio
git pull
pip install -e .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment