Slurm遠程登錄Jupyter Notebook


前言

  • 之前想利用實驗室的服務器資源(GPU和CPU)來運行jupyter notebook,但是現在實驗室使用slurm管理所有的節點,ssh只能登錄管理節點,再通過管理節點來申請資源或提交任務,因此不能通過ssh來直接訪問計算資源
  • 不能直接在管理節點上啟動jupyter,可以通過slurm腳本通過sbatch發送上去啟動jupyter,或者通過srun申請一個交互的bash,在其中啟動jupyter

實施

交互bash啟動jupyter

在服務器上啟動jupyter

srun -w sugon-gpu-x -c 4 --gres=gpu:V100:1 --pty bash //申請資源
source activate env_dl //啟動環境
jupyter notebook --no-browser --port=8879 --ip=sugon-gpu-x //啟動jupyter,指定port,指定ip
//目前服務器每個用戶對節點的占有時間有限制,另外為了防止斷連,tmux或nohup的使用自便

在本地連接jupyter

//8880為本地端口,sugon-gpu-x:8879為服務器jupyter指定ip和指定端口,your_name為用戶名,cluster_url為服務器ip
ssh -N -L 8880:sugon-gpu-x:8879 your_name@cluster_url 

打開瀏覽器通過 localhost:8880 訪問

// 對於瀏覽器要求的token,復制啟動jupyter后返回的信息中的token即可
"http://sugon-gpu-x:8879/?token=d5a9744d7ebf58fec4ebf133c******27fd74fb12bb896"

Slurm腳本啟動jupyter

參考:分享腳本遠程登陸 Jupyter Notebook
通過sbatch發射腳本上去啟動jupyter
腳本內容:

#!/bin/bash
#SBATCH --partition sugon
#SBATCH --nodes 1
#SBATCH --ntasks 1
#SBATCH --cpus-per-task 4
#SBATCH --gres=gpu:V100:1
#SBATCH --time 48:00:00
#SBATCH --job-name jupyter-notebook
#SBATCH --output ./Logs/jupyter-notebook-%J.log
#SBATCH --error ./Logs/jupyter-errors.log
#SBATCH --mail-user=xxx@act.buaa.edu.cn

# get tunneling info
XDG_RUNTIME_DIR=""
port=$(shuf -i8000-9999 -n1) # 可以固定下來
node=$(hostname -s)
user=$(whoami)
cluster=$(hostname -f | awk -F"." '{print $2}')

### 在這里添加你的服務器地址
clusterurl="192.168.5.xxx"

export PATH=$PATH:~/.local/bin

# print tunneling instructions jupyter-log
echo -e "
MacOS or linux terminal command to create your ssh tunnel:
ssh -N -L ${port}:${node}:${port} ${user}@${clusterurl}
 
 Here is the MobaXterm info:

 Forwarded port:same as remote port
 Remote server: ${node}
 Remote port: ${port}
 SSH server: ${cluster}.${clusterurl}
 SSH login: $user
 SSH port: 22

 Use a Browser on your local machine to go to:
 localhost:${port} (prefix w/ https:// if using password)

 or copy the token from the error file"

 # load modules or conda environments here
 # e.g. farnam:
 # module load Python/2.7.13-foss-2016b 
 # conda env activate mx
 # DON'T USE ADDRESS BELOW. 
 # DO USE TOKEN BELOWa

 source activate env_dl
 jupyter-notebook --no-browser --port=${port} --ip=${node}

之后查看Logs/文件夾下的log文件和error文件,從log文件中找到本地連接方式(與前面的相同),從error文件中找到token

ssh -N -L xxxx:sugon-gpu-x:xxxx your_name@cluster_url


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM