최근 cpu를 사용하여 pytorch 코드를 배우면서 gpu의 절실함을 느끼게 되었다..ㅎㅎㅎ
gpu 사용하는게 까다로워보여 cpu를 고집했지만...어쩔 수 없이 gpu 시도
그런데...! Mac os에서는 이미 gpu가 내장되어있어 세상 사용하기 쉬웠다....이런....
*혹시나 pytorch 버전으로 고생하시는 분들을 위해 pytorch 호환 버전 링크를 모아놓았다. 참고해서 버전을 호환시키면 된다 .
1. 본인 환경에서 pytorch 버전 확인
https://pytorch.org/get-started/locally/
2. pytorch 호환 버전
https://pytorch.org/get-started/previous-versions/
PyTorch
An open source machine learning framework that accelerates the path from research prototyping to production deployment.
pytorch.org
3. torchtext 호환버전
# !pip install torch==1.8.0 torchtext==0.9.0 여러 시도를 해보았지만..해당 버전에서만 작동됨
- 이 경우 gpu사용이 불가한 것인가...?
LINER | Collect Your Favorites
In the flood of information, LINER helps you find and learn reliable information faster. Discover the highlights of the web, filtered by millions of intelligent people around the world.
getliner.com
본격적으로 mac os에서 gpu 사용방법은 다음과 같다 (pytorch 1.12.0 버전 이상)
참고 블로그: https://bio-info.tistory.com/184
# conda 이용 pytorch 최신 버전 설치
conda install -c pytorch pytorch
#device에 적용하는 코드
device = torch.device('mps:0' if torch.backends.mps.is_available() else 'cpu')
#mps 지원 확인
print (f"PyTorch version:{torch.__version__}") # 1.12.1 이상
print(f"MPS 장치를 지원하도록 build 되었는지: {torch.backends.mps.is_built()}") # True 여야 합니다.
print(f"MPS 장치가 사용 가능한지: {torch.backends.mps.is_available()}") # True 여야 합니다.
!python -c 'import platform;print(platform.platform())'
이렇게 결과값이 뜨면 성공!
테스트 해 볼 수 있는 간단한 코드는 참고 링크로 걸어두었다:)
'Jee's 알쓸신잡' 카테고리의 다른 글
시각화 방법 가이드라인 (0) | 2023.10.29 |
---|---|
[에러 반환] assert vs. raise (0) | 2023.08.27 |
pyenv로 환경 만들기 (0) | 2023.08.27 |
kaggle 데이터를 local Jupyter notebook으로 (0) | 2023.04.13 |
Jupyter notebook 마크다운 글 스타일 변경 방법 (0) | 2023.04.03 |