Mac m1 深度学习环境配置

本文是Mac m1的深度环境安装指南。一方面,记录了一些有用的链接,这些链接讲述了m1芯片与Intel芯片的不同之处以及在安装mac m1时需要注意的问题。另一方面,记录了我安装时的全过程,安装内容包括vscode, pytorch, jupyter。

m1芯片不同在哪?
https://www.anaconda.com/blog/apple-silicon-transition

从下面得知,对于m1芯片,下载安装包时应该注意下载注明有AArch64,ARM Macs,ARM64,ARMv8,osx-arm64的包。

Intel CPUs support the x86-64 ISA (sometimes also called AMD64 because AMD originally proposed this 64-bit extension to x86 back in 1999). The new Apple Silicon CPUs use an ISA designed by ARM called AArch64, just like the iPhone and iPad CPUs they descend from. For this reason, these new Macs are often called “ARM Macs” in contrast to “Intel Macs,” although ARM only defined the ISA used by the Apple M1 but did not design the CPU. In general, the naming conventions for 64-bit ARM architectures are confusing, as different people will use subtly different terms for the same thing. You may see some people call these “ARM64” CPUs (which is what Apple does in their developer tools), or slightly incorrectly as “ARMv8” (which is a specification that describes both AArch64 and AArch32). Even in conda, you’ll see the platform names osx-arm64, which you would use for macOS running on the M1, and linux-aarch64, which you would use for Linux running on a 64-bit ARM CPU.

配置环境前的注意:
m1芯片的mac做深度学习? - 真中合欢的回答 - 知乎
https://www.zhihu.com/question/493225739/answer/2178223987


1.下载vs code

vs code下载地址:https://code.visualstudio.com/Download#

  • 现在(2022-01-17 19:08:13)已经支持mac m1,不用通过 Rosetta 仿真来运行了。
  • 下载时选择universal版本或者apple silicon。
  • 如果下载速度过慢,可以使用镜像下载,可以参考以下链接。
    https://blog.csdn.net/weixin_44041875/article/details/120039029

2. 安装pytorch与jupyter

M1 mac安装PyTorch的完整步骤指南 - deephub的文章 - 知乎
https://zhuanlan.zhihu.com/p/394514049

  1. 安装homebrew
/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”

安装后如果报错:
Warning: /opt/homebrew/bin is not in your PATH.
按照指引添加路径。

    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/<用户名>/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"
  1. 安装mini forge
  • 安装mini forge
    brew install miniforge
  • 为Z shell (zsh)初始化conda
    conda init zsh
  1. 安装pytorch
    创建虚拟环境,并在环境中安装pytorch
  • 安装环境基于pytorch3.8,名为torchenv的环境
    conda create --name torchenv python=3.8
    conda init zsh #为Z shell (zsh)初始化conda
  • 在环境中安装pytorch
    conda activate torchenv #激活环境
    conda install -c pytorch pytorch #安装pytorch
  1. 安装jupyter
    在安装的环境下,安装jupyter notebook
    conda install jupyter notebook
  2. 将环境与vs code的interpreter链接
    首先找到环境的路径:
    conda env list
    添加该环境路径中的,bin中的,python3文件到vs code中。
  3. 验证安装
    跑一个程序,打开Activity Monitor。
    如果你在“Kind”下看到“Apple”,这意味着程序是在M1芯片上本地运行的,而不是在Rosetta模拟器下。

2022-01-17 19:08:13 完成

你可能感兴趣的:(Mac m1 深度学习环境配置)