-
Notifications
You must be signed in to change notification settings - Fork 826
将setup.py的编译方式写入官方文档 #5582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
将setup.py的编译方式写入官方文档 #5582
Changes from 4 commits
557c7ca
475d76f
e456579
7d7e6f9
84dc1d0
7f05b4e
24b136d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,13 +137,8 @@ git checkout develop | |
|
||
注意:python3.6、python3.7 版本从 release/1.2 分支开始支持, python3.8 版本从 release/1.8 分支开始支持, python3.9 版本从 release/2.1 分支开始支持, python3.10 版本从 release/2.3 分支开始支持 | ||
|
||
#### 7. 创建并进入/paddle/build 路径下: | ||
|
||
``` | ||
mkdir -p /paddle/build && cd /paddle/build | ||
``` | ||
|
||
#### 8. 使用以下命令安装相关依赖: | ||
#### 7. 使用以下命令安装相关依赖: | ||
|
||
- 安装 protobuf。 | ||
|
||
|
@@ -159,8 +154,15 @@ pip3.7 install protobuf | |
apt install patchelf | ||
``` | ||
|
||
#### 8. 可使用以下两种方式编译 PaddlePaddle: | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 叙述8.1及8.2之前可以先介绍一下,目前支持2种编译安装方式、简要说明区别是什么,推荐setup There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好 |
||
#### 9. 执行 cmake: | ||
##### 8.1. 方式一:使用 cmake,make 编译 PaddlePaddle: | ||
|
||
###### 8.1.1. 请创建并进入一个叫 build 的目录下: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 创建并进入/paddle/build 路径下: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok,我加上 |
||
``` | ||
mkdir build && cd build | ||
``` | ||
###### 8.1.2. 执行 cmake: | ||
|
||
* 对于需要编译**CPU 版本 PaddlePaddle**的用户: | ||
``` | ||
|
@@ -177,7 +179,7 @@ apt install patchelf | |
|
||
- 我们目前不支持 CentOS 6 下使用 Docker 编译 GPU 版本的 PaddlePaddle | ||
|
||
#### 10. 执行编译: | ||
###### 8.1.3. 执行编译: | ||
|
||
使用多核编译 | ||
|
||
|
@@ -188,13 +190,13 @@ make -j$(nproc) | |
注意: | ||
编译过程中需要从 github 上下载依赖,请确保您的编译环境能正常从 github 下载代码。 | ||
|
||
#### 11. 编译成功后进入`/paddle/build/python/dist`目录下找到生成的`.whl`包: | ||
###### 8.1.4. 编译成功后进入`/paddle/build/python/dist`目录下找到生成的`.whl`包: | ||
|
||
``` | ||
cd /paddle/build/python/dist | ||
``` | ||
|
||
#### 12. 在当前机器或目标机器安装编译好的`.whl`包: | ||
###### 8.1.5. 在当前机器或目标机器安装编译好的`.whl`包: | ||
|
||
|
||
For Python3: | ||
|
@@ -205,8 +207,58 @@ pip3.7 install -U [whl 包的名字] | |
注意: | ||
以上用 Python3.7 命令来举例,如您的 Python 版本为 3.6/3.8/3.9,请将上述命令中的 pip3.7 改成 pip3.6/pip3.8/pip3.9。 | ||
|
||
#### 恭喜,至此您已完成 PaddlePaddle 的编译安装。您只需要进入 Docker 容器后运行 PaddlePaddle,即可开始使用。更多 Docker 使用请参见[Docker 官方文档](https://docs.docker.com) | ||
###### 恭喜,至此您用方式一已完成 PaddlePaddle 的编译安装。您只需要进入 Docker 容器后运行 PaddlePaddle,即可开始使用。更多 Docker 使用请参见[Docker 官方文档](https://docs.docker.com) | ||
|
||
##### 8.2. 使用 setup.py 编译 PaddlePaddle: | ||
|
||
###### 8.2.1. export 环境变量控制编译选项: | ||
|
||
* 对于需要编译**CPU 版本 PaddlePaddle**的用户: | ||
``` | ||
export PY_VERSION=3.7 WITH_GPU=OFF | ||
``` | ||
|
||
* 对于需要编译**GPU 版本 PaddlePaddle**的用户: | ||
``` | ||
export PY_VERSION=3.7 WITH_GPU=ON | ||
``` | ||
- 此处 export 的环境变量即为 camke 编译选项,具体编译选项含义请参见[编译选项表](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/install/Tables.html#Compile) | ||
|
||
- 请注意修改参数`PY_VERSION`为您希望编译使用的 python 版本, 例如`export PY_VERSION=3.7`表示 python 版本为 3.7 | ||
|
||
- 我们目前不支持 CentOS 6 下使用 Docker 编译 GPU 版本的 PaddlePaddle | ||
|
||
###### 8.2.2. 进入/paddle 目录下执行 setup.py 进行编译和打包,以下三种命令 install,develop,bdist_wheel 均可: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这句主要是介绍功能、不太适合作为标题 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好的,我改一下 |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在介绍install、develop、bdist_wheel的一开始,建议说明在什么样的场景下推荐哪种方式,然后再逐个介绍使用方式 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好的 |
||
* install 命令将包直接安装到 python 环境下,如在 python3.7 环境下,将.egg 包拷贝到"python3.7/site-packages"下。 | ||
``` | ||
python3.7 setup.py install | ||
``` | ||
|
||
* develop 命令在 python 环境中创建一个软链接指向包实际所在目录。 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 软链接是哪里指向哪里,最好根据这里教程的示例写清楚 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好,从site-package下指向到build/python |
||
``` | ||
python3.7 setup.py develop | ||
``` | ||
|
||
上例中,`develop 命令`不会拷贝包到本地 Python 环境的`python3.7/site-packages`目录下,而是在 site-packages 目录下创建一个指向当前项目位置(build/python)的软链接。好处在于如果当前位置的源码被改动,再次执行`python3.7 setup.py develop`就会立刻反应到”site-packages”里,便于 debug。 | ||
|
||
* bdist_wheel 命令编译得到.whl 包,编译完成后得到的.whl 包保存在/paddle/dist 目录下,需要手动通过 pip install 命令安装.whl 包到 python 环境。 | ||
``` | ||
python3.7 setup.py bdist_wheel | ||
|
||
cd /paddle/dist | ||
|
||
pip3.7 install -U [whl 包的名字] | ||
``` | ||
其它适用小功能: | ||
1 `export MAX_JOBS=xxx`,xxx 为具体数字可控制使用多核编译,若不指定,默认为$(nproc); | ||
2 `export BUILD_DIR=xxx`,xxx 为所指定的存放编译产物的目录,若不指定,默认为 build 目录; | ||
3 `export CMAKE_GENERATOR=xxx`,xxx 为所指定的 cmake 生成器,如`export CMAKE_GENERATOR=Ninja` 使用 ninja 加速编译,默认为`Unix Makefiles`。 | ||
|
||
注意: | ||
以上用 Python3.7 命令来举例,如您的 Python 版本为 3.8/3.9/3.10 等,请将上述命令中的 python 改成 python3.7/python3.8/python3.9,pip 同理. | ||
|
||
###### 恭喜,至此您已完成 PaddlePaddle 的编译安装。您只需要进入 Docker 容器后运行 PaddlePaddle,即可开始使用。更多 Docker 使用请参见[Docker 官方文档](https://docs.docker.com) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 和上面的"恭喜,至此您已完成 PaddlePaddle 的编译安装"重复了,在整体介绍完2种编译安装方式之后,写一次即可 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 好,删掉一个 |
||
|
||
<a name="ct_source"></a> | ||
### <span id="compile_from_host">本机编译</span> | ||
|
@@ -478,13 +530,17 @@ cd Paddle | |
git checkout develop | ||
``` | ||
|
||
#### 10. 并且请创建并进入一个叫 build 的目录下: | ||
##### 10. 可使用以下两种方式编译 PaddlePaddle: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 本部分意见和和上面的意见一致 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok,thks,我尽快改下 |
||
|
||
``` | ||
mkdir build && cd build | ||
``` | ||
##### 10.1. 方式一:使用 cmake,make 编译 PaddlePaddle: | ||
|
||
#### 11. 执行 cmake: | ||
###### 10.1.1. 请创建并进入一个叫 build 的目录下: | ||
|
||
``` | ||
mkdir build && cd build | ||
``` | ||
|
||
###### 10.1.2. 执行 cmake: | ||
|
||
>具体编译选项含义请参见[编译选项表](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/install/Tables.html#Compile) | ||
|
||
|
@@ -541,9 +597,7 @@ mkdir build && cd build | |
注意:以上涉及 Python3 的命令,用 Python3.7 来举例,如您的 Python 版本为 3.8/3.9,请将上述命令中的 Python3.7 改成 Python3.8/Python3.9 | ||
|
||
|
||
|
||
|
||
#### 12. 使用以下命令来编译: | ||
###### 10.1.3. 使用以下命令来编译: | ||
|
||
``` | ||
make -j$(nproc) | ||
|
@@ -553,12 +607,12 @@ make -j$(nproc) | |
|
||
> 如果编译过程中显示“Too many open files”错误时,请使用指令 ulimit -n 8192 来增大当前进程允许打开的文件数,一般来说 8192 可以保证编译完成。 | ||
|
||
#### 13. 编译成功后进入`/paddle/build/python/dist`目录下找到生成的`.whl`包: | ||
###### 10.1.4. 编译成功后进入`/paddle/build/python/dist`目录下找到生成的`.whl`包: | ||
``` | ||
cd /paddle/build/python/dist | ||
``` | ||
|
||
#### 14. 在当前机器或目标机器安装编译好的`.whl`包: | ||
###### 10.1.5. 在当前机器或目标机器安装编译好的`.whl`包: | ||
|
||
``` | ||
pip install -U(whl 包的名字) | ||
|
@@ -568,8 +622,62 @@ pip install -U(whl 包的名字) | |
pip3 install -U(whl 包的名字) | ||
``` | ||
|
||
#### 恭喜,至此您已完成 PaddlePaddle 的编译安装 | ||
###### 恭喜,至此您已使用方式一完成 PaddlePaddle 的编译安装 | ||
|
||
##### 10.2. 方式二:使用 setup.py 编译 PaddlePaddle: | ||
|
||
###### 10.2.1. export 环境变量控制编译选项: | ||
|
||
* 对于需要编译**CPU 版本 PaddlePaddle**的用户: | ||
``` | ||
export PY_VERSION=3.7 WITH_GPU=OFF PYTHON_INCLUDE_DIR=${PYTHON_INCLUDE_DIRS} PYTHON_LIBRARY=${PYTHON_LIBRARY} | ||
``` | ||
也可不指定`PYTHON_INCLUDE_DIR`和`PYTHON_LIBRARY`,此时 setup.py 会自动匹配这两个编译选项的合适路径,您只需: | ||
``` | ||
export PY_VERSION=3.7 WITH_GPU=OFF | ||
``` | ||
|
||
* 对于需要编译**GPU 版本 PaddlePaddle**的用户:(**仅支持 CentOS7(CUDA11.2/CUDA11.0/CUDA10.2/CUDA10.1)**) | ||
|
||
1. 请确保您已经正确安装 nccl2,或者按照方式一中的指令指令安装 nccl2,如果您已经正确安装了 nccl2,可进行下面操作:(For Python3: 请给 PY_VERSION 参数配置正确的 python 版本) | ||
|
||
``` | ||
export PYTHON_EXECUTABLE=[您可执行的 Python3 的路径] PYTHON_INCLUDE_DIR:PATH=[之前的 PYTHON_INCLUDE_DIRS] -DPYTHON_LIBRARY:FILEPATH=[之前的 PYTHON_LIBRARY] WITH_GPU=ON | ||
``` | ||
当然,也可不指定`PYTHON_EXECUTABLE`,`PYTHON_INCLUDE_DIR`和`PYTHON_LIBRARY`,此时 setup.py 会自动匹配这三个编译选项的合适路径,您只需: | ||
``` | ||
export WITH_GPU=ON | ||
``` | ||
注意:以上涉及 Python3 的命令,用 Python3.7 来举例,如您的 Python 版本为 3.8/3.9,请将上述命令中的 Python3.7 改成 Python3.8/Python3.9 | ||
|
||
###### 10.2.2. 进入/paddle 目录执行 setup.py 进行编译和打包,以下三种命令 install,develop,bdist_wheel 均可: | ||
|
||
* install 命令将包直接安装到 python 环境下,如在 python3.7 环境下,将.egg 包拷贝到"python3.7/site-packages"下。 | ||
``` | ||
python3.7 setup.py install | ||
``` | ||
|
||
* develop 命令在 python 环境中创建一个软链接指向包实际所在目录。 | ||
``` | ||
python3.7 setup.py develop | ||
``` | ||
|
||
上例中,`develop 命令`不会拷贝包到本地 Python 环境的`python3.7/site-packages`目录下,而是在 site-packages 目录下创建一个指向当前项目位置(build/python)的软链接。好处在于如果当前位置的源码被改动,再次执行`python3.7 setup.py develop`就会立刻反应到”site-packages”里,便于 debug。 | ||
|
||
* bdist_wheel 命令编译得到.whl 包,编译完成后得到的.whl 包保存在/paddle/dist 目录下,需要手动通过 pip install 命令安装.whl 包到 python 环境。 | ||
``` | ||
python3.7 setup.py bdist_wheel | ||
|
||
cd /paddle/dist | ||
|
||
pip3.7 install -U [whl 包的名字] | ||
``` | ||
其它适用小功能: | ||
1 `export MAX_JOBS=xxx`,xxx 为具体数字可控制使用多核编译,若不指定,默认为$(nproc); | ||
2 `export BUILD_DIR=xxx`,xxx 为所指定的存放编译产物的目录,若不指定,默认为 build 目录; | ||
3 `export CMAKE_GENERATOR=xxx`,xxx 为所指定的 cmake 生成器,如`export CMAKE_GENERATOR=Ninja` 使用 ninja 加速编译,默认为`Unix Makefiles`。 | ||
|
||
###### 恭喜,至此您已使用方式二完成 PaddlePaddle 的编译安装 | ||
## **验证安装** | ||
安装完成后您可以使用 `python` 或 `python3` 进入 python 解释器,输入 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用以下任意一种方式编译安装Paddle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok,get