Loading

安装机器学习环境

首先需要安装好Python3

配置pip源

这里使用清华源:pypi | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

临时使用

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

注意,simple 不能少, 是 https 而不是 http

设为默认

升级 pip 到最新的版本 (>=10.0.0) 后进行配置:

pip3 install pip -U
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

如果您到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip:

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U

安装显卡驱动和CUDA工具包

查看显卡驱动版本和支持的CUDA版本

nvidia-smi

# 输出:
Mon Nov  8 18:37:26 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 496.49       Driver Version: 496.49       CUDA Version: 11.5     |
|-------------------------------+----------------------+----------------------+
| GPU  Name            TCC/WDDM | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ... WDDM  | 00000000:01:00.0 Off |                  N/A |
| N/A    0C    P8    12W /  N/A |    162MiB /  6144MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

进入官网下载驱动

显卡驱动下载:

官方 GeForce 驱动程序 | NVIDIA

程序安装完后记得打开更新下显卡驱动

CUDA工具包下载:
CUDA Toolkit 11.5 Downloads | NVIDIA Developer

官网下载如果太慢,可以从百度网盘下载驱动:

链接:https://pan.baidu.com/s/1qy7hJKPAktqoNy8xwFxM3Q
提取码:d7z3

查看是否安装成功

nvcc -V

# 输出:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Mon_Sep_13_20:11:50_Pacific_Daylight_Time_2021
Cuda compilation tools, release 11.5, V11.5.50
Build cuda_11.5.r11.5/compiler.30411180_0

安装Torch

Torch官网:Start Locally | PyTorch
比如,我是用以下命令安装PyTorch:

 pip3 install torch==1.10.0+cu113 torchvision==0.11.1+cu113 torchaudio===0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html

要使用管理员身份运行命令,否则可能安装失败

安装jupyter notebook

使用pip3安装:

pip3 install jupyter

运行jupyter notebook:

jupyter notebook

验证torch是否能使用GPU:

import torch
torch.cuda.is_available()
posted @ 2021-11-08 19:27  橘崽崽啊  阅读(139)  评论(0编辑  收藏  举报