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

【Hackathon No.89】 Remove circle import Part7 #51129

Closed
wants to merge 10 commits into from
4 changes: 1 addition & 3 deletions python/paddle/jit/dy2static/ifelse_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@
# 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.utils import FALSE_FUNC_PREFIX, TRUE_FUNC_PREFIX, gast

from .base_transformer import BaseTransformer

__all__ = []

TRUE_FUNC_PREFIX = 'true_fn'
FALSE_FUNC_PREFIX = 'false_fn'
GET_ARGS_FUNC_PREFIX = 'get_args'
SET_ARGS_FUNC_PREFIX = 'set_args'
ARGS_NAME = '__args'
Expand Down
11 changes: 6 additions & 5 deletions python/paddle/jit/dy2static/loop_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
from collections import defaultdict

from paddle.fluid import unique_name
from paddle.utils import gast
from paddle.utils import (
FOR_BODY_PREFIX,
FOR_CONDITION_PREFIX,
WHILE_BODY_PREFIX,
gast,
)

from .base_transformer import (
BaseTransformer,
Expand All @@ -39,10 +44,6 @@
__all__ = []

WHILE_CONDITION_PREFIX = 'while_condition'
WHILE_BODY_PREFIX = 'while_body'

FOR_CONDITION_PREFIX = 'for_loop_condition'
FOR_BODY_PREFIX = 'for_loop_body'


def create_while_nodes(
Expand Down
3 changes: 1 addition & 2 deletions python/paddle/jit/dy2static/partial_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
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
from .utils import _out_grad_names, _param_grad_names
from .utils import RETURN_NO_VALUE_MAGIC_NUM, _out_grad_names, _param_grad_names

__all__ = []

Expand Down
1 change: 0 additions & 1 deletion python/paddle/jit/dy2static/return_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
# should return.

# Assign not support float64, use float32 value as magic number.
RETURN_NO_VALUE_MAGIC_NUM = 1.77113e27
RETURN_NO_VALUE_VAR_NAME = "__no_value_return_var"


Expand Down
29 changes: 9 additions & 20 deletions python/paddle/jit/dy2static/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ def visit(self, node):
RE_PYNAME = '[a-zA-Z0-9_]+'
RE_PYMODULE = r'[a-zA-Z0-9_]+\.'

RETURN_NO_VALUE_MAGIC_NUM = 1.77113e27

TRUE_FUNC_PREFIX = 'true_fn'
FALSE_FUNC_PREFIX = 'false_fn'

WHILE_BODY_PREFIX = 'while_body'
FOR_CONDITION_PREFIX = 'for_loop_condition'
FOR_BODY_PREFIX = 'for_loop_body'


def data_layer_not_check(name, shape, dtype='float32', lod_level=0):
"""
Expand Down Expand Up @@ -143,10 +152,6 @@ def data_layer_not_check(name, shape, dtype='float32', lod_level=0):


def create_undefined_variable():
from paddle.jit.dy2static.return_transformer import (
RETURN_NO_VALUE_MAGIC_NUM,
)

var = data_layer_not_check(
unique_name.generate("undefined_var"), [1], "float64"
)
Expand Down Expand Up @@ -256,7 +261,6 @@ def is_api_in_module(node, module_prefix):

func_str = astor.to_source(gast.gast_to_ast(func_node)).strip()
try:
import paddle # noqa: F401
import paddle.fluid as fluid # noqa: F401
import paddle.fluid.dygraph as dygraph # noqa: F401
import paddle.fluid.layers as layers # noqa: F401
Expand Down Expand Up @@ -296,8 +300,6 @@ def is_numpy_api(node):
assert isinstance(node, gast.Call), "Input non-Call node for is_numpy_api"
func_str = astor.to_source(gast.gast_to_ast(node.func))
try:
import numpy as np # noqa: F401

module_result = eval(
"_is_api_in_module_helper({}, '{}')".format(func_str, "numpy")
)
Expand Down Expand Up @@ -1204,19 +1206,6 @@ def pre_func():
)

def post_func():
"""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.ifelse_transformer import (
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 = [
WHILE_BODY_PREFIX,
WHILE_BODY_PREFIX,
Expand Down