Skip to content
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

Setuptools #48301

Merged
merged 70 commits into from
Dec 5, 2022
Merged

Setuptools #48301

merged 70 commits into from
Dec 5, 2022

Conversation

risemeup1
Copy link
Contributor

@risemeup1 risemeup1 commented Nov 23, 2022

PR types

others

PR changes

others

Describe

在paddle支持setuptools打包工具,新增setup.py文件主要分为两个功能,1 封装cmake和make(暂不支持ninja加速,等ninja编译完成之后可支持);2 使用setuptools工具打包python目录;3 本地同时支持原来的cmake -> make -> pip install .whl逻辑和现在使用python setupt.py install的逻辑;4 现在将GPUps流水线换成了现在python setup.py install逻辑,其它的流水线里的有些逻辑或者流水线插件里需要依赖.whl包做操作,需要后续讨论下再替换;5 目前已经跑通了py3,GPUps,CINN,Build流水线里所有的单测

To Do:
1逐步在所有流水线上替换成python setup.py install命令
2 后期支持ninja加速编译

使用方法:
1 使用方法,如在gpu环境下:
原来:cmake .. -DPY_VERSION=3.7 -DWITH_GPU=ON ,然后make -j ,pip install .whl
现在:export PY_VERSION=3.7 WITH_GPU=ON,然后python setup.py develop或者install
若要设置make -j的核数,如可export MAX_JOBS=23

2 常用命令:
2.1python setup.py install:
将包直接安装到python环境中,install 会将文件复制到 site-packages python安装文件夹下, 如将包paddlepaddle_gpu-0.0.0-py3.7-linux-x86_64.egg 直接安装到/py3.7_env/lib/python3.7/site-packages

2.2 python setup.py develop:
develop 在 site-packages 中创建一个 .egg-link 文件> 目录,该方法不会真正的安装包,而是在系统环境中创建一个软链接指向包实际所在目录。即Creating /py3.7_env/lib/python3.7/site-packages/paddlepaddle-gpu.egg-link (link to build/python),这样在修改包之后不用再安装就能生效,便于调试

2.3 python setup.py cmake-only :
仅仅camke-only,cmake后即退出,然后执行ccmake build可以调整build选项,或者python setup.py或者install命令

2.4 python setup.py rerun-cmake:
重新cmake

3 其他功能后面陆续完善

@paddle-bot
Copy link

paddle-bot bot commented Nov 23, 2022

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

setup.py Outdated
subprocess.check_call(cmake_args)


def make_run(args, build_path, envrion_var):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest build_run

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

setup.py Outdated


def get_package_data_and_package_dir():

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete empyt lines

setup.py Outdated


def get_headers():

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete empty lines

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -63,9 +68,9 @@ if(WIN32)
OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
COMMAND
${CMAKE_COMMAND} -E copy_directory ${PADDLE_SOURCE_DIR}/python/paddle
${PADDLE_BINARY_DIR}/python/paddle/
${PADDLE_BINARY_DIR}/python/paddle/ if (NOT WITH_SETUP)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么写在了一行?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是pre-commit自动修改的

@@ -22,8 +22,13 @@ set(SETUP_LOG_FILE "setup.py.log")

set(FLUID_CORE_NAME "libpaddle")

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in
${CMAKE_CURRENT_BINARY_DIR}/setup.py)
if(WITH_SETUP)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe INSTALL_WITH_SETUP is clearer?
Where this environment variable is set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否都最好保持用WITH开头好一些呢?
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以

@@ -917,6 +917,160 @@ set +x
set -ex
fi
}

function run_linu_cpu_test_by_setup(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linu -> linux

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -917,6 +917,160 @@ set +x
set -ex
fi
}

function run_linu_cpu_test_by_setup(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数只是删除了pip install *.whl的逻辑吧,需要重新写一个函数么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我是觉得后期统一删除??先留着??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

相同逻辑太多,不易于维护,如果改动很小,尽量复用原逻辑

)
else:
if os.getenv("PY_VERSION") is None:
print("export PY_VERSION = %s" % platform.python_version())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个print如果是为了在编译日志中提示用户,可以优化一下描述


IS_WINDOWS = os.name == 'nt'


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete empty line

setup.py Outdated
IS_WINDOWS = os.name == 'nt'


# filter args of setup.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议删除该注释,与函数名无区别,该注释无意义

filter_args_list.append(arg)
return cmake_and_build, only_cmake, rerun_cmake, filter_args_list


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete empty line

setup.py Outdated
print("Start executing %s" % dist.script_name)
# get args of setup.py
dist.script_args = sys.argv[1:]
print("args of setup.py:%s" % dist.script_args)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print("Start executing %s" % dist.script_name)、print("args of setup.py:%s" % dist.script_args)
这两个print建议合并一个来打印解析结果

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已改成print("Start executing python {} {}".format(dist.script_name,dist.script_args))

function main() {
local CMD=$1
local parallel_number=$2
init
case $CMD in
build_only)
cmake_gen_and_build ${PYTHON_ABI:-""} ${parallel_number}
#cmake_gen_and_build ${PYTHON_ABI:-""} ${parallel_number}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete unused code

function main() {
local CMD=$1
local parallel_number=$2
init
case $CMD in
build_only)
cmake_gen_and_build ${PYTHON_ABI:-""} ${parallel_number}
#cmake_gen_and_build ${PYTHON_ABI:-""} ${parallel_number}
run_setup ${PYTHON_ABI:-""} ${parallel_number}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run_setup函数中如何指定的parallel_number?没有看到指定逻辑

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该把run_setuo后边的第二个参数parallel_number直接删掉,我们是在setup.py中设置的这部分逻辑

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这意味着用户无法设置编译并发度么?

@@ -3491,6 +3715,7 @@ function main() {
build_and_check_cpu)
set +e
cmake_gen_and_build ${PYTHON_ABI:-""} ${parallel_number}
#run_setup ${PYTHON_ABI:-""} ${parallel_number}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete unused code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -3665,7 +3890,9 @@ function main() {
build_mac
;;
cicheck_py37)
cmake_gen_and_build ${PYTHON_ABI:-""} ${parallel_number}
# cmake_gen_and_build ${PYTHON_ABI:-""} ${parallel_number}
# run_linux_cpu_test ${PYTHON_ABI:-""} ${PROC_RUN:-1}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete unused code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -3678,7 +3905,8 @@ function main() {
parallel_test
;;
build_gpubox)
cmake_gen_and_build ${PYTHON_ABI:-""} ${parallel_number}
#cmake_gen_and_build ${PYTHON_ABI:-""} ${parallel_number}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete unused code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor

@zhangbo9674 zhangbo9674 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@zhiqiu zhiqiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@phlrain phlrain self-requested a review December 5, 2022 06:20
@zhangbo9674 zhangbo9674 merged commit 9913da0 into PaddlePaddle:develop Dec 5, 2022
export PYTHON_EXECUTABLE=/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
export PYTHON_INCLUDE_DIR=/Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m/
export PYTHON_LIBRARY=/Library/Frameworks/Python.framework/Versions/3.6/lib/libpython3.6m.dylib
pip3.6 install --user -r ${PADDLE_ROOT}/python/requirements.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gsq7474741 这里新引入的python 3.6内容也需要清理下

lxsbupt pushed a commit to lxsbupt/Paddle that referenced this pull request Dec 17, 2022
* test

* test

* test

* test

* test

* suport setuptools for paddle

* modify paddle_build.sh

* modify paddle_build.sh

* modify paddle_build.sh

* modify paddle_build.sh

* modify paddle_build.sh

* test

* modify setup.py

* modify build_options

* modify build_options

* modify paddle_build.sh

* modify setup.py

* modify paddle_build.sh

* modify setup.py

* modify setup.py

* modify setup.py

* modify setup.py

* modfiy paddle_build.sh

* debug

* debug

* debug

* dddd

* debug

* debug

* debug

* debug

* debug

* debug

* debug

* debug

* debug

* fix bug that no version.py

* debug

* debug

* debug

* debug

* debug

* debug

* Delete .pre-commit-config.yaml

* debug

* support ninja

* support ninja

* debug

* debug

* debug

* support setuptools for paddle

* modify code style

* debug

* debug

* debug

* debug

* 取消make clean

* 取消make clean

* debug

* debug

* debug

* debug for py3

* debug

* debug

* debug

* 将mkdir_and_copy_file单独封装一个函数

* modify paddle_build.sh

* modify setup.py after zhangbo reviewd
@risemeup1 risemeup1 deleted the setuptools branch April 23, 2023 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants