Server
前提条件:
- 无 root 权限
- Ubuntu 16.04
- CUDA 9.0 (not necessary)
非 root 用户安装 cuda, cudnn
1. 下载安装 cuda
- 下载 TensorFlow 对应版本的 CUDA https://developer.nvidia.com/cuda-downloads
- 选择 linux 及对应系统之后,选择 runfile(local) 下载,即 ``linux -> x86_64 -> Ubuntu -> 16.04 -> runfile (local)’’
- 给文件运行权限 chmod +x filename.run 然后运行 ./filename.run
- 在协议中选择同意 (accept),不安装 driver installation (no),然后在安装 cuda 时选择个人用户的家目录,如 /home/yourname/cuda90,link 选择 no,samples 自己设定 (yes or no) 及安装目录,sudo 选择 no
- 修改个人用户的环境变量,环境变量文件 ~/.bashrc 位于家目录,即 /home/yourname/.bashrc (可用 vim ~/.bashrc 编辑),末尾添加如下语句 ;修改之后需 source ~/.bashrc 使环境变量生效,或另开终端
1
2export PATH=$HOME/VirtualEnv/cuda90/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/VirtualEnv/cuda90/lib64/
2. 查看 cuda 安装状态
- nvidia-smi 查看显卡驱动运行状态
- nvcc -V 查看 cuda-toolkit 安装是否成功
3. 安装 cudnn
- cudnn 的安装,官网下载 https://developer.nvidia.com/cudnn (需注册账号),解压到 cuda 所在的文件夹,tar -xzvf cuda-9.0-linux-x64-v7.4.2.24.tgz (输入自己下载的安装包名)
- 拷贝过去 cudnn -> cuda (cuda90 是个人用户家目录下的 /home/yourname/VirtualEnv/cuda90 ),注意路径正确
cp cuda/include/cudnn.h ~/VirtualEnv/cuda90/include/
cp cuda/lib64/libcudnn ~/VirtualEnv/cuda90/lib64*
*chmod a+r ~/VirtualEnv/cuda90/include/cudnn.h ~/VirtualEnv/cuda90/lib64/libcudnn **
4. 查看 cudnn 安装状态
cat ~/VirtualEnv/cuda90/include/cudnn.h | grep CUDNN_MAJOR -A5
显示
1 | $ cat ~/VirtualEnv/cuda90/include/cudnn.h | grep CUDNN_MAJOR -A5 |
则 cudnn 版本为 7.4.2
然后就可以安装自己想要安装的框架了
后续:编译框架的时候提示无 lcuda.so 动态库
解决办法:在 /usr/lib64/nvidia 中有,创建软链接到自己的安装 cuda 的目录 /home/liuao/cuda91/lib64 (i.e., /home/username/VirtualEnv/cuda90/lib64) 即可。
* 安装过程 (所用到的命令)
1 | install cuda |
非 root 用户安装自己的 Python
我的习惯是
- virtualenv 创建的虚拟环境都放在 VirtualEnv 文件夹下,命名格式 e.g., py36env, py35gnn, etc
- 家目录安装的不同版本 Python 都放在 software 文件夹下 (同时存放软件下载包),命名格式 e.g., python27, etc
1 | mkdir software |
非 root 用户安装 Python 包库
两种方法:
pip install –user package-name
virtualenv, virtualenvwrapper
方法一的卸载,pip uninstall package-name 即可,会先卸载个人目录下的包。如果个人目录和系统目录有同名包,随后使用 sudo 卸载系统包即可。
方法二更方便环境隔离,可以自行配置多个环境。
方法三是用 docker,暂未尝试。
非 root 用户在服务器上配置自己的环境,使用 pip install –user package 设置自己的虚拟环境
1 | $ pip install --user virtualenv virtualwrapper |
Remote (Local - Server)
TensorBoard 远程访问
远程连接
在本地/虚拟机 (Ubuntu 16.04) 中
- 终端 其中 16006:127.0.0.1 代表自己机器上的 16006 号端口,6006 是服务器上 TensorBoard 使用的端口
1
ssh -L 16006:127.0.0.1:6006 yourname@server.address
- 在浏览器中打开 http://127.0.0.1:16006
- 服务器上 ctrl+c 关闭后,本地即无法连接
- 本地终端 exit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21ubuntu@VirtualBox:~$ ssh -L 16006:127.0.0.1:6006 yourname@server.address
yourname@server.address's password:
Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-141-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
79 packages can be updated.
4 updates are security updates.
New release '18.04.1 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
*** System restart required ***
Last login: Thu Feb 7 15:46:49 2019 from 10.231.238.49
yourname@server.address:~$ exit
logout
Connection to server.address closed.
ubuntu@VirtualBox:~$
使用
Usage: $ tensorboard --logdir=folder_path
- between Local Steps 1 & 2
- 在服务器上开启 TensorBoard
1
tensorboard --logdir=./network
e.g.,
1 | ubuntu@VirtualBox:~$ ssh -L 16006:127.0.0.1:6006 yourname@server.address |
Jupyter notebook 远程访问
仍以非 root 用户身份安装
1, 安装步骤
(1) 登录服务器
1 | ~$ source ~/VirtualEnv/py36env/bin/activate |
(2) 检查是否有安装 jupyter notebook
终端输入 jupyter nootbook ,如果报错就是没有安装,用下列命令安装
1 | (py36env) ~$ #pip install pyzmq tornado jinja2 jsonschema |
(3) 生成配置文件
1 | (py36env) ~$ jupyter notebook --generate-config |
(4) 生成密码 (后续写配置文件、登录 Jupyter notebook 时需要)
打开Python终端,我输入的密码是 1234
1 | (py36env) ~$ python |
(5) 修改默认配置文件
1 | (py36env) ~$ vim ~/.jupyter/jupyter_notebook_config.py |
进行如下修改(这里可以自行配置):
1 | c.NotebookApp.ip = '*' #允许所有ip访问 |
(6) 启动 Jupyter notebook
1 | (py36env) ~$ jupyter notebook |
注意:服务器的 ip,不需要加自己的用户名,即 ‘server.address’ 即可,若写成 ‘username@server.address‘ 会报错,说其并非是一个 ip 地址
1 | Traceback (most recent call last): |
注意:c.NotebookApp.ip 的问题及报错
1 | #(1) c.NotebookApp.ip = 'username@server.address' |
(7) 远程访问
此时应该可以直接从本地浏览器直接访问 http://address_of_remote:8888 就可以看到 jupyter 的登录页面。(注意服务器上的 Jupyter notebook 不要关)
PyCharm
Deployment
Tools -> Deployment -> Configuration
+server, and remember to “Save password”
Tools -> Deployment -> Options
click “Create empty directions”
Python interpreter
File -> Settings
Project: your_name -> Project Interpreter
add the python path on the server, remember to “Move this server to IDE settings“ instead of “Create copy of this deployment server in IDE settings”
Edit Sync Folders (Local Path, Remote Path)
其它配置
autopep8
File -> Settings -> Tools -> External Tools -> +
Program:C:\Python35\Scripts\autopep8.exe
Parameters:–in-place –ignore=E123,E133,E50 “$FilePath$“
Working directory:$FileDir$
在PyCharm环境配置Autopep8到菜单栏
PyCharm 使用 autopep8 按 PEP8 风格自动排版 Python 代码
Local
Ubuntu 16.04 (alongside Win 7)
我双系统安装失败了,现在只能用 Ubuntu,一启动 Win 7 就花屏
Windows 10
Bitvise SSH Client
可以写个 .sh 然后 nohup 执行。
如果不用 nohup,一旦关闭终端/连接断掉,这个脚本就会停止执行
1 | vim yourtask.sh |
GitHub
1 | git checkout branchname |