背景介绍:在训练、验证新模型时,需要使用jupyter notebook逐步执行,查看中间效果,服务器端无法提供可视化窗口,本地运行速度缓慢且容易出现CUDA:out of memory,因此,本地配置可以远程访问GPU及pytorch\tensorflow的Jupyter notebook可以方便完成本地编程远程运行,方便查看中间运行结果等优点。
配置方法:
1、服务器端配置jupyter notebook
# 1' 激活虚拟环境
source pytorch/bin/activate
# 2' 安装jupyter notebook
pip install jupyter
# 3' 设置jupyter notebook密码
jupyter notebook --generate-config
|-------------------------------------|
|>>from IPython.lib import passwd |
|>>passwd() |
|-------------------------------------|
# 2' 安装ipykernel
pip install ipykernel
# 3' 将环境写入notebook
python -m ipykernel install --user --name pytorch
# 4' 打开notebook,默认端口号8889
jupyter notebook
2、本地访问jupyter notebook
# win cmd下映射服务器端口
ssh -L 8889:127.0.0.1:8889 username@severport
# 打开jupyter notebook, 更改端口
http://localhost:8889/
3、测试