기술공부/파이토치

mac M1, M2에서 GPU

넹넹선생님 2024. 4. 17. 13:56
728x90
반응형

- M1, M2 Apple silicon 칩에서 pytorch GPU 가속이 가능하게 됨

 

환경: Mac M1

 

1. 해당하는 miniconda 설치

https://docs.anaconda.com/free/miniconda/index.html

필자는 "Miniconda3 macOS Apple M1 64-bit pkg"으로 진행

 

설치 완료되었는지 확인:

터미널에 conda 입력

- 결과: 

더보기

usage: conda [-h] [-v] [--no-plugins] [-V] COMMAND ...

conda is a tool for managing and deploying applications, environments and packages.

options:
  -h, --help          Show this help message and exit.
  -v, --verbose       Can be used multiple times. Once for detailed output,
                      twice for INFO logging, thrice for DEBUG logging, four
                      times for TRACE logging.
  --no-plugins        Disable all plugins that are not built into conda.
  -V, --version       Show the conda version number and exit.

commands:
  The following built-in and plugins subcommands are available.

  COMMAND
    activate          Activate a conda environment.
    clean             Remove unused packages and caches.
    compare           Compare packages between conda environments.
    config            Modify configuration values in .condarc.
    content-trust     Signing and verification tools for Conda
    create            Create a new conda environment from a list of specified
                      packages.
    deactivate        Deactivate the current active conda environment.
    doctor            Display a health report for your environment.
    export            Export a given environment
    info              Display information about current conda install.
    init              Initialize conda for shell interaction.
    install           Install a list of packages into a specified conda
                      environment.
    list              List installed packages in a conda environment.
    notices           Retrieve latest channel notifications.
    package           Create low-level conda packages. (EXPERIMENTAL)
    remove (uninstall)
                      Remove a list of packages from a specified conda
                      environment.
    rename            Rename an existing environment.
    repoquery         Advanced search for repodata.
    run               Run an executable in a conda environment.
    search            Search for packages and display associated information
                      using the MatchSpec format.
    update (upgrade)  Update conda packages to the latest compatible version.

콘다 사용법에 대해 알려줌

 

2. conda 사용 시 필요 패키지 설치

conda create -n torch python==3.10
conda activate torch
conda update --all
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 -c pytorch

 

3. GPU 가속 가능여부 확인

터미널에 다음과 같이 입력

% python

>> torch.backends.mps.is_available()

>> torch.backends.mps.is_built() 

 

둘 다 True나오면 가속 가능

 

Apple silicon -> model.to(’mps’) 으로 GPU 가속이 가능

(Before) CUDA -> model.to(’cuda’) 

728x90
반응형

'기술공부 > 파이토치' 카테고리의 다른 글

torch.max  (0) 2024.08.01
.view(), .reshape()  (0) 2022.10.24