AI - Stable diffussion with dreambooth
AI - Stable diffussion with dreambooth: CUDA 11.8 on Xubuntu (GCC 12) — My DreamBooth Prep Notes • Knowledge • cuda, dreambooth
CUDA 11.8 on Xubuntu (GCC 12) — My DreamBooth Prep Notes
I’ve spent a lot of time getting a local Linux box ready to train image models of me. Cloud (Drive + rented GPUs) works, but I wanted it running on my own metal. The catch: tons of moving pieces that must play nicely together — GCC, CUDA toolkit, kernel/NVIDIA drivers, etc. The “latest and greatest” combo didn’t behave for me, so I pinned a known-good stack: CUDA 11.8 on Xubuntu 22.04 with GCC 12.
1) NVIDIA driver (clean slate → 525)
On a fresh Xubuntu 22.04 install I wiped any old NVIDIA bits and installed nvidia-driver-525:
sudo apt update # optional but recommended
sudo apt upgrade # optional but recommended
sudo apt install nvidia-driver-525Reboot after installing the driver.
2) Install CUDA 11.8 (runfile)
Grab the CUDA 11.8 runfile installer and run it:
wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
sudo sh cuda_11.8.0_520.61.05_linux.runQuick sanity check:
nvidia-smiYou should see your GPUs and a driver line (e.g., Driver Version: 525.xx, CUDA Version: 12.0).
3) Add CUDA to your environment
Append to ~/.bashrc:
export PATH="/usr/local/cuda/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda/lib64:$LD_LIBRARY_PATH"Reload the shell:
source ~/.bashrcRegister the library path with the dynamic loader:
sudo bash -c "echo /usr/local/cuda/lib64 > /etc/ld.so.conf"
sudo ldconfigConfirm it’s visible:
ldconfig -p | grep cuda4) Verify your CUDA version
cat /usr/local/cuda/version.json | grep version -B 2
# Expect something like:
# "cuda" : { "name" : "CUDA SDK", "version" : "11.8.20220929" },5) Build CUDA Samples (optional but reassuring)
Samples moved to GitHub:
git clone https://github.com/NVIDIA/cuda-samples.git
cd cuda-samples/
git checkout v11.8Install a required dependency:
sudo apt install libfreeimage-devCompile using all cores and tail the log:
make -j"$(nproc)" > compile.log 2>&1 &
tail -f compile.logYou’ll get warnings for older GPUs — ignore them. When the log ends with Finished building CUDA samples, try a couple examples:
# CUBLAS matrix multiply
cd Samples/4_CUDA_Libraries/matrixMulCUBLAS
./matrixMulCUBLAS
# (Optional) P2P bandwidth/latency if you have multiple GPUs
cd ~/cuda-samples/Samples/5_Domain_Specific/p2pBandwidthLatencyTest
./p2pBandwidthLatencyTestNVLink matrix (if applicable):
nvidia-smi nvlink -sClean up if you like:
rm -rf ~/cuda_11.8.0_520.61.05_linux.run ~/cuda-samples6) Python env + Diffusers / DreamBooth deps
You can use Anaconda or plain venv. If you prefer Anaconda (example version — grab the latest from their site):
wget https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh
chmod +x ./Anaconda3-2022.05-Linux-x86_64.sh
./Anaconda3-2022.05-Linux-x86_64.shClone the DreamBooth-ready Diffusers fork and install pieces:
# Fork with DreamBooth examples
git clone https://github.com/ShivamShrirao/diffusers
cd diffusers
# CUDA-enabled PyTorch (11.7 wheels play well with a 11.8 toolkit install)
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
# DreamBooth example requirements
cd examples/dreambooth
pip install -r requirements.txt
# Back to repo root to install diffusers in editable/standard mode
cd ../..
pip install .
# Extra performance libs
pip install -U --pre triton
pip install ninja bitsandbytes
# xFormers (specific commit used)
pip install git+https://github.com/facebookresearch/xformers@51dd119#egg=xformersConfigure accelerate (I set all device indices to 0 and chose FP16):
accelerate configAuthenticate with Hugging Face:
huggingface-cli loginConvert a Diffusers model to an original Stable Diffusion checkpoint (example):
python convert_diffusers_to_original_stable_diffusion.py --model_path /home/MODEL-TO-CONVERT --checkpoint_path /OUTPUT_PATHThat’s all. This combo (Xubuntu 22.04 + driver 525 + CUDA 11.8 + GCC 12) was the first setup that behaved consistently for me and didn’t fight my DreamBooth runs.