未验证 提交 173ed8c2 编写于 作者: N Nyakku Shigure 提交者: GitHub

[CodeStyle][isort][Dy2St] sort imports for paddle.jit (#48637)

* isort jit

* refine comment
上级 0ffba1c9
......@@ -17,7 +17,4 @@ extend_skip_glob = [
"python/paddle/utils/gast/**",
"python/paddle/fluid/tests/unittests/npu/**",
"python/paddle/fluid/tests/unittests/mlu/**",
# These files will be fixed in the future
"python/paddle/jit/**",
]
......@@ -13,6 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# Temporary disable isort to avoid circular import
# This can be removed after the circular import is resolved
# isort: skip_file
import os
import pickle
import warnings
......
......@@ -12,15 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from paddle.jit.dy2static.static_analysis import AstNodeWrapper
from paddle.jit.dy2static.utils import ast_to_source_code
from paddle.utils import gast
from paddle.jit.dy2static.static_analysis import (
AstNodeWrapper,
)
from paddle.jit.dy2static.utils import ast_to_source_code
from .base_transformer import (
BaseTransformer,
)
from .base_transformer import BaseTransformer
__all__ = []
......
......@@ -18,57 +18,27 @@
# See details in https://github.com/serge-sans-paille/gast/
import os
from .base_transformer import (
BaseTransformer,
)
from .early_return_transformer import (
EarlyReturnTransformer,
)
from .assert_transformer import (
AssertTransformer,
)
from .basic_api_transformer import (
BasicApiTransformer,
)
from . import logging_utils
from .assert_transformer import AssertTransformer
from .base_transformer import BaseTransformer
from .basic_api_transformer import BasicApiTransformer
from .break_continue_transformer import (
BreakContinueTransformer,
BreakTransformOptimizer,
)
from .call_transformer import (
CallTransformer,
)
from .cast_transformer import (
CastTransformer,
)
from .typehint_transformer import (
TypeHintTransformer,
)
from .ifelse_transformer import (
IfElseTransformer,
)
from .logical_transformer import (
LogicalTransformer,
)
from .loop_transformer import (
LoopTransformer,
)
from .return_transformer import (
ReturnTransformer,
)
from .create_variable_transformer import (
CreateVariableTransformer,
)
from .static_analysis import (
StaticAnalysisVisitor,
)
from .tensor_shape_transformer import (
TensorShapeTransformer,
)
from .decorator_transformer import (
DecoratorTransformer,
)
from . import logging_utils
from .call_transformer import CallTransformer
from .cast_transformer import CastTransformer
from .create_variable_transformer import CreateVariableTransformer
from .decorator_transformer import DecoratorTransformer
from .early_return_transformer import EarlyReturnTransformer
from .ifelse_transformer import IfElseTransformer
from .logical_transformer import LogicalTransformer
from .loop_transformer import LoopTransformer
from .return_transformer import ReturnTransformer
from .static_analysis import StaticAnalysisVisitor
from .tensor_shape_transformer import TensorShapeTransformer
from .typehint_transformer import TypeHintTransformer
from .utils import ast_to_source_code
__all__ = []
......
......@@ -12,20 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from paddle.utils import gast
from paddle.fluid import unique_name
from paddle.jit.dy2static.utils import (
ORIGI_INFO,
FOR_ITER_INDEX_PREFIX,
FOR_ITER_VAR_LEN_PREFIX,
FOR_ITER_ITERATOR_PREFIX,
FOR_ITER_TARGET_PREFIX,
FOR_ITER_VAR_LEN_PREFIX,
FOR_ITER_VAR_NAME_PREFIX,
FOR_ITER_ZIP_TO_LIST_PREFIX,
FOR_ITER_ITERATOR_PREFIX,
create_assign_node,
ORIGI_INFO,
ast_to_source_code,
create_assign_node,
get_attribute_full_name,
)
from paddle.utils import gast
__all__ = []
......
......@@ -13,15 +13,12 @@
# limitations under the License.
import astor
from paddle.utils import gast
from .static_analysis import (
AstNodeWrapper,
)
from . import utils
from .base_transformer import (
BaseTransformer,
)
from .base_transformer import BaseTransformer
from .static_analysis import AstNodeWrapper
__all__ = []
......
......@@ -12,20 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from paddle.fluid import unique_name
from paddle.jit.dy2static.utils import BaseNodeVisitor, index_in_list
from paddle.jit.dy2static.variable_trans_func import create_bool_node
from paddle.utils import gast
from paddle.fluid import unique_name
from paddle.jit.dy2static.utils import index_in_list
from paddle.jit.dy2static.utils import BaseNodeVisitor
from paddle.jit.dy2static.variable_trans_func import (
create_bool_node,
)
from .base_transformer import (
BaseTransformer,
)
from .base_transformer import (
ForNodeVisitor,
)
from .base_transformer import BaseTransformer, ForNodeVisitor
__all__ = []
......
......@@ -12,16 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from paddle.jit.dy2static.static_analysis import AstNodeWrapper
from paddle.jit.dy2static.utils import ast_to_source_code, is_paddle_api
from paddle.utils import gast
from paddle.jit.dy2static.static_analysis import (
AstNodeWrapper,
)
from paddle.jit.dy2static.utils import ast_to_source_code
from paddle.jit.dy2static.utils import is_paddle_api
from .base_transformer import (
BaseTransformer,
)
from .base_transformer import BaseTransformer
PDB_SET = "pdb.set_trace"
......@@ -53,9 +48,7 @@ class CallTransformer(BaseTransformer):
func_str = ast_to_source_code(node.func).strip()
try:
from paddle.jit.dy2static.convert_call_func import (
is_builtin,
)
from paddle.jit.dy2static.convert_call_func import is_builtin
need_convert_builtin_func_list = {
'len',
......
......@@ -12,15 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from paddle.jit.dy2static.static_analysis import AstNodeWrapper
from paddle.jit.dy2static.utils import ast_to_source_code
from paddle.utils import gast
from paddle.jit.dy2static.static_analysis import (
AstNodeWrapper,
)
from paddle.jit.dy2static.utils import ast_to_source_code
from .base_transformer import (
BaseTransformer,
)
from .base_transformer import BaseTransformer
__all__ = []
......
......@@ -12,34 +12,31 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import builtins
import collections
import copy
import functools
import logging
import inspect
import logging
import pdb
import re
import types
import numpy
import builtins
from paddle.fluid.dygraph.container import Sequential
from paddle.fluid.dygraph.layers import Layer
from paddle.jit.dy2static.logging_utils import TranslatorLogger
from paddle.jit.dy2static.utils import is_paddle_func, unwrap
from .convert_operators import (
convert_len,
convert_zip,
convert_range,
convert_enumerate,
convert_len,
convert_print,
convert_range,
convert_zip,
)
from paddle.jit.dy2static.logging_utils import (
TranslatorLogger,
)
from paddle.jit.dy2static.utils import is_paddle_func, unwrap
from paddle.fluid.dygraph.layers import Layer
__all__ = []
......@@ -179,9 +176,9 @@ def convert_call(func):
"""
# NOTE(Aurelius84): Fix it after all files migrating into jit.
from paddle.jit.dy2static.program_translator import (
StaticFunction,
convert_to_static,
unwrap_decorators,
StaticFunction,
)
translator_logger.log(
......
......@@ -13,38 +13,29 @@
# limitations under the License.
import re
import paddle
from paddle.fluid.data_feeder import convert_dtype
from .variable_trans_func import (
to_static_variable,
)
from paddle.fluid.framework import core, Variable
from paddle.fluid.layers import Print
from paddle.fluid.framework import Variable, core
from paddle.fluid.layers import (
Print,
array_read,
array_write,
)
from paddle.fluid.layers import (
assign,
fill_constant,
)
from paddle.fluid.layers import (
cast,
control_flow,
fill_constant,
)
from paddle.fluid.layers.control_flow import (
while_loop,
)
from .return_transformer import (
RETURN_NO_VALUE_VAR_NAME,
)
from paddle.fluid.layers.control_flow import while_loop
from paddle.fluid.layers.utils import copy_mutable_vars
from paddle.jit.dy2static.utils import (
UndefinedVar,
Dygraph2StaticException,
GetterSetterHelper,
UndefinedVar,
)
from paddle.fluid.layers.utils import copy_mutable_vars
from .return_transformer import RETURN_NO_VALUE_VAR_NAME
from .variable_trans_func import to_static_variable
__all__ = []
......
......@@ -12,19 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from .static_analysis import (
AstNodeWrapper,
)
from .utils import (
FunctionNameLivenessAnalysis,
)
from .variable_trans_func import (
create_undefined_var,
)
from .base_transformer import (
BaseTransformer,
)
from .base_transformer import BaseTransformer
from .static_analysis import AstNodeWrapper
from .utils import FunctionNameLivenessAnalysis
from .variable_trans_func import create_undefined_var
__all__ = []
......
......@@ -13,21 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from paddle.utils import gast
from .static_analysis import (
AstNodeWrapper,
)
from .base_transformer import (
BaseTransformer,
)
from .utils import (
RE_PYNAME,
RE_PYMODULE,
ast_to_source_code,
)
import re
import warnings
import re
from paddle.utils import gast
from .base_transformer import BaseTransformer
from .static_analysis import AstNodeWrapper
from .utils import RE_PYMODULE, RE_PYNAME, ast_to_source_code
__all__ = []
......
......@@ -13,12 +13,9 @@
# limitations under the License.
from paddle.utils import gast
from .static_analysis import (
AstNodeWrapper,
)
from .base_transformer import (
BaseTransformer,
)
from .base_transformer import BaseTransformer
from .static_analysis import AstNodeWrapper
__all__ = []
......
......@@ -12,22 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import linecache
import os
import re
import sys
import traceback
import linecache
import re
import numpy as np # noqa: F401
from .origin_info import (
Location,
OriginInfo,
global_origin_info_map,
)
from .origin_info import Location, OriginInfo, global_origin_info_map
from .utils import _is_api_in_module_helper # noqa: F401
from .utils import RE_PYMODULE
__all__ = []
ERROR_DATA = "Error data about original source code information and traceback."
......
......@@ -12,24 +12,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import collections
import inspect
import numpy as np
import collections
import paddle
from paddle.fluid import core
from paddle.fluid.dygraph import layers
from paddle.fluid.layers.utils import flatten
from paddle.fluid.layers.utils import pack_sequence_as
from paddle.fluid.dygraph.base import switch_to_static_graph
from paddle.fluid.dygraph.io import TranslatedLayer
from paddle.fluid.layers.utils import flatten, pack_sequence_as
from . import logging_utils
from .utils import (
func_to_source_code,
parse_arg_and_kwargs,
parse_varargs_name,
type_name,
func_to_source_code,
)
__all__ = []
......
......@@ -15,48 +15,35 @@
import copy
from collections import defaultdict
# gast is a generic AST to represent Python2 and Python3's Abstract Syntax Tree(AST).
# It provides a compatibility layer between the AST of various Python versions,
# as produced by ast.parse from the standard ast module.
# See details in https://github.com/serge-sans-paille/gast/
from paddle.utils import gast
from paddle.fluid import unique_name
from paddle.jit.dy2static.utils import (
create_funcDef_node,
ast_to_source_code,
)
from paddle.jit.dy2static.utils import (
FunctionNameLivenessAnalysis,
)
from paddle.jit.dy2static.static_analysis import (
AstNodeWrapper,
)
from paddle.jit.dy2static.utils import (
create_nonlocal_stmt_nodes,
)
from paddle.jit.dy2static.utils import (
create_get_args_node,
create_set_args_node,
)
from .base_transformer import (
BaseTransformer,
)
from paddle.jit.dy2static.static_analysis import AstNodeWrapper
from paddle.jit.dy2static.utils import (
FOR_ITER_INDEX_PREFIX,
FOR_ITER_TUPLE_PREFIX,
FOR_ITER_ITERATOR_PREFIX,
FOR_ITER_TARGET_PREFIX,
FOR_ITER_TUPLE_INDEX_PREFIX,
FOR_ITER_TUPLE_PREFIX,
FOR_ITER_VAR_LEN_PREFIX,
FOR_ITER_VAR_NAME_PREFIX,
FOR_ITER_ZIP_TO_LIST_PREFIX,
FOR_ITER_TARGET_PREFIX,
FOR_ITER_ITERATOR_PREFIX,
)
from paddle.jit.dy2static.utils import (
FunctionNameLivenessAnalysis,
GetterSetterHelper,
ast_to_source_code,
create_funcDef_node,
create_get_args_node,
create_name_str,
create_nonlocal_stmt_nodes,
create_set_args_node,
)
# gast is a generic AST to represent Python2 and Python3's Abstract Syntax Tree(AST).
# It provides a compatibility layer between the AST of various Python versions,
# as produced by ast.parse from the standard ast module.
# See details in https://github.com/serge-sans-paille/gast/
from paddle.utils import gast
from .base_transformer import BaseTransformer
__all__ = ['IfElseTransformer']
TRUE_FUNC_PREFIX = 'true_fn'
......
......@@ -16,6 +16,7 @@ import os
import threading
from paddle.fluid import log_helper
from .utils import ast_to_source_code
__all__ = []
......
......@@ -13,10 +13,9 @@
# limitations under the License.
from paddle.utils import gast
from .base_transformer import BaseTransformer
from .utils import ast_to_source_code
from .base_transformer import (
BaseTransformer,
)
__all__ = []
......
......@@ -13,28 +13,28 @@
# limitations under the License.
import copy
from paddle.utils import gast
from collections import defaultdict
from paddle.fluid import unique_name
from paddle.utils import gast
from .base_transformer import (
BaseTransformer,
ForLoopTuplePreTransformer,
ForNodeVisitor,
)
from .ifelse_transformer import ARGS_NAME
from .static_analysis import AstNodeWrapper, NodeVarType, StaticAnalysisVisitor
from .utils import (
ast_to_source_code,
get_attribute_full_name,
create_nonlocal_stmt_nodes,
create_get_args_node,
create_set_args_node,
FunctionNameLivenessAnalysis,
GetterSetterHelper,
ast_to_source_code,
create_get_args_node,
create_name_str,
create_nonlocal_stmt_nodes,
create_set_args_node,
get_attribute_full_name,
)
from .ifelse_transformer import ARGS_NAME
from .base_transformer import (
BaseTransformer,
ForLoopTuplePreTransformer,
ForNodeVisitor,
)
__all__ = []
......
......@@ -13,16 +13,13 @@
# limitations under the License.
import inspect
from collections.abc import Sequence
from paddle.utils import gast
from paddle.fluid import core
from .utils import (
unwrap,
ORIGI_INFO,
)
from paddle.fluid.framework import Program
from paddle.utils import gast
from collections.abc import Sequence
from .utils import ORIGI_INFO, unwrap
__all__ = []
......
......@@ -15,34 +15,31 @@
import numpy as np
import paddle
from paddle.fluid import framework, backward, core, program_guard
from paddle.fluid.executor import (
_is_enable_standalone_executor,
_is_dy2st_enable_standalone_executor,
)
from paddle.fluid.dygraph import layers
from paddle.fluid.dygraph.base import switch_to_static_graph
from . import logging_utils
from .return_transformer import (
RETURN_NO_VALUE_MAGIC_NUM,
)
from paddle.fluid.layers.utils import flatten
from paddle.fluid.layers.utils import pack_sequence_as
from paddle.fluid.layers.utils import _hash_with_id
from paddle import _legacy_C_ops
from paddle.fluid import backward, core, framework, program_guard
from paddle.fluid.compiler import BuildStrategy
from paddle.fluid.framework import _apply_pass
from paddle.fluid.contrib.mixed_precision.decorator import (
AutoMixedPrecisionLists,
)
from paddle.fluid.contrib.mixed_precision.fp16_utils import (
rewrite_program,
cast_model_to_fp16,
rewrite_program,
)
from paddle.fluid.dygraph import layers
from paddle.fluid.dygraph.amp.auto_cast import (
_in_amp_guard,
_in_pure_fp16_guard,
)
from paddle import _legacy_C_ops
from paddle.fluid.dygraph.base import switch_to_static_graph
from paddle.fluid.executor import (
_is_dy2st_enable_standalone_executor,
_is_enable_standalone_executor,
)
from paddle.fluid.framework import _apply_pass
from paddle.fluid.layers.utils import _hash_with_id, flatten, pack_sequence_as
from . import logging_utils
from .return_transformer import RETURN_NO_VALUE_MAGIC_NUM
__all__ = []
......
......@@ -13,49 +13,42 @@
# limitations under the License.
import collections
from paddle.utils import gast
import inspect
import textwrap
import threading
import weakref
from paddle.fluid import framework
from paddle.fluid import _non_static_mode
from paddle.fluid.dygraph import layers
from paddle.fluid import _non_static_mode, framework
from paddle.fluid.data_feeder import check_type
from paddle.fluid.dygraph import layers
from paddle.fluid.dygraph.base import param_guard, switch_to_static_graph
from paddle.fluid.layers.utils import flatten
from paddle.fluid.dygraph.base import param_guard
from paddle.fluid.dygraph.base import switch_to_static_graph
from . import error
from . import logging_utils
from paddle.utils import gast
from . import error, logging_utils
from .ast_transformer import DygraphToStaticAst
from .function_spec import (
FunctionSpec,
_hash_spec_names,
get_buffers,
get_parameters,
)
from .origin_info import (
attach_origin_info,
create_and_update_origin_info_map,
update_op_callstack_with_origin_info,
)
from .partial_program import (
partial_program_from,
)
from .partial_program import partial_program_from
from .utils import (
ALREADY_D2S,
ast_to_func,
ast_to_source_code,
func_to_source_code,
input_specs_compatible,
make_hashable,
type_name,
unwrap,
make_hashable,
ALREADY_D2S,
)
from .function_spec import (
FunctionSpec,
_hash_spec_names,
get_buffers,
get_parameters,
)
from .ast_transformer import DygraphToStaticAst
__all__ = []
......
......@@ -12,18 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from paddle.fluid import unique_name
from paddle.utils import gast
from paddle.fluid import unique_name
from .base_transformer import BaseTransformer
from .break_continue_transformer import ForToWhileTransformer
from .utils import (
index_in_list,
ast_to_source_code,
Dygraph2StaticException,
ORIGI_INFO,
)
from .break_continue_transformer import ForToWhileTransformer
from .base_transformer import (
BaseTransformer,
Dygraph2StaticException,
ast_to_source_code,
index_in_list,
)
__all__ = []
......
......@@ -13,13 +13,14 @@
# limitations under the License.
from paddle.utils import gast
from .logging_utils import warn
from .utils import (
is_paddle_api,
ast_to_source_code,
index_in_list,
is_dygraph_api,
is_numpy_api,
index_in_list,
ast_to_source_code,
is_paddle_api,
)
__all__ = []
......
......@@ -14,13 +14,9 @@
from paddle.utils import gast
from .base_transformer import BaseTransformer
from .static_analysis import AstNodeWrapper
from .utils import ast_to_source_code
from .static_analysis import (
AstNodeWrapper,
)
from .base_transformer import (
BaseTransformer,
)
__all__ = []
......
......@@ -13,12 +13,9 @@
# limitations under the License.
from paddle.jit.dy2static.static_analysis import (
AstNodeWrapper,
)
from .base_transformer import (
BaseTransformer,
)
from paddle.jit.dy2static.static_analysis import AstNodeWrapper
from .base_transformer import BaseTransformer
__all__ = []
......
......@@ -13,29 +13,28 @@
# limitations under the License.
import ast
import astor
import atexit
import copy
from paddle.utils import gast
import inspect
import importlib.util
import inspect
import os
import sys
import shutil
import sys
import tempfile
import textwrap
import warnings
from functools import reduce
from importlib.machinery import SourceFileLoader
import astor
import numpy as np
import paddle
from paddle.fluid import unique_name
from paddle.fluid import core, unique_name
from paddle.fluid.data_feeder import convert_dtype
from paddle.fluid import core
from paddle.fluid.layer_helper import LayerHelper
from paddle.fluid.layers import assign
from functools import reduce
from importlib.machinery import SourceFileLoader
import warnings
from paddle.utils import gast
__all__ = []
......@@ -263,8 +262,8 @@ def is_api_in_module(node, module_prefix):
import paddle.fluid.dygraph as dygraph # noqa: F401
import paddle.fluid.layers as layers # noqa: F401
import paddle.jit.dy2static as _jst # noqa: F401
from paddle.fluid.dygraph import to_variable # noqa: F401
from paddle import to_tensor # noqa: F401
from paddle.fluid.dygraph import to_variable # noqa: F401
return eval(
"_is_api_in_module_helper({}, '{}')".format(func_str, module_prefix)
......@@ -891,9 +890,7 @@ class IsControlFlowVisitor(gast.NodeVisitor):
return node
def _is_node_with_tensor(self, node, name_id):
from paddle.jit.dy2static.static_analysis import (
NodeVarType,
)
from paddle.jit.dy2static.static_analysis import NodeVarType
# Look up the node_var_type_map by name_id.
if self.node_var_type_map:
......@@ -1209,14 +1206,14 @@ class FunctionNameLivenessAnalysis(gast.NodeVisitor):
"""NOTE: why we need merge w_vars and push_pop_vars here ?
because we do ifelse_transformer after loop_transformer. Loops will changed into functioons. but we know this function will be called in if. so we add w_vars to father function scope.
"""
from paddle.jit.dy2static.loop_transformer import (
WHILE_BODY_PREFIX,
FOR_CONDITION_PREFIX,
FOR_BODY_PREFIX,
)
from paddle.jit.dy2static.ifelse_transformer import (
TRUE_FUNC_PREFIX,
FALSE_FUNC_PREFIX,
TRUE_FUNC_PREFIX,
)
from paddle.jit.dy2static.loop_transformer import (
FOR_BODY_PREFIX,
FOR_CONDITION_PREFIX,
WHILE_BODY_PREFIX,
)
control_flow_function_def = [
......
......@@ -13,13 +13,11 @@
# limitations under the License.
import paddle
from paddle.utils import gast
from paddle.fluid.framework import Variable
from .utils import (
UndefinedVar,
create_undefined_variable,
)
from paddle.fluid.layers.utils import map_structure, is_sequence
from paddle.fluid.layers.utils import is_sequence, map_structure
from paddle.utils import gast
from .utils import UndefinedVar, create_undefined_variable
__all__ = []
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册