during docker build i get following error:625.4 self.build_extension(ext)
625.4 File "/opt/conda/envs/kpinst/lib/python3.9/site-packages/setuptools/command/build_ext.py", line 263, in build_extension
625.4 _build_ext.build_extension(self, ext)
625.4 File "/opt/conda/envs/kpinst/lib/python3.9/site-packages/Cython/Distutils/build_ext.py", line 135, in build_extension
625.4 super(build_ext, self).build_extension(ext)
625.4 File "/opt/conda/envs/kpinst/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 557, in build_extension
625.4 objects = self.compiler.compile(
625.4 File "/opt/conda/envs/kpinst/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 649, in unix_wrap_ninja_compile
625.4 cuda_post_cflags = unix_cuda_flags(cuda_post_cflags)
625.4 File "/opt/conda/envs/kpinst/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 548, in unix_cuda_flags
625.4 cflags + _get_cuda_arch_flags(cflags))
625.4 File "/opt/conda/envs/kpinst/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 1773, in _get_cuda_arch_flags
625.4 arch_list[-1] += '+PTX'
625.4 IndexError: list index out of range
625.4 [end of output]
625.4
625.4 note: This error originates from a subprocess, and is likely not a problem with pip.
625.4 ERROR: Failed building wheel for inplace-abn
625.4 ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (inplace-abn)
625.4
625.4
625.4 failed
625.4
625.4 CondaEnvException: Pip failed
625.4
ERROR: failed to solve: process "/bin/sh -c mamba env create -f /tmp/conda_env.yml -p /opt/conda/envs/kpinst && conda clean -afy && conda env list" did not complete successfully: exit code: 1
my dockerfile is :# Use base CUDA development image instead of runtime
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04
The error you're encountering during the Docker build process is due to an IndexError in PyTorch's cpp_extension module. Specifically, the arch_list is empty when the code attempts to append +PTX, leading to the list index out of range error. This typically happens when the CUDA architecture flags are not properly set, resulting in no architectures being detected for compilation.
Root Cause
The primary issue is that the CUDA architecture flags (TORCH_CUDA_ARCH_LIST) are not set or are incorrectly set, causing PyTorch's build process to fail when it attempts to compile CUDA extensions like inplace-abn.
Solution
To resolve this issue, you need to explicitly specify the CUDA architectures your build should target. This can be done by setting the TORCH_CUDA_ARCH_LIST environment variable in your Dockerfile before the mamba env create step. Here's how you can do it:
Determine Your CUDA Architectures:
Identify the CUDA compute capabilities relevant to your target GPU(s). Common compute capabilities include 6.0, 6.1, 7.0, 7.5, 8.0, etc.
For general purposes, especially if you're unsure, you can specify multiple architectures to cover a broad range of GPUs.
Modify Your Dockerfile:
Add the TORCH_CUDA_ARCH_LIST environment variable before the mamba env create command.
Example architectures are provided below, but you should adjust them based on your requirements.
Here's the updated Dockerfile with the necessary changes:
dockerfile
# Use base CUDA development image instead of runtime
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04
# Update NVIDIA GPG key
RUN rm -f /etc/apt/sources.list.d/cuda.list && \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends wget && \
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb && \
dpkg -i cuda-keyring_1.0-1_all.deb
# Preseed tzdata and install dependencies including build-essential and ninja-build
RUN truncate -s0 /tmp/preseed.cfg && \
echo "tzdata tzdata/Areas select Europe" >> /tmp/preseed.cfg && \
echo "tzdata tzdata/Zones/Europe select Berlin" >> /tmp/preseed.cfg && \
debconf-set-selections /tmp/preseed.cfg && \
rm -f /etc/timezone /etc/localtime && \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
tzdata \
sudo \
nano \
git \
ffmpeg \
libsm6 \
libxext6 \
build-essential \
ninja-build && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Install Miniconda
ENV CONDA_DIR=/opt/conda
ENV PATH="$CONDA_DIR/bin:$PATH"
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \
/bin/bash ~/miniconda.sh -b -p $CONDA_DIR && \
rm ~/miniconda.sh && \
$CONDA_DIR/bin/conda clean -afy && \
ln -s $CONDA_DIR/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
echo ". $CONDA_DIR/etc/profile.d/conda.sh" >> ~/.bashrc
# Update conda, set channel priority to flexible, and install mamba
RUN conda update -n base -c defaults conda -y && \
conda config --set channel_priority flexible && \
conda install -n base -c conda-forge mamba -y
# **Set CUDA architectures to prevent the IndexError**
# Adjust the compute capabilities based on your GPU. Below are common values:
# - 6.0: Pascal (e.g., GTX 1080)
# - 7.0: Volta (e.g., Tesla V100)
# - 7.5: Turing (e.g., RTX 2080)
# - 8.0: Ampere (e.g., RTX 3080)
ENV TORCH_CUDA_ARCH_LIST="7.5;8.0"
# Copy your conda environment file
COPY conda_env.yml /tmp/conda_env.yml
# Create Conda environment with mamba
RUN mamba env create -f /tmp/conda_env.yml -p /opt/conda/envs/kpinst && \
conda clean -afy && \
conda env list
# Set environment variables to use the new environment
ENV CONDA_DEFAULT_ENV=kpinst
ENV PATH="$CONDA_DIR/envs/kpinst/bin:$PATH"
# Initialize conda
RUN conda init bash
# Install openmim and mmcv-full
RUN conda run -p /opt/conda/envs/kpinst pip install openmim && \
conda run -p /opt/conda/envs/kpinst mim install mmcv-full==1.7.1
# Verify that mim is installed
RUN ls /opt/conda/envs/kpinst/bin/
# Activate the environment
ENV PATH /opt/conda/envs/kpinst/bin:$PATH
# Set PYTHONPATH to include the 'iSUOR_toolbox' directory
ENV PYTHONPATH="/workspace/isuor_kpinst/kpinst:${PYTHONPATH}"
# Install MMDetection from source
RUN git clone https://github.com/open-mmlab/mmdetection.git /mmdet && \
cd /mmdet && \
git checkout 94afcdc && \
pip install -v -e .
# Install Monocular-Depth-Estimation-Toolbox from source
RUN git clone https://github.com/zhyever/Monocular-Depth-Estimation-Toolbox.git /mde_toolbox && \
cd /mde_toolbox && \
git checkout 7c0c89c && \
pip install -v -e .
# Update PYTHONPATH and activate the environment in .bashrc for interactive sessions
RUN echo "export PYTHONPATH=/workspace/isuor_kpinst/kpinst/:${PYTHONPATH}" >> ~/.bashrc && \
echo "conda activate kpinst" >> ~/.bashrc
# Verify that init.py exists
RUN ls -la /mde_toolbox/depth/
# Adjust MMCV_MAX version in MDE-Toolbox to prevent version complaints
RUN sed -i "s/MMCV_MAX = '1.5.0'/MMCV_MAX = '1.8.0'/g" /mde_toolbox/depth/init.py
# Install yapf to fix configuration printing bug
RUN pip install yapf==0.40.1
# Replace memory hook in MMCV to fix GPU context issue
COPY patch/hooks_memory.py $CONDA_DIR/envs/kpinst/lib/python3.9/site-packages/mmcv/runner/hooks/memory.py
# Set default command
CMD ["bash"]
Explanation of Changes
Set TORCH_CUDA_ARCH_LIST:
The ENV TORCH_CUDA_ARCH_LIST="7.5;8.0" line sets the CUDA architectures to Turing (7.5) and Ampere (8.0). Adjust these values based on the GPUs you intend to support.
This ensures that PyTorch's build process has the necessary architecture information, preventing the IndexError.
Placement of the Environment Variable:
The TORCH_CUDA_ARCH_LIST is set before the mamba env create command. This is crucial because the environment variable needs to be available during the build of packages like inplace-abn that require compilation.
Additional Recommendations
Verify CUDA Toolkit Path:
Ensure that CUDA_HOME is correctly set, although the nvidia/cuda base image typically handles this.
Check PyTorch Version:
Ensure that the PyTorch version specified in your conda_env.yml is compatible with CUDA 11.8. For CUDA 11.8, PyTorch versions 1.13.x and above are generally compatible.
Precompiled Wheels:
If possible, use precompiled wheels for inplace-abn to avoid compilation issues. This can be done by specifying the package version or using alternatives that offer binary distributions.
Update inplace-abn:
Ensure you're using the latest version of inplace-abn, as newer versions might have better compatibility with recent CUDA and PyTorch releases.
Fallback to CPU-Only (If Applicable):
If CUDA support isn't strictly necessary for inplace-abn in your application, consider installing it without CUDA extensions.
Final Steps
After updating your Dockerfile, rebuild your Docker image:
bash
docker build -t your-image-name:tag .
Monitor the build process to ensure that the mamba env create step completes successfully without the IndexError. If you encounter further issues, consider examining the specific versions of dependencies in your conda_env.yml and ensuring compatibility across all packages.
Note: The TORCH_CUDA_ARCH_LIST should be tailored to the specific GPUs you plan to use. Specifying architectures that are not supported by your hardware can lead to inefficient builds or runtime errors.