M1 맥북에서 MPS 사용이 되지 않습니다.

안녕하세요 알기 쉽게 정리해주심에 감사드립니다.
환경들이 모두 갖춰져 있는데, mps 인식을 하지 못하는 것 같아 질문을 여쭈고 싶습니다.
image
image
차이나는 점은 dev20220519, dev20220520 차이인 듯 한데, 이외에도 신경써야할 부분이 있을까요?

감사합니다.

안녕하세요, @wazs555 님.

올려주신 스크린샷을 보니까 PyTorch가 MPS를 지원하지 않고 있는 것 같습니다.

혹시 PyTorch Preview 버전을 어떻게 설치하셨는지 알려주실 수 있으실까요?
Preview 버전의 경우 매일 밤 빌드가 되고 있기 때문에 버전은 큰 이슈가 아닐 것 같습니다.

아래는 제가 오늘 기존 버전(dev20220520)을 삭제하고 동일한 버전(dev20220520)으로 재설치한 것인데요,
동일한 버전에서 torch.backends.mps.is_built()True를 반환하는 것을 보실 수 있습니다

$ pip uninstall torch
Found existing installation: torch 1.12.0.dev20220519
Uninstalling torch-1.12.0.dev20220519:
  Would remove:
    /Users/reserve/.pyenv/versions/3.8.13/envs/torchmps/bin/convert-caffe2-to-onnx
    /Users/reserve/.pyenv/versions/3.8.13/envs/torchmps/bin/convert-onnx-to-caffe2
    /Users/reserve/.pyenv/versions/3.8.13/envs/torchmps/bin/torchrun
    /Users/reserve/.pyenv/versions/3.8.13/envs/torchmps/lib/python3.8/site-packages/caffe2/*
    /Users/reserve/.pyenv/versions/3.8.13/envs/torchmps/lib/python3.8/site-packages/torch-1.12.0.dev20220519.dist-info/*
    /Users/reserve/.pyenv/versions/3.8.13/envs/torchmps/lib/python3.8/site-packages/torch/*
    /Users/reserve/.pyenv/versions/3.8.13/envs/torchmps/lib/python3.8/site-packages/torchgen/*
Proceed (Y/n)? y
  Successfully uninstalled torch-1.12.0.dev20220519
$ pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/nightly/cpu
Collecting torch
  Downloading https://download.pytorch.org/whl/nightly/cpu/torch-1.12.0.dev20220520-cp38-none-macosx_11_0_arm64.whl (48.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 48.1/48.1 MB 18.4 MB/s eta 0:00:00
Requirement already satisfied: torchvision in ./.pyenv/versions/3.8.13/envs/torchmps/lib/python3.8/site-packages (0.12.0)
Requirement already satisfied: torchaudio in ./.pyenv/versions/3.8.13/envs/torchmps/lib/python3.8/site-packages (0.11.0)
Requirement already satisfied: typing-extensions in ./.pyenv/versions/3.8.13/envs/torchmps/lib/python3.8/site-packages (from torch) (4.2.0)
Requirement already satisfied: numpy in ./.pyenv/versions/3.8.13/envs/torchmps/lib/python3.8/site-packages (from torchvision) (1.22.3)
Requirement already satisfied: requests in ./.pyenv/versions/3.8.13/envs/torchmps/lib/python3.8/site-packages (from torchvision) (2.27.1)
Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in ./.pyenv/versions/3.8.13/envs/torchmps/lib/python3.8/site-packages (from torchvision) (9.1.1)
Requirement already satisfied: certifi>=2017.4.17 in ./.pyenv/versions/3.8.13/envs/torchmps/lib/python3.8/site-packages (from requests->torchvision) (2022.5.18.1)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in ./.pyenv/versions/3.8.13/envs/torchmps/lib/python3.8/site-packages (from requests->torchvision) (1.26.9)
Requirement already satisfied: charset-normalizer~=2.0.0 in ./.pyenv/versions/3.8.13/envs/torchmps/lib/python3.8/site-packages (from requests->torchvision) (2.0.12)
Requirement already satisfied: idna<4,>=2.5 in ./.pyenv/versions/3.8.13/envs/torchmps/lib/python3.8/site-packages (from requests->torchvision) (3.3)
Installing collected packages: torch
Successfully installed torch-1.12.0.dev20220520
WARNING: You are using pip version 22.0.4; however, version 22.1 is available.
You should consider upgrading via the '/Users/reserve/.pyenv/versions/3.8.13/envs/torchmps/bin/python3.8 -m pip install --upgrade pip' command.
$ python
Python 3.8.13 (default, Mar 31 2022, 14:14:05)
[Clang 13.1.6 (clang-1316.0.21.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.__version__)
1.12.0.dev20220520
>>> print(torch.backends.mps.is_built())
True
>>> print(torch.backends.mps.is_available())
True
>>>

더불어 묻고 답하기 게시판으로 주제를 옮겼습니다. :slight_smile:
제목은 제가 임의로 작성하였는데 변경해주셔도 좋을 것 같습니다.

답변 감사드립니다!
아나콘다를 이용해 설치를 진행하였으며, 해당 내용을 코드블럭으로 공유드리겠습니다.

(base)  ~  conda create -n mac_gpu_test
Collecting package metadata (current_repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.9.2
  latest version: 4.12.0

Please update conda by running

    $ conda update -n base -c defaults conda



## Package Plan ##

  environment location: /Users/yuhwanseung/opt/anaconda3/envs/mac_gpu_test



Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate mac_gpu_test
#
# To deactivate an active environment, use
#
#     $ conda deactivate


(base)  ✘  ~  conda activate mac_gpu_test
(mac_gpu_test)  ~  conda install pytorch torchvision torchaudio -c pytorch-nightly
Collecting package metadata (current_repodata.json): done
Solving environment: done


==> WARNING: A newer version of conda exists. <==
  current version: 4.9.2
  latest version: 4.12.0

Please update conda by running

    $ conda update -n base -c defaults conda



## Package Plan ##

  environment location: /Users/yuhwanseung/opt/anaconda3/envs/mac_gpu_test

  added / updated specs:
    - pytorch
    - torchaudio
    - torchvision


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    brotlipy-0.7.0             |py310hca72f7f_1002         342 KB
    certifi-2022.5.18.1        |  py310hecd8cb5_0         148 KB
    cffi-1.15.0                |  py310hc55c11b_1         221 KB
    cryptography-37.0.1        |  py310hf6deb26_0         1.1 MB
    mkl-service-2.4.0          |  py310hca72f7f_0          47 KB
    mkl_fft-1.3.1              |  py310hf879493_0         174 KB
    mkl_random-1.2.2           |  py310hc081a56_0         292 KB
    numpy-1.22.3               |  py310hdcd3fac_0          11 KB
    numpy-base-1.22.3          |  py310hfd2de13_0         5.3 MB
    pillow-9.0.1               |  py310hde71d04_0         639 KB
    pip-21.2.4                 |  py310hecd8cb5_0         1.8 MB
    pysocks-1.7.1              |  py310hecd8cb5_0          28 KB
    python-3.10.4              |       hdfd78df_0        13.3 MB
    pytorch-1.12.0.dev20220520 |         py3.10_0        74.2 MB  pytorch-nightly
    setuptools-61.2.0          |  py310hecd8cb5_0        1020 KB
    torchaudio-0.12.0.dev20220520|        py310_cpu         5.4 MB  pytorch-nightly
    torchvision-0.13.0.dev20220520|        py310_cpu         6.3 MB  pytorch-nightly
    urllib3-1.26.9             |  py310hecd8cb5_0         185 KB
    ------------------------------------------------------------
                                           Total:       110.5 MB

The following NEW packages will be INSTALLED:

  blas               pkgs/main/osx-64::blas-1.0-mkl
  brotlipy           pkgs/main/osx-64::brotlipy-0.7.0-py310hca72f7f_1002
  bzip2              pkgs/main/osx-64::bzip2-1.0.8-h1de35cc_0
  ca-certificates    pkgs/main/osx-64::ca-certificates-2022.4.26-hecd8cb5_0
  certifi            pkgs/main/osx-64::certifi-2022.5.18.1-py310hecd8cb5_0
  cffi               pkgs/main/osx-64::cffi-1.15.0-py310hc55c11b_1
  charset-normalizer pkgs/main/noarch::charset-normalizer-2.0.4-pyhd3eb1b0_0
  cryptography       pkgs/main/osx-64::cryptography-37.0.1-py310hf6deb26_0
  ffmpeg             pkgs/main/osx-64::ffmpeg-4.2.2-h97e5cf8_0
  freetype           pkgs/main/osx-64::freetype-2.11.0-hd8bbffd_0
  gettext            pkgs/main/osx-64::gettext-0.21.0-h7535e17_0
  giflib             pkgs/main/osx-64::giflib-5.2.1-haf1e3a3_0
  gmp                pkgs/main/osx-64::gmp-6.2.1-h23ab428_2
  gnutls             pkgs/main/osx-64::gnutls-3.6.15-hed9c0bf_0
  icu                pkgs/main/osx-64::icu-58.2-h0a44026_3
  idna               pkgs/main/noarch::idna-3.3-pyhd3eb1b0_0
  intel-openmp       pkgs/main/osx-64::intel-openmp-2021.4.0-hecd8cb5_3538
  jpeg               pkgs/main/osx-64::jpeg-9e-hca72f7f_0
  lame               pkgs/main/osx-64::lame-3.100-h1de35cc_0
  lcms2              pkgs/main/osx-64::lcms2-2.12-hf1fd2bf_0
  libcxx             pkgs/main/osx-64::libcxx-12.0.0-h2f01273_0
  libffi             pkgs/main/osx-64::libffi-3.3-hb1e8313_2
  libiconv           pkgs/main/osx-64::libiconv-1.16-hca72f7f_2
  libidn2            pkgs/main/osx-64::libidn2-2.3.2-h9ed2024_0
  libopus            pkgs/main/osx-64::libopus-1.3.1-h1de35cc_0
  libpng             pkgs/main/osx-64::libpng-1.6.37-ha441bb4_0
  libtasn1           pkgs/main/osx-64::libtasn1-4.16.0-h9ed2024_0
  libtiff            pkgs/main/osx-64::libtiff-4.2.0-hdb42f99_1
  libunistring       pkgs/main/osx-64::libunistring-0.9.10-h9ed2024_0
  libuv              pkgs/main/osx-64::libuv-1.40.0-haf1e3a3_0
  libvpx             pkgs/main/osx-64::libvpx-1.7.0-h378b8a2_0
  libwebp            pkgs/main/osx-64::libwebp-1.2.2-h56c3ce4_0
  libwebp-base       pkgs/main/osx-64::libwebp-base-1.2.2-hca72f7f_0
  libxml2            pkgs/main/osx-64::libxml2-2.9.12-hbf8cd5e_2
  llvm-openmp        pkgs/main/osx-64::llvm-openmp-12.0.0-h0dcd299_1
  lz4-c              pkgs/main/osx-64::lz4-c-1.9.3-h23ab428_1
  mkl                pkgs/main/osx-64::mkl-2021.4.0-hecd8cb5_637
  mkl-service        pkgs/main/osx-64::mkl-service-2.4.0-py310hca72f7f_0
  mkl_fft            pkgs/main/osx-64::mkl_fft-1.3.1-py310hf879493_0
  mkl_random         pkgs/main/osx-64::mkl_random-1.2.2-py310hc081a56_0
  ncurses            pkgs/main/osx-64::ncurses-6.3-hca72f7f_2
  nettle             pkgs/main/osx-64::nettle-3.7.3-h230ac6f_1
  numpy              pkgs/main/osx-64::numpy-1.22.3-py310hdcd3fac_0
  numpy-base         pkgs/main/osx-64::numpy-base-1.22.3-py310hfd2de13_0
  openh264           pkgs/main/osx-64::openh264-2.1.1-h8346a28_0
  openssl            pkgs/main/osx-64::openssl-1.1.1o-hca72f7f_0
  pillow             pkgs/main/osx-64::pillow-9.0.1-py310hde71d04_0
  pip                pkgs/main/osx-64::pip-21.2.4-py310hecd8cb5_0
  pycparser          pkgs/main/noarch::pycparser-2.21-pyhd3eb1b0_0
  pyopenssl          pkgs/main/noarch::pyopenssl-22.0.0-pyhd3eb1b0_0
  pysocks            pkgs/main/osx-64::pysocks-1.7.1-py310hecd8cb5_0
  python             pkgs/main/osx-64::python-3.10.4-hdfd78df_0
  pytorch            pytorch-nightly/osx-64::pytorch-1.12.0.dev20220520-py3.10_0
  readline           pkgs/main/osx-64::readline-8.1.2-hca72f7f_1
  requests           pkgs/main/noarch::requests-2.27.1-pyhd3eb1b0_0
  setuptools         pkgs/main/osx-64::setuptools-61.2.0-py310hecd8cb5_0
  six                pkgs/main/noarch::six-1.16.0-pyhd3eb1b0_1
  sqlite             pkgs/main/osx-64::sqlite-3.38.3-h707629a_0
  tk                 pkgs/main/osx-64::tk-8.6.11-h3fd3227_1
  torchaudio         pytorch-nightly/osx-64::torchaudio-0.12.0.dev20220520-py310_cpu
  torchvision        pytorch-nightly/osx-64::torchvision-0.13.0.dev20220520-py310_cpu
  typing_extensions  pkgs/main/noarch::typing_extensions-4.1.1-pyh06a4308_0
  tzdata             pkgs/main/noarch::tzdata-2022a-hda174b7_0
  urllib3            pkgs/main/osx-64::urllib3-1.26.9-py310hecd8cb5_0
  wheel              pkgs/main/noarch::wheel-0.37.1-pyhd3eb1b0_0
  x264               pkgs/main/osx-64::x264-1!157.20191217-h1de35cc_0
  xz                 pkgs/main/osx-64::xz-5.2.5-hca72f7f_1
  zlib               pkgs/main/osx-64::zlib-1.2.12-h4dc903c_2
  zstd               pkgs/main/osx-64::zstd-1.5.2-hcb37349_0


Proceed ([y]/n)? y


Downloading and Extracting Packages
urllib3-1.26.9       | 185 KB    | ############################################################################################################# | 100%
mkl_fft-1.3.1        | 174 KB    | ############################################################################################################# | 100%
setuptools-61.2.0    | 1020 KB   | ############################################################################################################# | 100%
cffi-1.15.0          | 221 KB    | ############################################################################################################# | 100%
brotlipy-0.7.0       | 342 KB    | ############################################################################################################# | 100%
torchaudio-0.12.0.de | 5.4 MB    | ############################################################################################################# | 100%
certifi-2022.5.18.1  | 148 KB    | ############################################################################################################# | 100%
pysocks-1.7.1        | 28 KB     | ############################################################################################################# | 100%
pip-21.2.4           | 1.8 MB    | ############################################################################################################# | 100%
numpy-1.22.3         | 11 KB     | ############################################################################################################# | 100%
python-3.10.4        | 13.3 MB   | ############################################################################################################# | 100%
pytorch-1.12.0.dev20 | 74.2 MB   | ############################################################################################################# | 100%
cryptography-37.0.1  | 1.1 MB    | ############################################################################################################# | 100%
mkl_random-1.2.2     | 292 KB    | ############################################################################################################# | 100%
mkl-service-2.4.0    | 47 KB     | ############################################################################################################# | 100%
numpy-base-1.22.3    | 5.3 MB    | ############################################################################################################# | 100%
torchvision-0.13.0.d | 6.3 MB    | ############################################################################################################# | 100%
pillow-9.0.1         | 639 KB    | ############################################################################################################# | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(mac_gpu_test)  ~  python
Python 3.10.4 (main, Mar 31 2022, 03:38:35) [Clang 12.0.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
i>>> import torch
>>> print(torch.__version__)
1.12.0.dev20220520
>>> print(torch.backends.mps.is_built())
False
>>> print(torch.backends.mps.is_available())
False
>>>

시간내주심에 감사드립니다

안녕하세요, @wazs555 님.
혹시 위 이슈는 M1에서 MPS 장치를 불러올 수 없습니다. - 9bow님의 글 #5@SoHaeng_Lee 님과 유사한 이슈가 아닐까요? :thinking:

@SoHaeng_Lee 님께서 M1에서 MPS 장치를 불러올 수 없습니다. - 9bow님의 글 #7 에 답변 달아주셨습니다!

Platform이 arm64인지 확인해보시면 좋을 것 같습니다. :slight_smile:

@SoHaeng_Lee @9bow
그 동안 도와주신 선생님들께.
드디어 됐습니다! SoHaeng님과 9bow님께서 큰 도움주셔서 마무리할 수 있었습니다.
여기 작성된 방법과 동일하다고 생각됩니다.

다른 분들께서도 저와 같은 어려움이 있을 수도 있을 것 같아 정리해서 작성해봅니다.

  1. 첫 번째로 anaconda의 버전을 고려해야합니다. 저의 경우 m1이 나온지 얼마 안된 상태에서 anaconda를 설치하여 mps가 True가 안되는 문제가 존재했습니다.
  2. 현재 Anaconda 페이지를 들어가게 되면 arm-64를 지원하는 conda가 배포중입니다. 이를 다운받고 이 전 anaconda는 삭제했습니다.
  3. 2번까지 수행했을 때, 기존과 다른 양상이 나타났습니다.
conda install pytorch torchvision torchaudio -c pytorch-nightly

기존에는 conda를 이용해서 설치했을 때, 모두 문제없이 설치가 됐었는데 이번의 경우, torchvision과 torchaudio는 설치 되지 않았습니다. -> 그래서 9bow님께서 친절히 설명해주신 pip3 설치방법으로 설치하였습니다.

pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu

여기까지 진행된다면 python open 후, mps가 정상적으로 작동하는 것을 확인할 수 있었습니다.

다시 한번 도와주신 분들께 감사인사를 드립니다.

2개의 좋아요

잘 되신다니 다행입니다! :tada:

알려주신 내용을 정리해서 기존 FAQ에 추가해두겠습니다 :smiley:

행렬 크기가 클수록 속도 차이가 많이납니다만, 너무 크게하면 오류가 뜹니다.
아직은 pytorch 베타버전이란 그런것 같습니다.

CPU와 MPS 차이가 단순연산에선 최대 100배 정도 나는것 같습니다.

위의 소스도 함께 올립니다.


import sys
import torch
import platform
import time

print("OS version : ",platform.platform())
print("Python version : ",sys.version)
print(“Torch Version : “,torch._ version _)
print(””)

print("MPS Bulit : ",torch.backends.mps.is_built())
print(“MPS avail : “,torch.backends.mps.is_available())
print(””)

a=torch.rand(10000,5000)
b=torch.rand(5000,10000)
tic=time.time()
torch.matmul(a,b)
toc=time.time()
print(a.device," : ",toc-tic)

c=torch.rand(10000,5000).to(“mps”)
d=torch.rand(5000,10000).to(“mps”)
tic=time.time()
torch.matmul(c,d)
toc=time.time()
print(c.device," : ",toc-tic)


3개의 좋아요