[GPU사용] Colab의 GPU를 vscode에서 사용하기

2021. 7. 5. 22:21노트/Others : 업무

1. Colab의 GPU를 vscode에 연결하여 사용함 

참고 : https://www.youtube.com/watch?v=oAKxxLy-G5g

 

  • vscode에 remote-ssh extension 설치

  • ngrok.com/get-started/setup 에서 Connect your account 복사 

  • Colab에 새 ipynb 파일 만들기 -> 런타임 유형 변경 -> 하드웨어 가속기 -> GPU
    NGROK_TOKEN = '위의 ngrok token 붙여넣기'
    PASSWORD = '111222333'​
  • Google Drive 마운트
from google.colab import drive
drive.mount('/content/drive/')

1) 온라인 에디터로 사용하는 방법 

from colabcode import ColabCode
ColabCode(port = 10000, password = PASSWORD)

2) 로컬 vscode 사용하는 방법 (colab-ssh로 연결 방법) 

# Install colab_ssh on google colab
!pip install colab_ssh --upgrade

from colab_ssh import launch_ssh_cloudflared
launch_ssh_cloudflared(PASSWORD)

Client machine configuration (처음 한번만 하면 됨.)

  • Download Cloudflared (당신의 로컬 운영체제에 맞는 cloudflared file download)
  • Terminal에서 version 확인 했을 때, 제대로 나오면 잘 설치 된 것
    • PS C:\Users\Administrator\Downloads\cloudflared-stable-windows-amd64> .\cloudflared.exe --version

 

  • SSH config file에 아래 내용 추가 
  • VSCode Remote SSH 
    • ctrl + shift + P and type "Connect to Host..."
    • kent-antigua-dining-.trycloudflare.com 입력

  • 비밀번호 입력 (위에 코랩 노트북에서 입력한 것)

  • 원하는 운영체제 선택 후 (저의 경우 linux 선택) Terminal 에서 nvidia-smi 입력 해서 확인