填坑之旅—QGDT(CPU版)
创建指定环境的虚拟环境
1 2 3 4 5
| os:linux package manager:conda python:3.5 cuda:None pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.0-
|
$ conda create -n cpu python=3.5
$ source activate cpu
$ conda install pytorch-cpu torchvision-cpu -c pytorch
安装依赖
1 2
| (cpu) pzs741@Ex-treme:~/PycharmProjects/QGDT-branch (cpu) $ pip install -i https://pypi.douban.com/simple -r requirements.txt
|
测试“原”代码
1 2 3 4 5 6
| python QGDT-branch (cpu)/example/example.py err:AttributeError: module 'torch._C' has no attribute '_cuda_getDevice' 1.首先用把device直接改成'cpu‘ 2.再用CPU训练一个RNNLM模型 3.再次测试 通过!
|
发布分支版本
1 2 3 4 5 6 7 8 9 10
| #创建分支 git branch cpu #切换分支 git checkout cpu #查看分支 git branch -a # 删除分支 git push origin --delete cpu # 发布分支 git push origin cpu
|
上传到pypi
1 2 3 4 5 6
| 修改setup的版本号和包名称 我的分支版本号是0.3.0 包名称是QGDT-cpu $ rm -rf build/ dist/ QGDT.egg-info/ $ python setup.py bdist_wheel --universal $ twine upload dist/*
|
下载测试
1 2 3 4 5 6 7 8 9 10 11 12
| **第一步很重要,CPU版本的torch要预先安装,要不然默认GPU版本** conda install pytorch-cpu torchvision-cpu -c pytorch 1.虚拟环境下测试 source activate cpu pip install QGDT-cpu python >>> import QGDT 2.本地测试 pip uninstall QGDT pip install QGDT-cpu python >>> import QGDT
|
云服务器实测
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| $ ssh root@39.105.124.151 -i xxx.pem $ wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.2.0-Linux-x86_64.sh $ chmod 777 Anaconda.sh $ ./Anaconda.sh $ nano ~/.bashrc export PATH=/root/anaconda3/bin:$PATH $ source ~/.bashrc $ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/(两次置顶) $ conda config --set show_channel_urls yes $ conda install pytorch-cpu torchvision-cpu -c pytorch $ pip uninstall QGDT $ git clone -b cpu https://github.com/pzs741/QGDT.git $ pip install QGDT/dist/*.wheel $ python QGDT/example/example.py 通过!
|