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#

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 完成

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容