[返回电脑前线首页]·[所有跟帖]·[ 回复本帖 ] ·[热门原创] ·[繁體閱讀]·[版主管理]
如何正确安装PyTorch on MacBook M1, M2
送交者: runcndottop[布衣] 于 2024-07-19 22:35 已读 28614 次 1 赞  

runcndottop的个人频道

How to set up a good PyTorch environment on Apple Silicon

Apple silicon refers to the arm64 architecture chips designed by Apple and used by new Macbook laptops, also known as M1, M2 Macbooks. It's different from old generations of Macbooks, because those use Intel x86_64 architecture chips. You can find out these information on your Macbook's system information. So why do you care? You care because you care about performance when you want to do AI, research, development, etc. It's best to get the best performance natively out of your Macbook instead of the other way round. So make sure you check whether you are installing a package built for arm64 or x86_64, before doing the real AI stuff. 6park.com

Install arm64 miniconda

The first step to make things right is to install the Miniconda version for MacOSX arm64: 6park.com

mkdir -p ~/miniconda3 curl https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh -o ~/miniconda3/miniconda.sh bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3 rm -rf ~/miniconda3/miniconda.sh

Install arm64 pytorch

Since we installed miniconda's arm64 version, it automatically installs the correct pytorch and python versions in the arm64 architecture for us, using the following command: 6park.com

conda create -n tutorial-1 python=3.11 pytorch -c pytorch

It installs the correct version for arm64, which you can see from the command's output, something like the this: 6park.com

pytorch pytorch/osx-arm64::pytorch-2.3.1-py3.11_0

Verify MPS support in pytorch

MPS stands for Metal Performance Shader, which is Apple's GPU programming language, corresponding to Nvidia's CUDA. We need MPS available so as to do efficient ML computation on Macbook's Apple Silicon. 6park.com

The code below should output no assertion errors if you are running it on Apple Silicon, as well as having installed the arm64 version of pytorch. 6park.com

import torch 6park.com

assert torch.backend.mps.is_available(), 'pytorch MPS not available' 6park.com

As of now, you have set up a good PyTorch environment that allows you to take adavantage of all the computational power Apple Silicon has to offer. Enjoy! 6park.com

原文看这儿: https://runcn.top/tutorials

评分完成:已经给本帖加上 20 银元!

6park.com

贴主:runcndottop于2024_07_22 13:56:10编辑 6park.com

贴主:runcndottop于2024_07_22 13:56:31编辑
贴主:runcndottop于2024_07_22 14:02:47编辑
喜欢runcndottop朋友的这个贴子的话, 请点这里投票,“赞”助支持!
[举报反馈]·[ runcndottop的个人频道 ]·[-->>参与评论回复]·[用户前期主贴]·[手机扫描浏览分享]·[返回电脑前线首页]
runcndottop 已标注本帖为原创内容,若需转载授权请联系网友本人。如果内容违规或侵权,请告知我们。

所有跟帖:        ( 主贴楼主有权删除不文明回复,拉黑不受欢迎的用户 )


用户名:密码:[--注册ID--]

标 题:

粗体 斜体 下划线 居中 插入图片插入图片 插入Flash插入Flash动画


     图片上传  Youtube代码器  预览辅助

手机扫描进入,浏览分享更畅快!

楼主本栏目热帖推荐:

>>>>查看更多楼主社区动态...






[ 留园条例 ] [ 广告服务 ] [ 联系我们 ] [ 个人帐户 ] [ 版主申请 ] [ Contact us ]