#20 Mac使用GPU

Open
created 1 year ago by qianRaquel · 3 comments
### 问题所属任务编号(Task 01-05) task02 ### 运行环境(操作系统版本、Python 版本)/ 非程序问题 macOS M2芯片。电脑本地已安装好anaconda和Jupyter Notebook,配置好pytorch环境,d2l和torch包都装好了,可以用CPU跑李沐老师给的深度学习的代码。想问应该怎么使用GPU进行计算呢? 一定需要NVIDA显卡吗?请教Mac怎么驱动GPU运行呢? ### 描述你期望看到的结果 Mac本地可以使用GPU进行计算。 谢谢!!
anine09 added the
Task 01
label 1 year ago
anine09 added this to the 未分配助教 milestone 1 year ago
anine09 modified the milestone from 未分配助教 to 已分配助教 1 year ago
YangSu commented 1 year ago
mac m芯片可以使用GPU计算的,只需要重新安装 `miniconda` 和 `gpu` 版本的 `Torch` 就好,步骤: - 从 [官网](https://docs.conda.io/en/latest/miniconda.html) 下载 `3.9` 版本的 `miniconda`,然后运行: ```shell # execute the following at the download location: sh Miniconda3-py39_23.1.0-1-MacOSX-arm64.sh -b ``` - 初始化 `miniconda`: ```shell # initiate the shell conda actiavte ~/miniconda3 ``` 或者(二选一): ```shell ~/miniconda3/bin/conda init ``` - 创建虚拟环境 ```shell conda create --name d2l python=3.9 -y ``` - 激活虚拟环境 ```shell conda actiavte d2l ``` - 下载 `torch-gpu` 版本(选) 考虑到后续可能需要 `gpu` 加速训练,因此此处直接下载 `torch-gpu` 版本。 ```shell pip install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu ``` **Note**:检查是否安装成功,首先在命令行输入 `python` 进入 `python` 编程环境,然后输入 ```python >>> import torch >>> print(torch.backends.mps.is_available()) True ``` 若输出结果为 `Ture`,则表明安装成功。 - 下载 `ipykernel` 考虑到书中给的代码运行环境是 `jupyter`,应该此处安装 `ipykernel`,以确保 `jupyter-notebook` 中可以使用刚刚安装的 `d2l` 虚拟环境的内核。 ```shell pip install ipykernel python -m ipykernel install --user --name ENVNAME --display-name DISP_NAME ``` **Note**:`ENVNAME` 和 `DISP-NAME` 分别为虚拟环境的名字 (此处为 `d2l`)和想要显示的名字。为了简便,此处将两个字段都设置为 `d2l`。
anine09 added the
程序问题
label 1 year ago
anine09 modified the milestone from 已分配助教 to 助教解答过 1 year ago
qianRaquel commented 1 year ago
Poster
原本的Jupyter notebook已经安装和配置好pytorch环境,现需重新安装miniconda 和 gpu 版本的 Torch, 1.请问是不需要进行卸载anaconda等操作、直接从步骤1开始操作吗?anaconda和miniconda会不会冲突 2.原来的Jupyter notebook会被直接覆盖吗?安装完miniconda和gpu版本的Torch之后,再打开Jupyter notebook,那么区别于torch环境的其他环境还能使用吗?之前安装过keras和pygmt环境。 3.配置好Mac GPU之后,电脑本地的计算资源或者算力足够运行多大数据集呢?本地Jupyter Notebook,或者通过colab使用线上算力,哪种更推荐呢? 谢谢~
anine09 modified the milestone from 助教解答过 to 学习者追问 1 year ago
YangSu commented 1 year ago
1. 不会冲突,miniconda 相当于是另一个conda环境,一般而言网上给出的建议都是基于miniconda来安装gpu。我电脑上安装了anaconda和miniconda,暂时未冲突。如果怕冲突,可以直接试试从创建虚拟环境开始后续步骤,如果未安装成功,删除该虚拟环境再从头开始。 2.1 不会覆盖,`miniconda` 个人认为可以理解为 `conda` 的另一个虚拟环境,每次使用时需要先激活minicnoda环境,即上面提到的 `conda actiavte ~/miniconda3`,然后再激活你在 `miniconda` 中安装的虚拟环境。 2.2 安装完miniconda和gpu版本的Torch之后,再打开Jupyter notebook,默认还是进入原始的内核 `kernel`,是不会直接进入虚拟环境的。这时候需要使用最后一步安装 `ipykernel` 将该创建的虚拟环境转为 `kernel`,然后在 `jupyter notebook` 中选择基于该虚拟环境的内核就好。其他虚拟环境类似操作。 3. 电脑本地的计算资源可能跟电脑配置有关,可能看实际的数据大小,如果是大规模数据集的话,肯定优先选择云端跑,小数据的话,本地跑更方便。
anine09 modified the milestone from 学习者追问 to 助教解答过 1 year ago
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.