Skip to content

Instantly share code, notes, and snippets.

@ashwanirathee
Created April 30, 2025 21:39
Show Gist options
  • Save ashwanirathee/caf2534626f05dcc9f9acf15d14b7ece to your computer and use it in GitHub Desktop.
Save ashwanirathee/caf2534626f05dcc9f9acf15d14b7ece to your computer and use it in GitHub Desktop.
ego_blur apptainer
Bootstrap: docker
From: nvidia/cuda:12.1.1-cudnn8-devel-ubuntu22.04
%labels
Author AshwaniRathee
Version v1.0
Description "EgoBlur container with LibTorch 2.1 and CUDA 12.1"
%environment
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
export LIBTORCH_HOME=/opt/libtorch
export CMAKE_PREFIX_PATH=$LIBTORCH_HOME
export TORCH_CUDA_ARCH_LIST="6.0;6.1;7.0;7.5;8.0;8.6" # Adjust based on your GPU
%post
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
build-essential cmake wget unzip git ninja-build \
libfmt-dev libturbojpeg-dev libpng-dev \
liblz4-dev libzstd-dev libxxhash-dev \
libboost-system-dev libboost-iostreams-dev \
libboost-filesystem-dev libboost-thread-dev \
libboost-chrono-dev libboost-date-time-dev \
libopencv-dev libomp-dev make gcc g++ vim tzdata \
libssl-dev zlib1g-dev
# Set timezone to avoid interactive prompt
ln -fs /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
echo "America/Los_Angeles" > /etc/timezone
dpkg-reconfigure -f noninteractive tzdata
####
# Build Python 3.10 from source
cd /opt
wget https://www.python.org/ftp/python/3.10.14/Python-3.10.14.tgz
tar xzf Python-3.10.14.tgz
cd Python-3.10.14
./configure --enable-optimizations
make -j$(nproc)
make altinstall # installs as python3.10
# Set Python 3.10 as default python3
update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.10 1
update-alternatives --set python3 /usr/local/bin/python3.10
# Upgrade pip and install dependencies
python3 -m ensurepip
python3 -m pip install --upgrade pip setuptools wheel
python3 -m pip install torch==2.1.0+cu121 torchvision==0.16.0+cu121 torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cu121
# Install CUDA Extensions for PyTorch
python3 -m pip install ninja # Needed for compiling CUDA extensions in PyTorch
mkdir -p /usr/local/lib/python3.10/site-packages/
chmod -R a+rw /usr/local/lib/python3.10/site-packages/
####
# Install CMake 3.28+
mkdir -p /opt/cmake && cd /opt/cmake
wget https://github.com/Kitware/CMake/releases/download/v3.28.0-rc4/cmake-3.28.0-rc4-linux-x86_64.sh
chmod +x cmake-3.28.0-rc4-linux-x86_64.sh
./cmake-3.28.0-rc4-linux-x86_64.sh --skip-license --prefix=/opt/cmake
ln -sf /opt/cmake/bin/cmake /usr/local/bin/cmake
# Install LibTorch 2.1.0 (CUDA 12.1)
mkdir -p /opt && cd /opt
wget https://download.pytorch.org/libtorch/cu121/libtorch-cxx11-abi-shared-with-deps-2.1.0%2Bcu121.zip -O libtorch.zip
unzip libtorch.zip && rm libtorch.zip
# Create models and repo directories
mkdir -p /workspace/models
mkdir -p /workspace/repos
# Clean up APT cache to reduce image size
apt-get clean && rm -rf /var/lib/apt/lists/*
%runscript
echo "Welcome to EgoBlur Apptainer Container"
echo "LibTorch path: $LIBTORCH_HOME"
exec "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment