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

[Dy2St] Shrink the eval scope #61149

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/paddle/jit/dy2static/convert_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ def convert_var_dtype(var, dtype):
}
return paddle.cast(var, dtype=cast_map[dtype])
else:
return eval(f'{dtype}(var)')
return eval(dtype)(var)


def convert_assert(cond, message=""):
Expand Down
7 changes: 3 additions & 4 deletions python/paddle/jit/dy2static/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .origin_info import Location, OriginInfo, global_origin_info_map
from .utils import (
RE_PYMODULE,
_is_api_in_module_helper, # noqa: F401
_is_api_in_module_helper,
)

__all__ = []
Expand Down Expand Up @@ -214,9 +214,8 @@ def numpy_api_check(self, format_exception, error_line):
func_str = searched_name.group(0)
break
try:
module_result = eval(
"_is_api_in_module_helper({}, '{}')".format(func_str, "numpy")
)
fn = eval(func_str)
module_result = _is_api_in_module_helper(fn, "numpy")
is_numpy_api_err = module_result or (
func_str.startswith("numpy.") or func_str.startswith("np.")
)
Expand Down
7 changes: 4 additions & 3 deletions python/paddle/jit/dy2static/transformers/call_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from paddle.jit.dy2static.utils import ast_to_source_code, is_paddle_api
from paddle.utils import gast

from ..utils import is_builtin # noqa: F401
from ..utils import is_builtin
from .base import BaseTransformer

PDB_SET = "pdb.set_trace"
Expand Down Expand Up @@ -51,9 +51,10 @@ def _no_need_convert_call(self, node):
'enumerate',
'print',
}
is_builtin = eval(f"is_builtin({func_str})") # noqa: F811
fn = eval(func_str)
is_builtin_fn = is_builtin(fn)
need_convert = func_str in need_convert_builtin_func_list
return is_builtin and not need_convert
return is_builtin_fn and not need_convert
except Exception:
return False

Expand Down
3 changes: 2 additions & 1 deletion python/paddle/jit/dy2static/utils_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def is_api_in_module(node, module_prefix):
import paddle.jit.dy2static as _jst # noqa: F401
from paddle import to_tensor # noqa: F401

return eval(f"_is_api_in_module_helper({func_str}, '{module_prefix}')")
fn = eval(func_str)
return _is_api_in_module_helper(fn, module_prefix)
except Exception:
return False

Expand Down