李沐机器学习环境配置相关
conda
退出 conda 环境
bash
conda deactivate
进入都d2l环境
bash
conda activate d2l
启动jupyter notebook:
bash
jupyter notebook
python
列出所有安装的包
bash
pip lsit
环境安装指令
安装miniconda
bash
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh
新建d2L环境
bash
conda create --name d2l python=3.9 -y
激活d2l环境
bash
conda activate d2l
安装cpu版本torch
bash
pip install torch==1.12.0
pip install torchvision==0.13.0
查看cuda版本
bash
nvidia-smi
安装GPU版本,我的cuda版本是11.4,装了11.3的
下面连接可以下载不同版本的pytorch
https://pytorch.org/get-started/previous-versions/
bash
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch
安装jupyter
bash
conda install jupyter
bash
pip install d2l==0.17.6
测试GPU是否可以使用
python
import torch
flag = torch.cuda.is_available()
print(flag)
ngpu= 1
# Decide which device we want to run on
device = torch.device("cuda:0" if (torch.cuda.is_available() and ngpu > 0) else "cpu")
print(device)
print(torch.cuda.get_device_name(0))
print(torch.rand(3,3).cuda())
True
cuda:0
GeForce GTX 1080
tensor([[0.9530, 0.4746, 0.9819],
[0.7192, 0.9427, 0.6768],
[0.8594, 0.9490, 0.6551]], device='cuda:0')