코렙의 GPU 사용
1. 코렙에서 device 변경하는 방법
- 상단 메뉴 -> 런타임 -> 런타임 유형 변경 -> 하드웨어 가속기를 T4 GPU or TPU로 변경 -> 저장 -> 세션 다시 시작 및 모두 실행
tensor = torch.rand(3, 4)
print(f'shape: {tensor.shape}')
print(f'dtype: {tensor.dtype}')
print(f'device: {tensor.device}')
# 결과값 =>
# shape: torch.Size([3, 4])
# dtype: torch.float32
# device: cpu
# is_available() : gpu 사용할 수 있는지 여부
tensor = tensor.reshape(4, 3)
tensor = tensor.int()
if torch.cuda.is_available():
print('GPU를 사용할 수 있음')
tensor = tensor.to('cuda')
print(f'shape: {tensor.shape}')
print(f'dtype: {tensor.dtype}')
print(f'device: {tensor.device}')
# 결과값 =>
# GPU를 사용할 수 있음
# shape: torch.Size([4, 3])
# dtype: torch.int32
# device: cuda:0
※ 만약 맥북을 사용하면서 jupyter notebook을 이용하여 GPU를 사용하고 싶으면 아래의 블로그를 토대로 설정하시면 됩니다.
https://selfhiam.tistory.com/109
맥북 M1, M2, M2 Pro Pytorch GPU가속화 사용하기
해당 내용은 Anaconda를 사용하지 않고 진행하였습니다 제품 사항 : Apple M2 pro 1. 제품의 GPU가속 진행전 제품 지원을 확인합니다. https://pytorch.org/get-started/locally/ Start Locally Start Locally pytorch.org 들어
selfhiam.tistory.com
'Study > GoogleColab' 카테고리의 다른 글
[GoogleColab] AIhub데이터를 코렙에서 다운로드 받기 (4) | 2024.02.28 |
---|---|
Colab Python Day10_2 (0) | 2023.09.14 |
Colab Python Day10_1 (0) | 2023.09.14 |
Colab Python Day9_2 (0) | 2023.09.13 |
Colab Python Day9_1 (0) | 2023.09.13 |