pip install, python setup.py, egg-info的说明--以Nvidia Apex安装为例

Install Nvidia Apex

若第一次安装需要把项目从github克隆到本地

Clean the old install before rebuilding:

pip uninstall apex
cd apex_repo_dir
rm -rf build (if present)
rm -rf apex.egg-info (if present)

Install package:

注:–no-cache-dir功能: 1. 不使用缓存在pip目录下的cache中的文件;2.也不保存在安装过程中需要的或者下次重新安装时需要的一些文件

pip install -v --no-cache-dir --global-option=“–cpp_ext” --global-option=“–cuda_ext” ./
或者
python setup.py install --cuda_ext --cpp_ext

扩展1. pip install --editable . vs python setup.py develop

转载自
Try to avoid calling setup.py directly, it will not properly tell pip that you’ve installed your package.

With pip install -e:

其中 -e 选项全称是–editable. For local projects, the “SomeProject.egg-info” directory is created relative to the project path (相对于此项目目录的路径). This is one advantage over just using setup.py develop, which creates the “egg-info” directly relative the current working directory (相对于当前工作环境目录的路径).

扩展2. 弄懂一个命令 pip3 install --editable '.[train,test]'

例子在这里
When you then did pip install --editable ., the command installs the Python package in the current directory
(signified by the dot .) with the optional dependencies needed for training and
testing (‘[train,test]’). 上面的安装命令中,-e选项全称是–editable,也就是可编辑的意思,以可继续开发的模式进行安装, ‘.’ 表示当前目录,也就是setup.py存在的
那个目录,此时pip install将会把包安装在当前文件目录下,而不是安装到所使用的python环境中的-site-packages。

[train,test] 只是我们举的一个例字,是可选参数,在setup.py中可以找到这两个选项(也可能叫其他名字或者根本就没有)之下包含了哪些第三方包。

扩展3. 别忘了pip其他丰富的功能

例如把clone和安装某个github上项目的命令压缩成一个
pip install git+http://127.0.0.1/xxx/demo.git

pip命令下直接制定所用的本地代理和镜像源
pip install --proxy http://127.0.0.1:8003 --user --index-url https://pypi.mirrors.ustc.edu.cn/simple/ einops

扩展4. 关于egg-info

注意⚠️:选则本地安装pip install .成功安装完成后,apex.egg-info文件夹可以只处于当前项目文件夹下而不是安装在系统环境中,只需要在当前使用的python虚拟环境-site-packages中一个指向该egg-info文件的超链接即可(这个是在本地安装自动的行为,不需要我们关心操作),这样就能找到使用Apex包时所需的apex.egg-info文件夹里的信息。

PS: 如果遇到Cuda版本不兼容的问题,解决办法见(升级pytoch 1.3后 cuda10.1不匹配版本的警告已经消失):

https://github.com/NVIDIA/apex/issues/350#issuecomment-500390952

如果没有出现其他error,可以直接使用上面链接的建议,删除版本检查抛出的报错。见以下讨论:

https://github.com/NVIDIA/apex/issues/350

https://github.com/NVIDIA/apex/pull/323

Apex的使用

命令行启动训练

—也是如何Pycharm运行时添加命令行参数的例子

python -m torch.distributed.launch --nproc_per_node=4 train_distributed.py
不使用命令行运行,而是使用Pycharm启动同步夸卡训练的配置

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值