未验证 提交 e1245f5c 编写于 作者: H Huihuang Zheng 提交者: GitHub

[Dy2stat] change deprecated imp dependency to importlib, test=develop (#26453)

As the title
上级 379222c3
......@@ -19,7 +19,6 @@ import astor
import atexit
import copy
import gast
import imp
import inspect
import os
import six
......@@ -28,6 +27,12 @@ import textwrap
from paddle.fluid import unique_name
# imp is deprecated in python3
if six.PY2:
import imp
else:
from importlib.machinery import SourceFileLoader
dygraph_class_to_static_api = {
"CosineDecay": "cosine_decay",
"ExponentialDecay": "exponential_decay",
......@@ -391,7 +396,10 @@ def ast_to_func(ast_root, dyfunc, delete_on_exit=True):
atexit.register(lambda: remove_if_exit(f.name))
atexit.register(lambda: remove_if_exit(f.name[:-3] + ".pyc"))
if six.PY2:
module = imp.load_source(module_name, f.name)
else:
module = SourceFileLoader(module_name, f.name).load_module()
func_name = dyfunc.__name__
if not hasattr(module, func_name):
raise ValueError(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册