requirements 목록
torch==2.0.1
torchvision==0.15.2
onnx==1.14.0
onnxruntime==1.15.1
pycocotools
PyYAML
scipy
torch==2.0.1 깔기
(rtdetr) moa@moa-Precision-3650-Tower:~/Documents/Rt-DETR/RT-DETR/rtdetr_pytorch$ nvidia-smi
Wed Jul 17 18:06:50 2024
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.161.07 Driver Version: 535.161.07 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 NVIDIA GeForce RTX 3090 Off | 00000000:01:00.0 On | N/A |
| 0% 54C P8 39W / 350W | 556MiB / 24576MiB | 14% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
현재 cuda version 12.2
pip install requirements.txt 가 안되므로
conda install 로 시도
conda install pytorch==2.0.1
(rtdetr) moa@moa-Precision-3650-Tower:~/Documents/Rt-DETR/RT-DETR/rtdetr_pytorch$ conda install pytorch==2.0.1
Channels:
- defaults
- conda-forge
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: - warning libmamba Added empty dependency for problem type SOLVER_RULE_UPDATE
failed
LibMambaUnsatisfiableError: Encountered problems while solving:
- package pytorch-2.0.1-cpu_py310hab5cca8_0 requires python >=3.10,<3.11.0a0, but none of the providers can be installed
Could not solve for environment specs
The following packages are incompatible
├─ pin-1 is installable and it requires
│ └─ python 3.7.* , which can be installed;
└─ pytorch 2.0.1 is not installable because there are no viable options
├─ pytorch 2.0.1 would require
│ └─ python >=3.10,<3.11.0a0 , which conflicts with any installable versions previously reported;
├─ pytorch 2.0.1 would require
│ └─ python >=3.11,<3.12.0a0 , which conflicts with any installable versions previously reported;
├─ pytorch 2.0.1 would require
│ └─ python >=3.8,<3.9.0a0 , which conflicts with any installable versions previously reported;
└─ pytorch 2.0.1 would require
└─ python >=3.9,<3.10.0a0 , which conflicts with any installable versions previously reported.
현재 파이썬 버전 문제. 3.9.10으로 변경
cuda, cuDnn version 호환 문제
정리
1. nvidia-smi로 gpu 정보 얻기 (모델명, driver 버전 등)
Driver version에 따른 사용 가능한 CUDA 버전 알아보기
링크 : https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cuda-major-component-versions
링크 : https://en.wikipedia.org/wiki/CUDA
링크 : https://pytorch.org/get-started/previous-versions/
출처: https://jjuke-brain.tistory.com/entry/GPU-서버-사용법-CUDA-PyTorch-버전-맞추기-총정리 [JJukE's Brain:티스토리]
(rtdetr) moa@moa-Precision-3650-Tower:~/Documents/Rt-DETR/RT-DETR/rtdetr_pytorch$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Mon_May__3_19:15:13_PDT_2021
Cuda compilation tools, release 11.3, V11.3.109
Build cuda_11.3.r11.3/compiler.29920130_0
사용하는 버전이 11.3인데, 2.0.1은 11.8부터 호환하니 cuda version을 업데이트해줘야한다.
다시 깔면 문제가 발생할 수 있으니 docker 환경 세팅으로 11.8 버전 사용하기
https://velog.io/@moey920/CUDA-%EB%B2%84%EC%A0%84-%EC%97%85%EB%8D%B0%EC%9D%B4%ED%8A%B8
도커(Docker)를 사용하면 여러 CUDA 및 cuDNN 버전을 격리된 환경에서 실행할 수 있기 때문에 다양한 소프트웨어 버전을 관리하고 테스트하는 데 매우 유용합니다.
Docker를 사용하여 여러 CUDA 버전 실행
도커를 사용하면 각 컨테이너마다 다른 CUDA 버전과 cuDNN 버전을 설정할 수 있습니다. 이는 컨테이너가 서로 독립적인 환경을 제공하기 때문에 가능합니다.
다음은 도커 설치 및 NVIDIA Docker 설정을 통해 여러 CUDA 및 cuDNN 버전을 사용하는 방법입니다.
도커 및 NVIDIA Docker 설치 가이드
1. 기본 Docker 설치
bash
코드 복사
$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
$ sudo usermod -aG docker $USER
2. NVIDIA Docker 설치
bash
코드 복사
$ distribution=(. /etc/os-release;echo $IDVERSION_ID)
$ curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
$ curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
$ sudo apt-get update
$ sudo apt-get install -y nvidia-container-toolkit
$ sudo systemctl restart docker
3. Docker 컨테이너에서 CUDA 확인
설치된 CUDA 버전을 확인하여 컨테이너가 정상적으로 동작하는지 확인합니다.
$ docker run -it --rm --gpus all -v ~/Documents/Rt-DETR:/workspace nvidia/cuda:11.8.0-cudnn8-devel-ubuntu20.04 /bin/bash
'devel' 이 포함된 컨테이너를 깔아서 개발 도구와 컴파일러가 포함된 이미지 run하기.
rt-detr을 마운트하여 run하기
///
하다보니 Dockerfile을 생성하고 기본 세팅을 한 후 컨테이너 생성을 해야한다는 것을 깨달음. dockerfile 생성.
# nvidia/cuda:11.8.0-cudnn8-devel-ubuntu20.04 이미지를 사용하여 python 3.9.10 설치
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu20.04
# 비대화형 프론트엔드 설정
ENV DEBIAN_FRONTEND=noninteractive
# 디펜던시 설치 및 타임존 설정
RUN apt-get update && apt-get install -y \
tzdata \
build-essential \
cmake \
git \
curl \
vim \
wget \
&& rm -rf /var/lib/apt/lists/*
RUN ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime && \
dpkg-reconfigure --frontend noninteractive tzdata
# Python 3.9.10 설치
RUN apt-get update && apt-get install -y \
software-properties-common \
&& add-apt-repository -y ppa:deadsnakes/ppa \
&& apt-get update && apt-get install -y \
python3.9 \
python3.9-dev \
python3.9-distutils \
&& rm -rf /var/lib/apt/lists/*
# Python 3.9를 기본 python으로 설정
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
# pip 설치
RUN curl https://bootstrap.pypa.io/get-pip.py | python3.9
# 작업 디렉토리 설정
WORKDIR /workspace
# requirements.txt 복사 및 패키지 설치
COPY requirements.txt .
RUN pip install -r requirements.txt
RUN pip install numpy==1.23.5
# RT-DETR 디렉토리 복사
COPY ~/Documents/Rt-DETR /workspace/Rt-DETR
# 기본 명령어 설정
CMD ["bash"]
현재 내 dockerfile에는 numpy랑 rtdetr 파일 마운트가 안되서 실행할 때 마운트해주고 numpy install 해주기
$ docker run --shm-size=20g -it --name rtdetr_container -v ~/Documents/Rt-DETR:/workspace/Rt-DETR rtdetr_image bash
$ pip install numpy==1.23.5
///
해보니 도커 컨테이너에서 gpu를 사용하려면 container_toolkit도 설치해야한다.
$ curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
$ sudo sed -i -e '/experimental/ s/^#//g' /etc/apt/sources.list.d/nvidia-container-toolkit.list
$ sudo apt-get update
$ sudo apt-get install -y nvidia-container-toolkit
$ sudo systemctl restart docker
현재 컨테이너 상태를 그대로 commit한 후 다시 실행. (dockerfile이 더 효율적이지만, 일단 현재 컨테이너 내부에서 업데이트 한 파일들이 있으므로)
$ docker commit rtdetr_container rtdetr_image
$ docker run --gpus all --shm-size=20g -it --name rtdetr_container_gpu -v ~/Documents/Rt-DETR:/workspace/Rt-DETR rtdetr_image bash
하고 nvidia-smi 하고 gpu 인식되는지 확인하면 진짜 끝
재시작 후 실행
docker start rtdetr_container_gpu
docker exec -it rtdetr_container_gpu bash