๐Ÿ‘ป OS & Tools/Ubuntu

CUDA, driver, PyTorch + Tensorflow ํ˜ธํ™˜๋˜๋Š” version ์ฐพ๊ณ  ์„ค์น˜(์—…๊ทธ๋ ˆ์ด๋“œ, ๋‹ค์šด๊ทธ๋ ˆ์ด๋“œ)ํ•˜๊ธฐ

๋ณต๋งŒ 2021. 8. 19. 14:42

CUDA๋ฅผ ์„ค์น˜ ์‹œ์— driver version์— ๋งž๋Š” version์„ ์„ค์น˜ํ•ด์•ผ ํ•˜๊ณ ,

CUDA version์— ๋งž๋Š” version์˜ PyTorch๋ฅผ ์„ค์น˜ํ•ด์•ผ ํ•œ๋‹ค.

 

์ฐธ๊ณ : Driver & Cuda & PyTorch version ํ™•์ธ

 

Python์œผ๋กœ PyTorch, Python, CUDA, cudnn ๋ฒ„์ „ ํ™•์ธ

PyTorch ๋ฒ„์ „ ํ™•์ธ import torch print(torch.__version__) Python ๋ฒ„์ „ ํ™•์ธ import sys print(sys.version) Python ๊ฒฝ๋กœ ํ™•์ธ import sys print(sys.executable) CUDA & Driver ๋ฒ„์ „ ํ™•์ธ 1. nvidia-smi - Drive..

bo-10000.tistory.com

 

 

1. Nvidia ๋“œ๋ผ์ด๋ฒ„ ์„ค์น˜

ubuntu 18.04์—์„œ nvidia ๋“œ๋ผ์ด๋ฒ„, cuda, cudnn ์„ค์น˜ํ•˜๊ธฐ

 

1) ubuntu ํŒจํ‚ค์ง€ ์—…๋ฐ์ดํŠธ ๋ฐ ์ถ”๊ฐ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜

 

sudo apt update
sudo apt install -y build-essential
sudo apt-get install -y freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev libglfw3-dev libgles2-mesa-dev
sudo apt-get install -y libfreeimage3 libfreeimage-dev

 

2) nouveau ๋“œ๋ผ์ด๋ฒ„ blacklist ๋“ฑ๋ก

 

sudo vi /etc/modprobe.d/blacklist-nouveau.conf

#๋‹ค์Œ ๋‚ด์šฉ์„ ์ถ”๊ฐ€

blacklist nouveau

options nouveau modeset=0

 

3) ์ปค๋„ ๋ฆฌ๋นŒ๋“œ ๋ฐ ์žฌ๋ถ€ํŒ…, noveau ๋น„ํ™œ์„ฑํ™” ํ™•์ธ

 

sudo update-initramfs –u

sudo reboot

lsmod | grep nouveau #์•„๋ฌด๊ฒƒ๋„ ์•ˆ๋œจ๋ฉด ์ •์ƒ

 

4) Repository ์ถ”๊ฐ€

 

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update

 

5) ์„ค์น˜ ๊ฐ€๋Šฅ nvidia ๋“œ๋ผ์ด๋ฒ„ ๋ชฉ๋ก ํ™•์ธ ๋ฐ ์„ค์น˜

 

apt-cache search nvidia | grep nvidia-driver #์„ค์น˜ ๊ฐ€๋Šฅ ๋“œ๋ผ์ด๋ฒ„ ๋ชฉ๋ก ํ™•์ธ
sudo apt install -y nvidia-driver-470 #์„ค์น˜
sudo reboot #์žฌ์‹œ์ž‘

 

6) ์„ค์น˜ ์™„๋ฃŒ ํ™•์ธ

 

 

 

2. CUDA & Driver compatibility

 

๊ฐ driver version๊ณผ ํ˜ธํ™˜๋˜๋Š” CUDA version์€ ๋‹ค์Œ ๋งํฌ์—์„œ ํ™•์ธ๊ฐ€๋Šฅํ•˜๋‹ค. 

[1] https://docs.nvidia.com/deploy/cuda-compatibility/ (11.x, 10.x)

[2] https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cuda-major-component-versions__table-cuda-toolkit-driver-versions (11.0~11.4)

 

 

 

์œ„ ํ‘œ๋Š” ๊ฐ CUDA version์— ํ˜ธํ™˜๊ฐ€๋Šฅํ•œ driver์˜ ์ตœ์†Œ ์‚ฌ์–‘์ด๊ณ , ์•„๋ž˜๋Š” CUDA Toolkit์— ํฌํ•จ๋œ driver version์ด๋ผ๊ณ  ํ•˜๋Š”๋ฐ.. ๋ฌด์Šจ ์ฐจ์ด๊ฐ€ ์žˆ๋Š”์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ๋‹ค.

 

 

๊ณต์‹ ํ™ˆํŽ˜์ด์ง€ [2] ์—์„œ๋Š” Toolkit driver version๊ณผ Minimum required version์ด ๋‹ค๋ฅธ ๊ฒฝ์šฐ๋Š” compatibility mode์—์„œ ํ—ˆ์šฉ๋œ๋‹ค ๋ผ๊ณ  ์ ํ˜€ ์žˆ๋Š”๋ฐ.. CUDA Toolkit์„ ์„ค์น˜ํ•˜๋ฉด ์ž๋™์œผ๋กœ ์„ค์น˜๋˜๋Š” driver version์ด Toolkit driver version์ด๊ณ , Minimum required version์—์„œ๋„ ํ˜ธํ™˜๋œ๋‹ค ๋ผ๋Š” ๋œป์ธ ๊ฒƒ ๊ฐ™๋‹ค.

 

 

3. CUDA installation

 

driver version๊ณผ ๊ทธ์— ๋งž๋Š” CUDA version์„ ํ™•์ธํ–ˆ์œผ๋ฉด,

์„ค์น˜ํ•  CUDA version์„ ๊ฒฐ์ •ํ•œ๋‹ค.

 

๊ฐ€์žฅ ์ตœ์‹  CUDA๋ฅผ ์„ค์น˜ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์€ ๊ฒƒ์ด ์•„๋‹ˆ๋‹ค.

PyTorch ์—ญ์‹œ CUDA version์— ๋งž๊ฒŒ ์„ค์น˜ํ•ด์•ผ ํ•˜๊ณ , ๊ฐ PyTorch version๋งˆ๋‹ค ์ง€์›ํ•˜๋Š” CUDA version์ด ์ •ํ•ด์ ธ ์žˆ๊ธฐ ๋•Œ๋ฌธ์—..

์•„๋ž˜ 3. ์„ ๋ณด๊ณ , ๋ณธ์ธ์ด ์„ค์น˜ํ•  PyTorch version๊ณผ ํ˜ธํ™˜๋˜๋Š” CUDA๋ฅผ ์„ค์น˜ํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•œ๋‹ค.

 

 

1) Uninstall previous version

 

๋งŒ์•ฝ ์ด๋ฏธ CUDA๊ฐ€ ๊น”๋ ค ์žˆ๋‹ค๋ฉด, ์ƒˆ๋กœ์šด version์„ ์„ค์น˜ํ•˜๊ธฐ ์ „์— ๋จผ์ € ์‚ญ์ œํ•ด์•ผ ํ•œ๋‹ค.

 

์•„๋ž˜ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํ–ˆ๋‹ค.

Linux(์šฐ๋ถ„ํˆฌ)์—์„œ CUDA ๋‹ค์šด๊ทธ๋ ˆ์ด๋“œํ•˜๊ธฐ

CUDA (+CUDA Toolkit), Nvidia Driver, cuDNN ์šฐ๋ถ„ํˆฌ 20.04 ์„ค์น˜

 

sudo rm /etc/apt/sources.list.d/cuda* #nvidia/cuda ํŒจํ‚ค์ง€ ์ œ๊ฑฐ
sudo apt remove --autoremove nvidia-cuda-toolkit #nvidia-cuda-toolkit ์ œ๊ฑฐ
sudo apt-get purge nvidia* && sudo apt-get autoremove && sudo apt-get autoclean && sudo rm -rf /usr/local/cuda* #nvidia ๊ด€๋ จ ํŒจํ‚ค์ง€ ์ œ๊ฑฐ
sudo reboot

 

 

2) Install latest version

 

๊ฐ€์žฅ ์ตœ์‹  version์˜ CUDA๋Š” ์•„๋ž˜ ๋งํฌ์—์„œ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ๋‹ค.

https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu 

 

CUDA Toolkit 11.4 Update 1 Downloads

Resources CUDA Documentation/Release NotesMacOS Tools Training Sample Code Forums Archive of Previous CUDA Releases FAQ Open Source PackagesSubmit a Bug

developer.nvidia.com

 

 

์šด์˜์ฒด์ œ์™€ Installer Type์„ ์„ ํƒํ•˜๋ฉด ์„ค์น˜ ๋ช…๋ น์–ด๋ฅผ ์•Œ๋ ค์ค€๋‹ค.

(CUDA 11.4๋Š” Ubuntu 16.04๋Š” ์ง€์›์„ ์•ˆํ•˜๋‚˜ ๋ณด๋‹ค.)

 

 

์ฐธ๊ณ : cuda ์„ค์น˜ ์‹œ ์œ ์˜์‚ฌํ•ญ (์ถœ์ฒ˜)

deb(local) ์„ค์น˜ ์‹œ cuda ๋ฒ„์ „๊ณผ ๋งค์นญ๋œ nvidia ๋“œ๋ผ์ด๋ฒ„๊ฐ€ ๊ฐ™์ด ์„ค์น˜๋œ๋‹ค๊ณ  ํ•œ๋‹ค. ์ถฉ๋Œ์ด ์ผ์–ด๋‚  ์ˆ˜๋„ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋“œ๋ผ์ด๋ฒ„ ๋ฒ„์ „ ์—†์ด ์„ค์น˜ํ•  ๊ฒฝ์šฐ runtime(local)๋กœ ์„ค์น˜ํ•˜๋ฉด ๋œ๋‹ค๊ณ  ํ•จ. runtime(local)์„ ์ด์šฉํ•œ ์„ค์น˜๋Š” ์œ„ ๋งํฌ ์ฐธ๊ณ 

 

 

3) Install previous version

 

์ด์ „ version์˜ CUDA๋Š” ๋‹ค์Œ ๋งํฌ์—์„œ ๋‹ค์šด๋กœ๋“œ ๊ฐ€๋Šฅํ•˜๋‹ค.

https://developer.nvidia.com/cuda-toolkit-archive

 

CUDA Toolkit Archive

Previous releases of the CUDA Toolkit, GPU Computing SDK, documentation and developer drivers can be found using the links below. Please select the release you want from the list below, and be sure to check www.nvidia.com/drivers for more recent production

developer.nvidia.com

 

 

์›ํ•˜๋Š” version์„ ํด๋ฆญํ•˜๊ณ , ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์šด์˜์ฒด์ œ์™€ Installer Type๋ฅผ ์„ ํƒํ•˜๋ฉด ์„ค์น˜๋ฅผ ์œ„ํ•œ ๋ช…๋ น์–ด๋ฅผ ์•Œ๋ ค์ค€๋‹ค.

 

 

 

4) Setting Environment variables

 

Cuda๋ฅผ (์žฌ)์„ค์น˜ํ–ˆ์œผ๋ฉด ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์„ค์ •ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.

 

vi .bashrc

 

bashrc ํŒŒ์ผ์„ ์—ด์–ด ๋งจ ์•„๋ž˜์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ถ”๊ฐ€ (ํ˜น์€ ์ˆ˜์ •) ํ•ด์ค€๋‹ค.

 

export CUDA_HOME=/usr/local/cuda-10.2
export PATH=/usr/local/cuda-10.2/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH

 

 

4. CUDA & PyTorch compatibility + PyTorch intallation

 

PyTorch๋Š” ์ด์ „ ๋ฒ„์ „์˜ uninstall ์—†์ด ๋ฐ”๋กœ ์„ค์น˜ํ•ด๋„ ๋œ๋‹ค.

 

๊ฐ€์žฅ ์ตœ์‹  version์˜ PyTorch๋Š” ์•„๋ž˜ ๋งํฌ์—์„œ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ๋‹ค.

https://pytorch.org/get-started/locally/

 

PyTorch

An open source machine learning framework that accelerates the path from research prototyping to production deployment.

pytorch.org

 

CUDA์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์„ค์น˜ํ•  PyTorch version, ํ˜„์žฌ ์šด์˜์ฒด์ œ, ๋‹ค์šด๋กœ๋“œํ•  ๋ฐฉ๋ฒ•, ์‚ฌ์šฉํ•  ์–ธ์–ด, CUDA version์„ ์„ ํƒํ•˜๋ฉด ๋ช…๋ น์–ด๋ฅผ ์•Œ๋ ค์ค€๋‹ค.

PyTorch v1.9.0๊ณผ 1.8.2๋Š” CUDA 10.2์™€ 11.1๊ณผ ํ˜ธํ™˜๊ฐ€๋Šฅํ•œ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

 

 

 

์ด์ „ version์€ ๋‹ค์Œ ๋งํฌ์—์„œ ๋‹ค์šด๋กœ๋“œํ•  ์ˆ˜ ์žˆ๋‹ค.

https://pytorch.org/get-started/previous-versions/

 

PyTorch

An open source machine learning framework that accelerates the path from research prototyping to production deployment.

pytorch.org

 

์ตœ์‹  version์ฒ˜๋Ÿผ ์นœ์ ˆํ•˜๊ฒŒ ์•Œ๋ ค์ฃผ์ง€๋Š” ์•Š์ง€๋งŒ, ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ PyTorch version, ํ˜„์žฌ ์šด์˜์ฒด์ œ, ๋‹ค์šด๋กœ๋“œํ•  ๋ฐฉ๋ฒ•, ์‚ฌ์šฉํ•  ์–ธ์–ด, CUDA version์— ๋”ฐ๋ผ ๋ช…๋ น์–ด๊ฐ€ ์ •๋ฆฌ๋˜์–ด ์žˆ๋‹ค.

 

 

 

5. CUDA & Tensorflow compatibility + Tensorflow intallation

 

Tensorflow ์—ญ์‹œ CUDA version๊ณผ์˜ ํ˜ธํ™˜์„ฑ์„ ํ™•์ธํ•˜๊ณ  ๊ทธ์— ๋งž๋Š” ๋ฒ„์ „์œผ๋กœ install/upgrade/downgradeํ•ด์•ผ ํ•˜๋Š”๋ฐ.. PyTorch์— ๋น„ํ•ด ๋น„๊ต์  ๊ฐ„๋‹จํ•˜๋‹ค.

 

์šฐ์„ , ๋‹ค์Œ ๋งํฌ์—์„œ CUDA version์— ๋งž๋Š” Tensorflow version์„ ํ™•์ธํ•œ๋‹ค.

https://www.tensorflow.org/install/source#tested_build_configurations

 

์†Œ์Šค์—์„œ ๋นŒ๋“œ  |  TensorFlow

ML Community Day is November 9! Join us for updates from TensorFlow, JAX, and more Learn more ์†Œ์Šค์—์„œ ๋นŒ๋“œ ์†Œ์Šค์—์„œ TensorFlow pip ํŒจํ‚ค์ง€๋ฅผ ๋นŒ๋“œํ•˜๊ณ  Ubuntu Linux ๋ฐ macOS์— ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค. ๋ช…๋ น์–ด๋Š” ๋‹ค๋ฅธ ์‹œ์Šคํ…œ์—๋„ ์ ์šฉ๋ 

www.tensorflow.org

 

 

 

์ดํ›„ pip install์„ ํ†ตํ•ด ์ƒˆ๋กœ์šด version์„ installํ•˜๋ฉด ๋œ๋‹ค. PyTorch์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ, uninstall์€ ํ•„์š”ํ•˜์ง€ ์•Š๋‹ค.

 

pip install tensorflow==2.3.0
pip install tensorflow-gpu==2.3.0
๋ฐ˜์‘ํ˜•