--- tags: Ubuntu, PyTorch title: TensorFlow & PyTorch 安裝 --- # [Ubuntu 20.04 安裝 TenserFlow & PyTorch for RTX 30系列](https://lambdalabs.com/blog/install-tensorflow-and-pytorch-on-rtx-30-series) ## 將會安裝以下套件 1. TensorFlow 2. PyTorch 3. CUDA 4. cuDNN 5. Dependencies and other frameworks like Caffe and Theano(?) ## 系統需求 * Nvidia RTX 系列 GPUs * Ubuntu 20.04 LTS (Focal Fossa) ## 安裝桌機版 Lambda Stack ```console LAMBDA_REPO=$(mktemp) && \ wget -O${LAMBDA_REPO} https://lambdalabs.com/static/misc/lambda-stack-repo.deb && \ sudo dpkg -i ${LAMBDA_REPO} && rm -f ${LAMBDA_REPO} && \ sudo apt-get update && sudo apt-get install -y lambda-stack-cuda --allow-downgrades ``` **重新啟動電腦** ## 確認是否安裝成功 ```console $ python >>> import tensorflow >>> tensorflow.__version__ '2.6.0' >>> import torch >>> torch.__version__ '1.9.1' ``` ## 管理/升級 TensorFlow & PyTorch ```console sudo apt-get update && sudo apt-get dist-upgrade ``` ## 確認 Nvidia Driver、CUDA、cuDNN 使否安裝成功 ```console $ nvidia-smi Tue Nov 2 21:04:44 2021 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 470.74 Driver Version: 470.74 CUDA Version: 11.4 | |-------------------------------+----------------------+----------------------+ | 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 ... On | 00000000:01:00.0 Off | N/A | | 0% 40C P0 111W / 370W | 72MiB / 10010MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | 0 N/A N/A 1326 G /usr/lib/xorg/Xorg 56MiB | | 0 N/A N/A 1484 G /usr/bin/gnome-shell 12MiB | +-----------------------------------------------------------------------------+ ``` ```console $ nvcc --version nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2020 NVIDIA Corporation Built on Mon_Oct_12_20:09:46_PDT_2020 Cuda compilation tools, release 11.1, V11.1.105 Build cuda_11.1.TC455_06.29190527_0 ``` ## 簡單測試 (Stanford Dog use vgg16 pretrained model by PyTorch) 1. [PyTorch - StandFord Dog](https://hackmd.io/@TienYi/pytorch-stanford-dog) 2. [PyTorch - MNIST](https://hackmd.io/@TienYi/pytorch-mnist)