From aa342a2da6eaa1d9e4647750ad17683c6537a29a Mon Sep 17 00:00:00 2001 From: Aurelius84 Date: Thu, 3 Nov 2022 11:12:38 +0800 Subject: [PATCH] Add six for @to_static and add CI approval (#47575) * Add six for @to_static and add CI approval * add six * refine logic * delete approve * fix return * add ImportError * typo `moduels` -> `modules` Co-authored-by: Nyakku Shigure --- .../dygraph_to_static/convert_call_func.py | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/convert_call_func.py b/python/paddle/fluid/dygraph/dygraph_to_static/convert_call_func.py index b43c4e9d36..2ac1d6403c 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/convert_call_func.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/convert_call_func.py @@ -50,16 +50,7 @@ from paddle.fluid.dygraph.layers import Layer __all__ = ["convert_call"] -# TODO(liym27): A better way to do this. -BUILTIN_LIKELY_MODULES = [ - collections, - pdb, - copy, - inspect, - re, - numpy, - logging, -] + # The api(s) should be considered as plain function and convert # them into static layer code. PADDLE_NEED_CONVERT_APIS = [Sequential] @@ -99,6 +90,32 @@ def is_builtin(func, name=None): return False +def builtin_modules(): + """ + Return builtin modules. + """ + modules = [ + collections, + pdb, + copy, + inspect, + re, + numpy, + logging, + ] + try: + import six + + modules.append(six) + except ImportError: + pass # do nothing + + return modules + + +BUILTIN_LIKELY_MODULES = builtin_modules() + + def is_unsupported(func): """ Checks whether the func is supported by dygraph to static graph. -- GitLab