首页 > 其他分享 >pytorch在Mac上实现像cuda一样的加速

pytorch在Mac上实现像cuda一样的加速

时间:2024-04-01 21:55:58浏览次数:25  
标签:torch pytorch print Mac MPS mps device cuda

1. 参考:https://developer.apple.com/metal/pytorch/ 
2. 具体实现:
  2.1 Requirements

      Mac M芯片或者AMD的GPU

      macOS 12.3 or later

      Python 3.7 or later

      Xcode command-line tools: xcode-select --install

  2.2  准备anaconda或者miniconda或者自带的pip3
    conda安装:
conda install pytorch torchvision torchaudio -c pytorch-nightly
    pip安装:
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu


3.如何实现应用
import torch
if torch.backends.mps.is_available():
    mps_device = torch.device("mps")
    x = torch.ones(1, device=mps_device)
    print (x)
else:
    print ("MPS device not found.")

# if not torch.backends.mps.is_available():
#     if not torch.backends.mps.is_built():
#         print("MPS not available because the current PyTorch install was not "
#               "built with MPS enabled.")
#     else:
#         print("MPS not available because the current MacOS version is not 12.3+ "
#               "and/or you do not have an MPS-enabled device on this machine.")
# mps_device = torch.device("mps")
# x = torch.ones(5, device=mps_device)
# # 或者 x = torch.ones(5, device="mps")
# y = x * 2
# model = YourFavoriteNet()
# model.to(mps_device)
# pred = model(x)

 

 

标签:torch,pytorch,print,Mac,MPS,mps,device,cuda
From: https://www.cnblogs.com/wwly/p/18109467

相关文章

  • Pytorch - Dataloader
    BasicallytheDataLoaderworkswiththeDatasetobject.SotousetheDataLoaderyouneedtogetyourdataintothisDatasetwrapper.Todothisyouonlyneedtoimplementtwomagicmethods:__getitem__and__len__.The__getitem__takesanindexandretu......
  • 【PyTorch 实战2:UNet 分类模型】10min揭秘 UNet 分割网络如何工作以及pytorch代码实现
    UNet网络详解及PyTorch实现一、UNet网络原理  U-Net,自2015年诞生以来,便以其卓越的性能在生物医学图像分割领域崭露头角。作为FCN的一种变体,U-Net凭借其Encoder-Decoder的精巧结构,不仅在医学图像分析中大放异彩,更在卫星图像分割、工业瑕疵检测等多个领域展现出强大的应用......
  • 下载安装 macOS 版本的 Windows 远程桌面客户端(Microsoft Remote Desktop)
    如果有非国区的账号,直接在商店中下载即可:https://apps.apple.com/us/app/microsoft-remote-desktop/id1295203466?mt=12国区是搜不到的,微软提供了beta版本下载:https://install.appcenter.ms/orgs/rdmacios-k2vy/apps/microsoft-remote-desktop-for-mac/distribution_groups/al......
  • cleanmymac有必要买吗?cleanmymac免费使用
    在使用mac时,小编遇到了运行内存不足、硬盘空间不足的情况。遇到这种情况,我们可以借助经典的电脑深度清理软件——CleanMyMacX,清理不常用的软件和系统垃圾,非常好用!不过,有许多网友发现CleanMyMacX有免费和收费两个版本,那cleanmymac有必要买吗?小编今天就带大家了解下这款软件,......
  • 模拟游戏《幸福工厂》好玩吗?《幸福工厂》怎么在mac电脑上打开?
    关于《幸福工厂》这款游戏是否好玩,普遍的玩家反馈和评价表明,《幸福工厂》(Satisfactory)因其深度的工厂建造模拟、自由度极高的探索以及精美的图形表现而受到许多玩家的喜爱。它允许玩家在一个开放的世界中规划并建立复杂的生产线,解决资源采集和物流问题,同时提供了一定的挑战性和......
  • macbook pip3路径报错
    执行pip3,提示:zsh:/usr/local/bin/pip3:badinterpreter:/Library/Developer/CommandLineTools/usr/bin/python3:nosuchfileordirectory问题:原因:python路径不正确方法:➜whichpython3/usr/local/bin/python➜bincd/usr/local/bin➜binvimpip3修改第一......
  • 1935B - Informatics in MAC
    这道题目考察了前缀和的思想以及对数学思维的理解,首先对于任意一组数组01710103考虑一下他们之间的MEX怎么分割,假设有两个数组{1,x},{x+1,n}要使得他们之间的MEX一样,则他们每个数组中都含有1~MEX-1个数(一定)那么把两个数组合并呢?两个数组合并之后MEX不变,则往下递推,假设分......
  • 使用镜像安装cuda12.1版本pytorch
    1.添加通道condaconfig--addchannelshttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/condaconfig--addchannelscondaconfig--addchannelshttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/condaconfig--addchannelshttps://mirrors.bfs......
  • WingPro for Mac(Python开发工具)
    了解更多相关内容请点击此处WingProforMac是一款Python开发环境,适用于Mac平台。它由Wingware公司开发,提供了一系列强工具,可以帮助Python开发人员轻松地编写、调试和测试Python代码。WingProforMac具有一个直观的用户界面,支持多种编程语言和框架,例如Django、Flask、Pyramid......
  • (译) 理解 Elixir 中的宏 Macro, 第二部分:宏理论
    ElixirMacros系列文章译文[1](译)UnderstandingElixirMacros,Part1Basics[2](译)UnderstandingElixirMacros,Part2-MicroTheory[3](译)UnderstandingElixirMacros,Part3-GettingintotheAST[4](译)UnderstandingElixirMacros,Part4-Div......