SAM 너무 느리다. GPU vs CPU 속도가 무슨 20배 차이...;
맥북 GPU 사용하면 서버 GPU만큼은 아니어도 좀 빠르게 가능할까 싶어서 셋팅하는 글이다.
환경
- 맥북
- M1 Max
- MacOS: 13.0 이상 (14.1.1 사용중)
이유: "RuntimeError: MPS support binary op with uint8 natively starting from macOS 13.0" 에러가 나중에 뜬다.
Q. 맥북에서 가속이 가능한가?
A. 가능하다.
device에 cpu or cuda를 지정해줬었는데, torch.device("mps") 이렇게 mps를 쓰면 된다.
글 참고: https://devocean.sk.com/blog/techBoardDetail.do?ID=163957
Q. MPS가 뭐지?
MPS 설명: https://dong-life.tistory.com/112 이 글을 읽으면 될듯.
Multi-Process Service (MPS)
환경 셋업1: homebrew, pip 설치
있으면 건너뛰어도 되는데 homebrew 설치하고, pip 설치하고, 경로를 설정해줬다.
참고했던 것
- https://www.takjakim.kr/macos/pip_install homebrew, pip
- https://stackoverflow.com/questions/42870537/zsh-command-cannot-found-pip 경로
환경 셋업2: conda 및 torch
설치 링크: https://pytorch.kr/get-started/locally/#mac-verification
- Stable 말고 Preview를 쓰자
발생 가능한 이슈
1.
conda path 설정하기: https://stackoverflow.com/questions/73615281/how-do-i-add-the-anaconda-path-to-the-path-environment-on-a-mac
2.
_C 무슨무슨 에러: Cython install로 해결
https://github.com/pytorch/pytorch/issues/1633
3. conda update 적용
conda update -n base -c defaults conda
4.
Stable 말고 Preview를 쓰라는 얘기는 여기 참고
https://github.com/pytorch/pytorch/issues/96610#issuecomment-1490930132
설치 확인
- import torch 해보고, 변수 만들어서 동작하는지 확인
- torch.device("mps") 동작 하는지 확인
여기까지 되면 SAM 설치한다.
돌리려는 모델: Segment Anything
https://github.com/facebookresearch/segment-anything#installation
GitHub - facebookresearch/segment-anything: The repository provides code for running inference with the SegmentAnything Model (S
The repository provides code for running inference with the SegmentAnything Model (SAM), links for downloading the trained model checkpoints, and example notebooks that show how to use the model. -...
github.com
실험 결과
- 30번 평균 낸 결과, 1.65초 소요. 서버 GPU에서 0.5초였고, CPU에서는 10초 가까이 걸렸던걸 생각하면 꽤 빠른 속도.
- 사용 할만한듯.
- 백본 크기에 따라 다를 수 있다. 이 글을 참고하자: https://kongsberg.tistory.com/4
참고 자료
- https://sebastianraschka.com/blog/2022/pytorch-m1-gpu.html
'딥러닝 어쩌구 > 연구일지&디버깅' 카테고리의 다른 글
[디버깅] Streamlit 데모 만들기... (0) | 2023.11.28 |
---|---|
Colab, CineScale (0) | 2023.06.26 |
(ing) fundamental matrix를 활용하여 이미지 이어붙이기 (1) | 2023.06.01 |
streamlit: 연구 주간보고 미팅용 시각화 툴 (0) | 2023.05.08 |
[2022.12.22] 텐서플로우... 버전... 고통... 디버깅... 못함... (0) | 2022.12.22 |
댓글