LoginSignup
1
0

More than 1 year has passed since last update.

Google ColabからさくらのクラウドのGPUサーバに接続する

Posted at

ssh port forwardingで接続します。

1.GPUサーバの作成

さくらのクラウドのコントロールパネルから、石狩第1ゾーンを選択し、サーバ追加画面を開きます。
サーバプランは GPUプラン を選択、ディスクのアーカイブは Ubuntu 22.04.1 LTS を選択します。
ディスクサイズは 100GB を選択します。

スクリーンショット 2023-03-17 10.26.35.png

2.GPUドライバのインストール

GPUサーバが完成したら、SSHでログインします。

NVIDIAのドキュメント通りにインストールを行う。
https://docs.nvidia.com/datacenter/tesla/tesla-installation-notes/index.html

$ sudo apt-get install linux-headers-$(uname -r)
$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID | sed -e 's/\.//g')
$ wget https://developer.download.nvidia.com/compute/cuda/repos/$distribution/x86_64/cuda-keyring_1.0-1_all.deb
$ sudo dpkg -i cuda-keyring_1.0-1_all.deb
$ sudo apt-get update
$ sudo apt-get -y install cuda-drivers

インストールが終わったら再起動を行う。

2.JupyterLabのインストール

以下のコマンドを実行します、全て完了したらssh接続をログアウトします。

$ sudo apt update
$ sudo apt install python3-pip
$ sudo pip install jupyterlab
$ sudo pip install jupyter_http_over_ws
$ jupyter serverextension enable --py jupyter_http_over_ws

3.Google ColabからさくらのクラウドのGPUサーバに接続する

ssh port forwardingを行うためにクライアントから以下のコマンドでGPUサーバにSSH接続します。

$ ssh -L 8888:localhost:8888 ubuntu@<GPUサーバのIPアドレス>

SSH接続後、GPUサーバで以下のコマンドを実行しJupyterLabを起動します。

$ jupyter notebook --NotebookApp.allow_origin='https://colab.research.google.com' --port=8888 --NotebookApp.port_retries=0 --ip=*

起動すると以下のような出力が表示されます。
出力下部の
http://127.0.0.1:8888/?token=************************************************
というURLをコピーしておきます。

$ jupyter notebook --NotebookApp.allow_origin='https://colab.research.google.com' --port=8888 --NotebookApp.port_retries=0 --ip=*

  _   _          _      _
 | | | |_ __  __| |__ _| |_ ___
 | |_| | '_ \/ _` / _` |  _/ -_)
  \___/| .__/\__,_\__,_|\__\___|
       |_|

Read the migration plan to Notebook 7 to learn about the new features and the actions to take if you are using extensions.

https://jupyter-notebook.readthedocs.io/en/latest/migrate_to_notebook7.html

Please note that updating to Notebook 7 might break some of your extensions.

[W 10:46:35.440 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
jupyter_http_over_ws extension initialized. Listening on /http_over_websocket
[W 10:46:36.327 NotebookApp] Loading JupyterLab as a classic notebook (v6) extension.
[C 10:46:36.328 NotebookApp] You must use Jupyter Server v1 to load JupyterLab as notebook extension. You have v2.4.0 installed.
    You can fix this by executing:
        pip install -U "jupyter-server<2.0.0"
[I 10:46:36.334 NotebookApp] Serving notebooks from local directory: /home/ubuntu
[I 10:46:36.334 NotebookApp] Jupyter Notebook 6.5.3 is running at:
[I 10:46:36.334 NotebookApp] http://jupyter:8888/?token=************************************************
[I 10:46:36.334 NotebookApp]  or http://127.0.0.1:8888/?token=************************************************
[I 10:46:36.334 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 10:46:36.342 NotebookApp] No web browser found: could not locate runnable browser.
[C 10:46:36.343 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///home/ubuntu/.local/share/jupyter/runtime/nbserver-867-open.html
    Or copy and paste one of these URLs:
        http://jupyter:8888/?token=************************************************
     or http://127.0.0.1:8888/?token=************************************************

Google Colabにアクセスし、新しいノートブックを開きます。
gpu1.png

右上の 接続 から ローカルランタイムに接続 をクリックします。
gpu2.png

先ほどコピーしたURLをペーストします。その際に、 127.0.0.1 となっている部分を localhost にします。
gpu3.png

接続済み (ローカル) と表示されたら接続完了です。
gpu4.png

!free -h!nvidia-smi コマンドを実行しGPUサーバに接続されていることを確認します。
以上で完了です。

gpu5.png

そのほか

  • Jupyter環境はdockerコンテナなどで立ち上げた方が便利かもしれません。お好みに応じて選択ください。
  • GPUサーバに使うOSをUbuntu DesktopにしてRDP/VNCなどでクライアントから接続し、そこからGoogle Colabに接続すれば直接Google Colabと接続できるので便利そうだなと思いました。
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0