diff --git a/.gitignore b/.gitignore index 14109003e478ab1d2bc4371519d90a43aa9f5f33..f1d02f4dd25c6958e43db3a5fe0b0f0193aae097 100644 --- a/.gitignore +++ b/.gitignore @@ -75,6 +75,7 @@ paddle/fluid/operators/generated_op.cc paddle/fluid/operators/generated_sparse_op.cc paddle/phi/ops/compat/generated_sig.cc paddle/phi/ops/compat/generated_sparse_sig.cc +paddle/phi/api/yaml/parsed_apis/ paddle/fluid/operators/generator/parsed_ops/ paddle/fluid/pybind/tmp_eager_op_function_impl.h paddle/fluid/pybind/eager_op_function_impl.h diff --git a/python/paddle/distributed/auto_parallel/helper.py b/python/paddle/distributed/auto_parallel/helper.py index 31deaea4275eb969a5e9bed344663cd78b054236..9cc2a57e56a504cc66d9d7b5c7691b93a794a036 100644 --- a/python/paddle/distributed/auto_parallel/helper.py +++ b/python/paddle/distributed/auto_parallel/helper.py @@ -20,7 +20,7 @@ from paddle.jit import to_static, not_to_static from paddle.fluid.framework import Parameter from paddle.fluid.framework import program_guard from paddle.fluid.executor import global_scope -from paddle.fluid.dygraph.dygraph_to_static.program_translator import ( +from paddle.jit.dy2static.program_translator import ( StaticFunction, ) diff --git a/python/paddle/fluid/compiler.py b/python/paddle/fluid/compiler.py index 47110b1e0bf7e58d503011be28e6cbcc9ae3a673..4dc495edc1a4fc2f213059c9b0e9e6ef2f2af597 100644 --- a/python/paddle/fluid/compiler.py +++ b/python/paddle/fluid/compiler.py @@ -691,16 +691,12 @@ class IpuDynamicPatcher: Returns: None """ - from ..fluid.dygraph.dygraph_to_static.program_translator import ( - ProgramCache, - ) - from ..fluid.dygraph.dygraph_to_static.program_translator import ( + from paddle.jit.dy2static.program_translator import ( CacheKey, - ) - from ..fluid.dygraph.dygraph_to_static import logging_utils - from ..fluid.dygraph.dygraph_to_static.program_translator import ( + ProgramCache, MAX_TRACED_PROGRAM_COUNT, ) + from ..fluid.dygraph.dygraph_to_static import logging_utils from ..fluid.dygraph.dygraph_to_static.partial_program import ( partial_program_from, ) diff --git a/python/paddle/fluid/dygraph/__init__.py b/python/paddle/fluid/dygraph/__init__.py index 875b7e28107d446d7771bc2c53e65c578034c45e..76c75b974e3a42ec2845c6216047e8868d2c1ded 100644 --- a/python/paddle/fluid/dygraph/__init__.py +++ b/python/paddle/fluid/dygraph/__init__.py @@ -36,8 +36,6 @@ from .checkpoint import * from . import learning_rate_scheduler from .learning_rate_scheduler import * -from . import jit -from .jit import * from . import io from .io import * @@ -46,7 +44,6 @@ from . import static_runner from .static_runner import StaticModelRunner from . import dygraph_to_static -from .dygraph_to_static import ProgramTranslator from . import rnn from .rnn import * @@ -66,8 +63,6 @@ __all__ += nn.__all__ __all__ += parallel.__all__ __all__ += checkpoint.__all__ __all__ += learning_rate_scheduler.__all__ -__all__ += jit.__all__ __all__ += io.__all__ __all__ += rnn.__all__ -__all__ += ['ProgramTranslator'] __all__ += amp.__all__ diff --git a/python/paddle/fluid/dygraph/checkpoint.py b/python/paddle/fluid/dygraph/checkpoint.py index f7a1db032f48b8dda7b545be8a3ce1f2282c15ce..9515a8bd1704e5968d376f40caf985c2d068c40e 100644 --- a/python/paddle/fluid/dygraph/checkpoint.py +++ b/python/paddle/fluid/dygraph/checkpoint.py @@ -31,7 +31,7 @@ from . import learning_rate_scheduler import warnings from .. import core from .base import guard -from paddle.fluid.dygraph.jit import _SaveLoadConfig +from paddle.jit.api import _SaveLoadConfig from paddle.fluid.dygraph.io import ( _construct_program_holders, _construct_params_and_buffers, diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/__init__.py b/python/paddle/fluid/dygraph/dygraph_to_static/__init__.py index c37fe364a5bf8205654aa27381d50bb1dcbe0d77..ad3fc3d18411b7b565a4aa76fb1c2cea0d3016bf 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/__init__.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/__init__.py @@ -12,9 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from . import ast_transformer -from .ast_transformer import * - from . import static_analysis from .static_analysis import * @@ -24,9 +21,6 @@ from .loop_transformer import * from . import variable_trans_func from .variable_trans_func import * -from . import program_translator -from .program_translator import * - from . import convert_call_func from .convert_call_func import * @@ -36,10 +30,8 @@ from . import logging_utils from .logging_utils import * __all__ = [] -__all__ += ast_transformer.__all__ __all__ += loop_transformer.__all__ __all__ += static_analysis.__all__ __all__ += variable_trans_func.__all__ -__all__ += program_translator.__all__ __all__ += convert_call_func.__all__ __all__ += logging_utils.__all__ 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 72b6cc98839d69c83e04af3c11852b826b84ae6f..86496d72f26339d2c3136e6553952f3fe7d3c4f1 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 @@ -36,15 +36,7 @@ from paddle.fluid.dygraph.dygraph_to_static.convert_operators import ( from paddle.fluid.dygraph.dygraph_to_static.logging_utils import ( TranslatorLogger, ) -from paddle.fluid.dygraph.dygraph_to_static.program_translator import ( - StaticFunction, -) -from paddle.fluid.dygraph.dygraph_to_static.program_translator import ( - convert_to_static, -) -from paddle.fluid.dygraph.dygraph_to_static.program_translator import ( - unwrap_decorators, -) + from paddle.fluid.dygraph.dygraph_to_static.utils import is_paddle_func, unwrap from paddle.fluid.dygraph.layers import Layer @@ -185,6 +177,13 @@ def convert_call(func): # [1. 1. 1.]] """ + # NOTE(Aurelius84): Fix it after all files migrating into jit. + from paddle.jit.dy2static.program_translator import ( + convert_to_static, + unwrap_decorators, + StaticFunction, + ) + translator_logger.log( 1, "Convert callable object: convert {}.".format(func) ) diff --git a/python/paddle/fluid/dygraph/static_runner.py b/python/paddle/fluid/dygraph/static_runner.py index c0a61fb3c2419e3ad10cf1a738bb081d21ff7c13..27cd5fd6dcc21ddeb7a2774a1542a9e129d1b4ea 100644 --- a/python/paddle/fluid/dygraph/static_runner.py +++ b/python/paddle/fluid/dygraph/static_runner.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from paddle.fluid.dygraph.jit import _SaveLoadConfig +from paddle.jit.api import _SaveLoadConfig from paddle.fluid.dygraph.io import TranslatedLayer diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/bert_dygraph_model.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/bert_dygraph_model.py index f35e7a973d3fa3aa48f93c7531cca331a4b7912c..0fbe99cce9e3297cdcbed856bd8dec037ddb79eb 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/bert_dygraph_model.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/bert_dygraph_model.py @@ -15,7 +15,7 @@ import paddle import paddle.fluid as fluid from paddle.fluid.dygraph import Embedding, Layer, Linear -from paddle.fluid.dygraph.jit import declarative +from paddle.jit.api import declarative from transformer_dygraph_model import MultiHeadAttention, PrePostProcessLayer diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/seq2seq_dygraph_model.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/seq2seq_dygraph_model.py index 78f50cd9d9a37224b762f5097b155d725608cb2e..44b977037d73c7c4f1e38e5650772125cca07a35 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/seq2seq_dygraph_model.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/seq2seq_dygraph_model.py @@ -20,7 +20,7 @@ from paddle.fluid import ParamAttr from paddle.fluid import layers from paddle.fluid.dygraph import Layer from paddle.fluid.dygraph.base import to_variable -from paddle.fluid.dygraph.jit import declarative +from paddle.jit.api import declarative from paddle.fluid.dygraph.nn import Embedding from seq2seq_utils import Seq2SeqModelHyperParams as args diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/simnet_dygraph_model.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/simnet_dygraph_model.py index 17a6572ad03c34e9a7fd7a8840badeb84a006a83..63d1229da705a1d79d38afc5ac87fbd97294c0e6 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/simnet_dygraph_model.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/simnet_dygraph_model.py @@ -17,7 +17,7 @@ import paddle.fluid as fluid import paddle.fluid.param_attr as attr from functools import reduce -from paddle.fluid.dygraph import declarative +from paddle.jit.api import declarative from paddle.fluid.dygraph import Embedding, Layer, Linear from paddle.static import Variable diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_assert.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_assert.py index c975a50bffd654146a8f900660fa24425311f501..c9399236b72b78666e5e7df1d78300f8a6ea0f6f 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_assert.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_assert.py @@ -17,8 +17,8 @@ import unittest import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph.dygraph_to_static import ProgramTranslator -from paddle.fluid.dygraph.jit import declarative +from paddle.jit import ProgramTranslator +from paddle.jit.api import declarative @paddle.jit.to_static diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_basic_api_transformation.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_basic_api_transformation.py index 5d01a687661fd67eb8a6e8ff6cca6f5613e1a2c5..2d0dd5ff5666a8f1065ce39a71df27c6527ff34c 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_basic_api_transformation.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_basic_api_transformation.py @@ -23,7 +23,7 @@ import paddle.fluid.dygraph as dygraph from paddle import to_tensor from paddle.fluid.dygraph import to_variable -from paddle.fluid.dygraph.jit import dygraph_to_static_func +from paddle.jit.api import dygraph_to_static_func from paddle.fluid.dygraph.dygraph_to_static.utils import is_dygraph_api SEED = 2020 diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_bert.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_bert.py index 7fb9eca260636d31728942d0c122be1f2706e4b3..3ce9b78e083ab54b398d6e58e8c581bd78881a3a 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_bert.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_bert.py @@ -20,7 +20,7 @@ import numpy as np import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph.dygraph_to_static import ProgramTranslator +from paddle.jit import ProgramTranslator from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX from bert_dygraph_model import PretrainModelLayer @@ -118,7 +118,7 @@ class TestBert(unittest.TestCase): step_idx += 1 if step_idx == STEP_NUM: if to_static: - fluid.dygraph.jit.save(bert, self.model_save_prefix) + paddle.jit.save(bert, self.model_save_prefix) else: fluid.dygraph.save_dygraph( bert.state_dict(), self.dy_state_dict_save_path @@ -194,7 +194,7 @@ class TestBert(unittest.TestCase): def predict_dygraph_jit(self, data): with fluid.dygraph.guard(place): - bert = fluid.dygraph.jit.load(self.model_save_prefix) + bert = paddle.jit.load(self.model_save_prefix) bert.eval() ( diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_bmn.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_bmn.py index f5343386fdbcc89d5efdf2050d77e2a4da6310fa..e2ee44a71219c2cd8e1b9194f1b99d50687aaf5b 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_bmn.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_bmn.py @@ -22,7 +22,7 @@ from paddle.jit import to_static import paddle.fluid as fluid from paddle.fluid import ParamAttr from paddle.fluid.dygraph import to_variable -from paddle.fluid.dygraph import ProgramTranslator +from paddle.jit import ProgramTranslator from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX from predictor_utils import PredictorTools @@ -751,7 +751,7 @@ class TestTrain(unittest.TestCase): if batch_id == args.train_batch_num: if to_static: - fluid.dygraph.jit.save(bmn, self.model_save_prefix) + paddle.jit.save(bmn, self.model_save_prefix) else: fluid.dygraph.save_dygraph( bmn.state_dict(), self.dy_param_path @@ -865,7 +865,7 @@ class TestTrain(unittest.TestCase): def predict_dygraph_jit(self, data): with fluid.dygraph.guard(self.place): - bmn = fluid.dygraph.jit.load(self.model_save_prefix) + bmn = paddle.jit.load(self.model_save_prefix) bmn.eval() x = to_variable(data) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_break_continue.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_break_continue.py index 143b14f7ed641693d2dd1c53bb9c8de224b8e4e7..5c826def66355f9d135e654f870265fd5d15f5d5 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_break_continue.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_break_continue.py @@ -16,8 +16,8 @@ import unittest import numpy as np import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph.jit import declarative -from paddle.fluid.dygraph.dygraph_to_static.program_translator import ( +from paddle.jit.api import declarative +from paddle.jit.dy2static.program_translator import ( ProgramTranslator, ) from paddle.fluid.dygraph.dygraph_to_static.utils import Dygraph2StaticException diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_cache_program.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_cache_program.py index 7df7c6333123581c40c7a05bfc9d65f3341caaac..45383c739232eee14ccf1d36a269e6271da61190 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_cache_program.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_cache_program.py @@ -18,9 +18,9 @@ from collections import Counter import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph.jit import declarative -from paddle.fluid.dygraph.dygraph_to_static import ProgramTranslator -from paddle.fluid.dygraph.dygraph_to_static import convert_to_static +from paddle.jit.api import declarative +from paddle.jit import ProgramTranslator +from paddle.jit.dy2static import convert_to_static from test_fetch_feed import Pool2D, Linear diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_cast.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_cast.py index 17f598f0f17e833e6d50ed6a0eb4e75885a156b6..43df75ae152156791e5bc0a66bdb7cebe8eb6182 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_cast.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_cast.py @@ -15,7 +15,7 @@ import unittest import numpy as np import paddle.fluid as fluid -from paddle.fluid.dygraph import declarative +from paddle.jit.api import declarative SEED = 2020 np.random.seed(SEED) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_convert_call.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_convert_call.py index 351b38edb422e32dde93bad5c768b62e2d24bb3c..2a7d15e8c296e6f572699b7aa956b59f7f6458e9 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_convert_call.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_convert_call.py @@ -19,7 +19,7 @@ import numpy as np import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph import ProgramTranslator +from paddle.jit import ProgramTranslator from paddle.fluid.dygraph.dygraph_to_static.convert_call_func import ( CONVERSION_OPTIONS, ) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_cycle_gan.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_cycle_gan.py index 6f4ea90030d5496653938ff311f8b5650c731b21..92009c09bfbac2af1282e09276881a2e67cdb813 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_cycle_gan.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_cycle_gan.py @@ -36,7 +36,9 @@ os.environ["CUDA_VISIBLE_DEVICES"] = "1" import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph import to_variable, declarative, ProgramTranslator +from paddle.fluid.dygraph import to_variable +from paddle.jit.api import declarative +from paddle.jit import ProgramTranslator from paddle.fluid.dygraph.nn import Conv2DTranspose, BatchNorm # Note: Set True to eliminate randomness. diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_declarative.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_declarative.py index c61fdbc0ecf537118e782331e0529451dd01669a..02c9ab3695803b05c0fd4670996505cf97542ec8 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_declarative.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_declarative.py @@ -21,12 +21,11 @@ import paddle.fluid as fluid from paddle.static import InputSpec from paddle.fluid.dygraph import ( to_variable, - declarative, - ProgramTranslator, Layer, - jit, ) -from paddle.fluid.dygraph.dygraph_to_static.program_translator import ( +from paddle.jit.api import declarative +from paddle.jit import ProgramTranslator +from paddle.jit.dy2static.program_translator import ( ConcreteProgram, StaticFunction, ) @@ -131,8 +130,8 @@ class TestInputSpec(unittest.TestCase): # 2. test save load net.inner_function(x) - jit.save(net, self.model_path) - infer_net = fluid.dygraph.jit.load(self.model_path) + paddle.jit.save(net, self.model_path) + infer_net = paddle.jit.load(self.model_path) pred = infer_net(x) np.testing.assert_allclose(out.numpy(), pred.numpy(), rtol=1e-05) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_deepcopy.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_deepcopy.py index a4823be643029df4f33c6215d397ee631520a0e7..7a8593066654fa29e1b75d8b017f26cc95f7416e 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_deepcopy.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_deepcopy.py @@ -15,7 +15,7 @@ import unittest import paddle import numpy as np -from paddle.fluid.dygraph.dygraph_to_static.program_translator import ( +from paddle.jit.dy2static.program_translator import ( StaticFunction, ) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_dict.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_dict.py index c9d87a6bbb432919760c36161c5a72fe064fff92..40f0c5085a0456d21db0335a5f910d74ef3c533f 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_dict.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_dict.py @@ -18,7 +18,7 @@ import unittest import paddle import paddle.fluid as fluid from paddle.jit import to_static -from paddle.fluid.dygraph.dygraph_to_static.program_translator import ( +from paddle.jit.dy2static.program_translator import ( ProgramTranslator, ) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_fetch_feed.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_fetch_feed.py index ffd950c21aa13aa63899eafaddc17e12ffb02d59..d58d24ea073cb5d501dd241363fae36954171808 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_fetch_feed.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_fetch_feed.py @@ -16,8 +16,8 @@ import numpy as np import unittest import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph.jit import declarative -from paddle.fluid.dygraph.dygraph_to_static import ProgramTranslator +from paddle.jit.api import declarative +from paddle.jit import ProgramTranslator SEED = 2020 diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_for_enumerate.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_for_enumerate.py index 6617227bd7386fc4109b50909c97729b0eb3e4b2..1003d1f025a957ec679c55b7c266d2046d1958d1 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_for_enumerate.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_for_enumerate.py @@ -19,7 +19,7 @@ import tempfile import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph.dygraph_to_static import ProgramTranslator +from paddle.jit import ProgramTranslator from paddle.static import InputSpec program_translator = ProgramTranslator() diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_full_name_usage.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_full_name_usage.py index f16d2410cbecc147c722b93f5138333c37366267..01b2a38c36ad48c45acdcd04655f22ed117679ed 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_full_name_usage.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_full_name_usage.py @@ -16,10 +16,10 @@ import numpy as np import paddle import paddle.fluid as fluid import unittest -from paddle.fluid.dygraph import declarative +from paddle.jit import to_static -@fluid.dygraph.declarative +@paddle.jit.to_static def dygraph_decorated_func(x): x = fluid.dygraph.to_variable(x) if paddle.mean(x) > 0: @@ -29,7 +29,7 @@ def dygraph_decorated_func(x): return x_v -@fluid.dygraph.declarative +@paddle.jit.to_static def jit_decorated_func(x): x = fluid.dygraph.to_variable(x) if paddle.mean(x) > 0: @@ -39,19 +39,19 @@ def jit_decorated_func(x): return x_v -@fluid.dygraph.declarative +@paddle.jit.to_static def decorated_call_decorated(x): return jit_decorated_func(x) class DoubleDecorated: @classmethod - @declarative + @to_static def double_decorated_func1(self, x): return dygraph_decorated_func(x) @classmethod - @fluid.dygraph.declarative + @paddle.jit.to_static def double_decorated_func2(self, x): return jit_decorated_func(x) @@ -78,13 +78,9 @@ class TestFullNameDecorator(unittest.TestCase): class TestImportProgramTranslator(unittest.TestCase): def test_diff_pkg_same_cls(self): - dygraph_prog_trans = fluid.dygraph.ProgramTranslator() - dy_to_stat_prog_trans = ( - fluid.dygraph.dygraph_to_static.ProgramTranslator() - ) - full_pkg_prog_trans = ( - fluid.dygraph.dygraph_to_static.program_translator.ProgramTranslator() - ) + dygraph_prog_trans = paddle.jit.ProgramTranslator() + dy_to_stat_prog_trans = paddle.jit.ProgramTranslator() + full_pkg_prog_trans = paddle.jit.ProgramTranslator() self.assertEqual(dygraph_prog_trans, dy_to_stat_prog_trans) self.assertEqual(dygraph_prog_trans, full_pkg_prog_trans) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ifelse.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ifelse.py index bc57b56d2b39e62ff58c0eccd2b539d84ca29a66..78273da028a2a074f6e8cdb639eadbfc69fbbe7e 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ifelse.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ifelse.py @@ -16,8 +16,8 @@ import numpy as np import unittest import paddle -from paddle.fluid.dygraph.jit import declarative -from paddle.fluid.dygraph.dygraph_to_static.program_translator import ( +from paddle.jit.api import declarative +from paddle.jit.dy2static.program_translator import ( ProgramTranslator, ) from paddle.fluid.dygraph.dygraph_to_static.utils import Dygraph2StaticException diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_lac.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_lac.py index c195081f5a0fdab6e2a5f74673be38dee8ea5cfe..91926f259a7f6011f8a139dc8c07e8b69e95b478 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_lac.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_lac.py @@ -26,7 +26,8 @@ import paddle import paddle.fluid as fluid from paddle.fluid.dygraph import to_variable from paddle.fluid.dygraph import Embedding, Linear, GRUUnit -from paddle.fluid.dygraph import declarative, ProgramTranslator +from paddle.jit.api import declarative +from paddle.jit import ProgramTranslator from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX from paddle.fluid.framework import _non_static_mode from paddle import _legacy_C_ops @@ -621,7 +622,7 @@ class TestLACModel(unittest.TestCase): step += 1 # save inference model if to_static: - fluid.dygraph.jit.save( + paddle.jit.save( layer=model, path=self.model_save_prefix, input_spec=[input_specs[0], input_specs[-1]], @@ -706,7 +707,7 @@ class TestLACModel(unittest.TestCase): def predict_dygraph_jit(self, batch): words, targets, length = batch with fluid.dygraph.guard(self.place): - model = fluid.dygraph.jit.load(self.model_save_prefix) + model = paddle.jit.load(self.model_save_prefix) model.eval() pred_res = model(to_variable(words), to_variable(length)) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_lambda.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_lambda.py index d0b45a050bc164b96ed3ef426624d0c80e27bae3..078322d15bd3180f8b3b1106a2714441c1e8e1f4 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_lambda.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_lambda.py @@ -17,7 +17,7 @@ import unittest import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph import declarative +from paddle.jit.api import declarative def call_lambda_as_func(x): diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_len.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_len.py index 01e5f1e1074cc828a0755bb282d8f95156f42954..1d0ccada5128e429e6f7ab23040347602794bdab 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_len.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_len.py @@ -17,7 +17,7 @@ import unittest import numpy as np import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph import declarative +from paddle.jit.api import declarative from paddle.fluid.dygraph.dygraph_to_static import convert_call SEED = 2020 diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_list.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_list.py index f2914614e603e17e7428f9c50a134a46fad1b886..f5aa8ffffbadb1d5c1b08e3d3da5cb237d99deb5 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_list.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_list.py @@ -18,7 +18,7 @@ import unittest import paddle import numpy as np import paddle.fluid as fluid -from paddle.fluid.dygraph.jit import declarative +from paddle.jit.api import declarative from paddle.fluid.layers.utils import map_structure SEED = 2020 diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_logical.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_logical.py index 4ab65c47660706cdea4a53fb9b58cd245aeedfab..847635bbc632bd04d907dfca089842cbefc9b8f4 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_logical.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_logical.py @@ -22,7 +22,7 @@ import numpy as np import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph import ProgramTranslator +from paddle.jit import ProgramTranslator from paddle.fluid.dygraph.dygraph_to_static.logical_transformer import ( cmpop_node_to_str, ) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_loop.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_loop.py index 75c59897d8825de30d8ef31857173b9742294225..771d9ce59ad5aefee90bb4f2c4eabe853995f81b 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_loop.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_loop.py @@ -20,7 +20,7 @@ import paddle.fluid as fluid import unittest from paddle.fluid.dygraph.dygraph_to_static.loop_transformer import NameVisitor -from paddle.fluid.dygraph.jit import declarative +from paddle.jit.api import declarative SEED = 2020 np.random.seed(SEED) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist.py index cfe085426932c2eb47bd48fd49caa88c2624c293..f8fcbff1f4519ed959cd0f1017a6675305299b31 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist.py @@ -269,7 +269,7 @@ class TestMNISTWithToStatic(TestMNIST): model_save_prefix = os.path.join(model_save_dir, 'mnist') model_filename = "mnist" + INFER_MODEL_SUFFIX params_filename = "mnist" + INFER_PARAMS_SUFFIX - fluid.dygraph.jit.save( + paddle.jit.save( layer=model, path=model_save_prefix, input_spec=input_spec, @@ -325,7 +325,7 @@ class TestMNISTWithToStatic(TestMNIST): return np.array(results[0]) def jit_load_and_run_inference_dygraph(self, model_path, inputs): - infer_net = fluid.dygraph.jit.load(model_path) + infer_net = paddle.jit.load(model_path) pred = infer_net(inputs[0]) return pred.numpy() diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mobile_net.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mobile_net.py index a3b55386b438b7c3789a7fa8d618f28300a28739..18308dbd85b41feeee3953b77a68202bfd5147f8 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mobile_net.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mobile_net.py @@ -21,7 +21,8 @@ import paddle.fluid as fluid from paddle.fluid.initializer import MSRA from paddle.fluid.param_attr import ParamAttr from paddle.fluid.dygraph.nn import Pool2D, BatchNorm, Linear -from paddle.fluid.dygraph import declarative, ProgramTranslator +from paddle.jit.api import declarative +from paddle.jit import ProgramTranslator from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX import unittest @@ -565,7 +566,7 @@ def train_mobilenet(args, to_static): t_last = time.time() if batch_id > args.train_step: if to_static: - fluid.dygraph.jit.save(net, args.model_save_prefix) + paddle.jit.save(net, args.model_save_prefix) else: fluid.dygraph.save_dygraph( net.state_dict(), args.dy_state_dict_save_path @@ -618,7 +619,7 @@ def predict_dygraph(args, data): def predict_dygraph_jit(args, data): with fluid.dygraph.guard(args.place): - model = fluid.dygraph.jit.load(args.model_save_prefix) + model = paddle.jit.load(args.model_save_prefix) model.eval() pred_res = model(data) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_origin_info.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_origin_info.py index 663c08ea28e3164ba8f7739177214809490aed67..eedbed04f0b53eb8a92025a530443828ca04ffac 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_origin_info.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_origin_info.py @@ -15,7 +15,7 @@ import sys import unittest -from paddle.fluid.dygraph.dygraph_to_static.ast_transformer import ( +from paddle.jit.dy2static import ( DygraphToStaticAst, ) from paddle.fluid.dygraph.dygraph_to_static.origin_info import ( @@ -29,7 +29,7 @@ from paddle.fluid.dygraph.dygraph_to_static.origin_info import ( unwrap, ) from paddle.fluid.dygraph.dygraph_to_static.utils import ast_to_func -from paddle.fluid.dygraph.jit import declarative +from paddle.jit.api import declarative def simple_func(x): diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_partial_program.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_partial_program.py index 692bae0218f03e582a6f07e13b2c1d8bdd31aa47..2b69ebacd6f9f560fb1a3dab0cc25e089d6b93d7 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_partial_program.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_partial_program.py @@ -16,7 +16,8 @@ import numpy as np import paddle import paddle.fluid as fluid from paddle.fluid.layers.utils import flatten -from paddle.fluid.dygraph import declarative, ProgramTranslator +from paddle.jit.api import declarative +from paddle.jit import ProgramTranslator from test_fetch_feed import Linear diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_print.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_print.py index 3603cac199ed5b0cdf9cfd90f0f0e8c5b18f3ccc..c6d290c6d0f6cc1951f32543e40c94e0de193100 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_print.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_print.py @@ -16,8 +16,8 @@ import numpy import unittest import paddle.fluid as fluid -from paddle.fluid.dygraph.dygraph_to_static import ProgramTranslator -from paddle.fluid.dygraph.jit import declarative +from paddle.jit import ProgramTranslator +from paddle.jit.api import declarative program_translator = ProgramTranslator() diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_program_translator.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_program_translator.py index c6eacfcb7f751ad03dfe6da3eef3ff8ee9f50b47..8b9234bd0f8ebdd7c97e7b6a0351f9f092766e64 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_program_translator.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_program_translator.py @@ -21,8 +21,8 @@ import unittest import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph.dygraph_to_static import ProgramTranslator -from paddle.fluid.dygraph.jit import declarative +from paddle.jit import ProgramTranslator +from paddle.jit.api import declarative from paddle.fluid.dygraph.dygraph_to_static.utils import func_to_source_code import paddle.jit.dy2static as _jst diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ptb_lm.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ptb_lm.py index 7e963cf42a59ea116a352dbba727202e6638cc3e..1c537528bb7cba6c31503eebe06c4748f2effd64 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ptb_lm.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ptb_lm.py @@ -19,9 +19,9 @@ import unittest import numpy as np import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph.dygraph_to_static import ProgramTranslator +from paddle.jit import ProgramTranslator from paddle.fluid.dygraph.base import to_variable -from paddle.fluid.dygraph.jit import declarative +from paddle.jit.api import declarative from paddle.fluid.dygraph.nn import Embedding from paddle.fluid.optimizer import SGDOptimizer diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_reinforcement_learning.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_reinforcement_learning.py index ecc9d26c8fed7226be65af6515686afc2fe6c8a5..a634cec0da5605329c4f3eeba0c05a85fbdcb7ec 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_reinforcement_learning.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_reinforcement_learning.py @@ -20,7 +20,8 @@ import paddle import paddle.fluid as fluid import paddle.fluid.dygraph.nn as nn from paddle.fluid.dygraph import to_variable, Layer -from paddle.fluid.dygraph import declarative, ProgramTranslator +from paddle.jit.api import declarative +from paddle.jit import ProgramTranslator import unittest diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_resnet.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_resnet.py index dfb371f414e2c5948b493d5f9dfb6ae151a77e76..72f78be55a56044bd5cc6b5f9416bc48cdeacd8e 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_resnet.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_resnet.py @@ -22,7 +22,7 @@ import numpy as np import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph import ProgramTranslator +from paddle.jit import ProgramTranslator from paddle.fluid.dygraph.nn import BatchNorm, Linear, Pool2D from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX @@ -311,9 +311,7 @@ class ResNetHelper: ) if batch_id == 10: if to_static: - fluid.dygraph.jit.save( - resnet, self.model_save_prefix - ) + paddle.jit.save(resnet, self.model_save_prefix) else: fluid.dygraph.save_dygraph( resnet.state_dict(), @@ -364,7 +362,7 @@ class ResNetHelper: def predict_dygraph_jit(self, data): with fluid.dygraph.guard(place): - resnet = fluid.dygraph.jit.load(self.model_save_prefix) + resnet = paddle.jit.load(self.model_save_prefix) resnet.eval() pred_res = resnet(data) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_resnet_amp.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_resnet_amp.py index aa53f663deb1f5dcb64c95b12cf08f2268c30f28..dbd98f2e000a60f8fc748ff9a06178cc81968d1d 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_resnet_amp.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_resnet_amp.py @@ -19,7 +19,7 @@ import numpy as np import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph import ProgramTranslator +from paddle.jit import ProgramTranslator from test_resnet import ResNet, optimizer_setting, SEED # NOTE: Reduce batch_size from 8 to 2 to avoid unittest timeout. diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_resnet_pure_fp16.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_resnet_pure_fp16.py index 9951d67c2b1a7a05fe00a2ee61e314815ccccf9c..2162e44917bcd5c6d10fd2a77866a0260fc7bbe9 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_resnet_pure_fp16.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_resnet_pure_fp16.py @@ -19,7 +19,7 @@ import numpy as np import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph import ProgramTranslator +from paddle.jit import ProgramTranslator from test_resnet import ResNet, optimizer_setting, SEED # NOTE: Reduce batch_size from 8 to 2 to avoid unittest timeout. diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_rollback.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_rollback.py index e1116d589a23e6f4c85535790209c0d2fbd3c90d..da80237b27cd130139de49aaba9382cf7733a1bc 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_rollback.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_rollback.py @@ -16,7 +16,7 @@ import unittest import paddle import numpy as np from paddle.fluid.dygraph.dygraph_to_static.utils import func_to_source_code -from paddle.fluid.dygraph.dygraph_to_static.program_translator import ( +from paddle.jit.dy2static.program_translator import ( StaticFunction, ) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_save_inference_model.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_save_inference_model.py index d486c5e8e106d17791f200ab4450960c9972e082..bacf03ace0a559cf3cfe3f128be7b3b7cc7af6de 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_save_inference_model.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_save_inference_model.py @@ -19,8 +19,8 @@ import numpy as np import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph.dygraph_to_static import ProgramTranslator -from paddle.fluid.dygraph.jit import declarative +from paddle.jit import ProgramTranslator +from paddle.jit.api import declarative from paddle.fluid.dygraph.dygraph_to_static.partial_program import ( partial_program_from, ) @@ -81,7 +81,7 @@ class TestDyToStaticSaveInferenceModel(unittest.TestCase): infer_model_dir = os.path.join( self.temp_dir.name, "test_dy2stat_inference_in_guard" ) - fluid.dygraph.jit.save( + paddle.jit.save( layer=layer, path=infer_model_prefix, input_spec=[x], @@ -111,7 +111,7 @@ class TestDyToStaticSaveInferenceModel(unittest.TestCase): ) model_filename = "model" + INFER_MODEL_SUFFIX params_filename = "model" + INFER_PARAMS_SUFFIX - fluid.dygraph.jit.save( + paddle.jit.save( layer=model, path=infer_model_prefix, input_spec=feed if feed else None, diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_save_load.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_save_load.py index 0898b72730441b0cf0de41d5f3875ba3cef17934..b64bd35a0b0666e6a59c670f82d1529fa0c4f5e6 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_save_load.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_save_load.py @@ -19,7 +19,7 @@ import tempfile import numpy as np import paddle.fluid as fluid -from paddle.fluid.dygraph.dygraph_to_static import ProgramTranslator +from paddle.jit import ProgramTranslator from paddle.fluid.optimizer import AdamOptimizer from test_fetch_feed import Linear diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_se_resnet.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_se_resnet.py index c5a25fca8d5206498f67deba6a10a8a547b8f95a..49d8f2df3aff3daaa4e21dc34ee7eb42a24d7a0c 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_se_resnet.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_se_resnet.py @@ -24,8 +24,8 @@ import paddle import paddle.fluid as fluid from paddle.fluid.dygraph.base import to_variable from paddle.fluid.dygraph.nn import BatchNorm, Linear, Pool2D -from paddle.fluid.dygraph import declarative -from paddle.fluid.dygraph import ProgramTranslator +from paddle.jit.api import declarative +from paddle.jit import ProgramTranslator from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX from predictor_utils import PredictorTools @@ -458,7 +458,7 @@ class TestSeResnet(unittest.TestCase): step_idx += 1 if step_idx == STEP_NUM: if to_static: - fluid.dygraph.jit.save( + paddle.jit.save( se_resnext, self.model_save_prefix, [img], @@ -520,7 +520,7 @@ class TestSeResnet(unittest.TestCase): def predict_dygraph_jit(self, data): with fluid.dygraph.guard(place): - se_resnext = fluid.dygraph.jit.load(self.model_save_prefix) + se_resnext = paddle.jit.load(self.model_save_prefix) se_resnext.eval() pred_res = se_resnext(data) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_sentiment.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_sentiment.py index d8c8aca10e8ee568649e7ee64860ed4c0501ecbe..f81c9a40c9469207e40e23a722dd0cb091e984b6 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_sentiment.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_sentiment.py @@ -18,7 +18,9 @@ import numpy as np import paddle import paddle.fluid as fluid from paddle.fluid.dygraph.nn import Linear, Embedding -from paddle.fluid.dygraph import to_variable, ProgramTranslator, declarative +from paddle.fluid.dygraph import to_variable +from paddle.jit import ProgramTranslator +from paddle.jit.api import declarative from test_lac import DynamicGRU diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_seq2seq.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_seq2seq.py index d4932b710c39186c9cbbff1ff450c34cf9639b22..c7bef3d7b1ca3a160e3e4cd6bb43efcefbcb9c62 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_seq2seq.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_seq2seq.py @@ -20,7 +20,7 @@ import unittest import numpy as np import paddle.fluid as fluid from paddle.fluid.clip import GradientClipByGlobalNorm -from paddle.fluid.dygraph.dygraph_to_static import ProgramTranslator +from paddle.jit import ProgramTranslator from seq2seq_dygraph_model import BaseModel, AttentionModel from seq2seq_utils import Seq2SeqModelHyperParams diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_simnet.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_simnet.py index 9762242385e75502ac5325f22a0a45350d8c8238..e4fb982166a326208aff3305fbed0a7e1e36f377 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_simnet.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_simnet.py @@ -19,7 +19,7 @@ import paddle.fluid as fluid import random import unittest -from paddle.fluid.dygraph import ProgramTranslator +from paddle.jit import ProgramTranslator from simnet_dygraph_model import BOW, HingeLoss SEED = 102 diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_tensor_shape.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_tensor_shape.py index 2087e615a576b507b2d0a7886b5bb9918620ed40..cb6ec59ee6bc88351f3ab3b300662d46455c9c44 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_tensor_shape.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_tensor_shape.py @@ -17,7 +17,7 @@ import numpy as np import unittest import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph.jit import declarative +from paddle.jit.api import declarative def dyfunc_tensor_shape_1(x): diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_tsm.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_tsm.py index f9c69aca6849ee3d3a0ede98e7f7231fe5426194..064ab0c3a502cbe9c6e83274cbe5adaac8de712b 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_tsm.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_tsm.py @@ -20,7 +20,9 @@ import sys import unittest import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph import declarative, ProgramTranslator, to_variable +from paddle.jit.api import declarative +from paddle.jit import ProgramTranslator +from paddle.fluid.dygraph import to_variable from paddle.fluid.dygraph.nn import BatchNorm, Linear, Pool2D from tsm_config_utils import merge_configs, parse_config, print_configs diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_typehint.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_typehint.py index 206ab40d0bc9b0621a392325031f0fa4544e0859..3096eff3406265bfe49934698714ce9d481f0266 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_typehint.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_typehint.py @@ -16,7 +16,7 @@ import numpy as np import paddle.fluid as fluid import unittest -from paddle.fluid.dygraph.jit import declarative +from paddle.jit.api import declarative SEED = 2020 np.random.seed(SEED) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_word2vec.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_word2vec.py index 95e993edddf4ebcffe52b5715c72b49c81a720a2..fc1341350c1659c309f1e111a647096fbb794963 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_word2vec.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_word2vec.py @@ -21,8 +21,8 @@ import unittest import paddle from paddle.fluid.dygraph.nn import Embedding -from paddle.fluid.dygraph import ProgramTranslator -from paddle.fluid.dygraph import declarative +from paddle.jit import ProgramTranslator +from paddle.jit.api import declarative def fake_text(): diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_yolov3.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_yolov3.py index 086e56828a3c6b4b4be73122ee34a957b50b3ce4..50144e74b93c93972ed89fb295bee08de1d49109 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_yolov3.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_yolov3.py @@ -19,7 +19,7 @@ import unittest import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph import ProgramTranslator +from paddle.jit import ProgramTranslator from paddle.fluid.dygraph import to_variable from yolov3 import cfg, YOLOv3 diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/transformer_dygraph_model.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/transformer_dygraph_model.py index 2e2a476dad1a5051f1f8883161010946243630b3..296d221c415c2d193b956a51b70a769346fe56ac 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/transformer_dygraph_model.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/transformer_dygraph_model.py @@ -23,7 +23,7 @@ from paddle.fluid.dygraph import ( Linear, to_variable, ) -from paddle.fluid.dygraph.jit import dygraph_to_static_func +from paddle.jit.api import dygraph_to_static_func from paddle.fluid.layers.utils import map_structure import paddle import paddle.nn.functional as F diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/yolov3.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/yolov3.py index 58dae8bcfeb593030f9bf87371b623cab2b85ec2..c0ef4408ff8ea40186215708d55489c8cc7acbd7 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/yolov3.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/yolov3.py @@ -18,7 +18,7 @@ import sys import paddle import paddle.fluid as fluid -from paddle.fluid.dygraph import declarative +from paddle.jit.api import declarative from paddle.fluid.param_attr import ParamAttr from paddle.fluid.regularizer import L2Decay diff --git a/python/paddle/fluid/tests/unittests/ipu/test_dy2static_ipu.py b/python/paddle/fluid/tests/unittests/ipu/test_dy2static_ipu.py index fd1c762f2095caa9316de4b8d6999d9cf8023602..90551314d9fb01d3a074eacafe81ab5a838bc950 100644 --- a/python/paddle/fluid/tests/unittests/ipu/test_dy2static_ipu.py +++ b/python/paddle/fluid/tests/unittests/ipu/test_dy2static_ipu.py @@ -17,7 +17,7 @@ import unittest import numpy as np import paddle -from paddle.fluid.dygraph.dygraph_to_static.program_translator import ( +from paddle.jit.dy2static.program_translator import ( ProgramCache, ) from paddle.fluid.tests.unittests.ipu.op_test_ipu import IPUD2STest diff --git a/python/paddle/fluid/tests/unittests/test_imperative_ptb_rnn.py b/python/paddle/fluid/tests/unittests/test_imperative_ptb_rnn.py index cfbc6b2560232276f16b42bdde946eaa166c40d2..4bc3ec36535f6d6afe72afb1a1816a80415ee21f 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_ptb_rnn.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_ptb_rnn.py @@ -20,7 +20,7 @@ from paddle.fluid.dygraph.nn import Embedding import paddle.fluid.framework as framework from paddle.fluid.optimizer import SGDOptimizer from paddle.fluid.dygraph.base import to_variable -from paddle.fluid.dygraph import TracedLayer +from paddle.jit import TracedLayer from test_imperative_base import new_program_scope import numpy as np from utils import DyGraphProgramDescTracerTestHelper, is_equal_program diff --git a/python/paddle/fluid/tests/unittests/test_imperative_resnet.py b/python/paddle/fluid/tests/unittests/test_imperative_resnet.py index 0b354868795ca5f78951e79a845eae9509343c3d..18e8b8d1cc321d5c0d358115add22d4cf85e9b48 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_resnet.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_resnet.py @@ -23,7 +23,7 @@ from paddle.fluid import Pool2D, BatchNorm, Linear from paddle.fluid.dygraph.base import to_variable from test_imperative_base import new_program_scope from utils import DyGraphProgramDescTracerTestHelper, is_equal_program -from paddle.fluid.dygraph import TracedLayer +from paddle.jit import TracedLayer from paddle.fluid.framework import _test_eager_guard, _in_legacy_dygraph # NOTE(zhiqiu): run with FLAGS_cudnn_deterministic=1 diff --git a/python/paddle/fluid/tests/unittests/test_imperative_transformer_sorted_gradient.py b/python/paddle/fluid/tests/unittests/test_imperative_transformer_sorted_gradient.py index 738e832a5d9538c959a85dc30dd6bb8f9f4bcf6a..8b34780ea7cc63f8f96d04aed9a46df6f47d9fc7 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_transformer_sorted_gradient.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_transformer_sorted_gradient.py @@ -17,7 +17,7 @@ import paddle import paddle.fluid as fluid from paddle.fluid import Embedding, LayerNorm, Linear, Layer from paddle.fluid.dygraph import to_variable, guard -from paddle.fluid.dygraph import TracedLayer +from paddle.jit import TracedLayer from test_imperative_base import new_program_scope from paddle.fluid.framework import _in_legacy_dygraph, _test_eager_guard from paddle.fluid import core diff --git a/python/paddle/fluid/tests/unittests/test_jit_layer.py b/python/paddle/fluid/tests/unittests/test_jit_layer.py index 6cdb01a03b7a69d63cf16816efd53aa9ec7af0c1..e6718fafeab92b08cd23498d89800210cf5aa700 100644 --- a/python/paddle/fluid/tests/unittests/test_jit_layer.py +++ b/python/paddle/fluid/tests/unittests/test_jit_layer.py @@ -20,7 +20,7 @@ import numpy as np from paddle.static import InputSpec from paddle.fluid.framework import _dygraph_place_guard from paddle.jit.layer import Layer -from paddle.fluid.dygraph.dygraph_to_static.program_translator import ( +from paddle.jit.dy2static.program_translator import ( ProgramTranslator, ) diff --git a/python/paddle/fluid/tests/unittests/test_jit_pre_save_hooks.py b/python/paddle/fluid/tests/unittests/test_jit_pre_save_hooks.py index 9b9ce8297ba4dfbae22a69c7531d3a40ceb69e18..69203733c2cb2466821f092be77a9b1980add471 100644 --- a/python/paddle/fluid/tests/unittests/test_jit_pre_save_hooks.py +++ b/python/paddle/fluid/tests/unittests/test_jit_pre_save_hooks.py @@ -16,7 +16,7 @@ import unittest import paddle -from paddle.fluid.dygraph.jit import ( +from paddle.jit.api import ( _run_save_pre_hooks, _clear_save_pre_hooks, _register_save_pre_hook, @@ -32,24 +32,20 @@ class TestPreSaveHooks(unittest.TestCase): _counter += 1 remove_handler = _register_save_pre_hook(fake_func) - self.assertEqual(len(paddle.fluid.dygraph.jit._save_pre_hooks), 1) - self.assertTrue( - paddle.fluid.dygraph.jit._save_pre_hooks[0] is fake_func - ) + self.assertEqual(len(paddle.jit.api._save_pre_hooks), 1) + self.assertTrue(paddle.jit.api._save_pre_hooks[0] is fake_func) # Test of avoiding redundancy hanging remove_handler = _register_save_pre_hook(fake_func) - self.assertEqual(len(paddle.fluid.dygraph.jit._save_pre_hooks), 1) - self.assertTrue( - paddle.fluid.dygraph.jit._save_pre_hooks[0] is fake_func - ) + self.assertEqual(len(paddle.jit.api._save_pre_hooks), 1) + self.assertTrue(paddle.jit.api._save_pre_hooks[0] is fake_func) remove_handler.remove() - self.assertEqual(len(paddle.fluid.dygraph.jit._save_pre_hooks), 0) + self.assertEqual(len(paddle.jit.api._save_pre_hooks), 0) remove_handler = _register_save_pre_hook(fake_func) _clear_save_pre_hooks() - self.assertEqual(len(paddle.fluid.dygraph.jit._save_pre_hooks), 0) + self.assertEqual(len(paddle.jit.api._save_pre_hooks), 0) global _counter _counter = 0 diff --git a/python/paddle/fluid/tests/unittests/test_jit_save_load.py b/python/paddle/fluid/tests/unittests/test_jit_save_load.py index 0dd05ea503696bc936755731809d54a1843dce59..7632c958464a4fe683ad0ce28c4019e681029bd8 100644 --- a/python/paddle/fluid/tests/unittests/test_jit_save_load.py +++ b/python/paddle/fluid/tests/unittests/test_jit_save_load.py @@ -24,7 +24,7 @@ from paddle.static import InputSpec import paddle.fluid as fluid from paddle.fluid.layers.utils import flatten from paddle.fluid.dygraph import Linear -from paddle.fluid.dygraph import declarative +from paddle.jit.api import declarative from paddle.fluid.dygraph.io import INFER_PARAMS_INFO_SUFFIX from paddle.fluid import unique_name diff --git a/python/paddle/fluid/tests/unittests/test_op_function_generator.py b/python/paddle/fluid/tests/unittests/test_op_function_generator.py index 4652dad62371e8b4295f1b86cb2ad4361e4d11f8..9b261b9eff940dd41b95cdddc3773338389bab8e 100644 --- a/python/paddle/fluid/tests/unittests/test_op_function_generator.py +++ b/python/paddle/fluid/tests/unittests/test_op_function_generator.py @@ -16,7 +16,7 @@ import unittest from paddle.fluid.framework import in_dygraph_mode import paddle.fluid as fluid import paddle.fluid.layers as layers -from paddle.fluid.dygraph.jit import TracedLayer +from paddle.jit.api import TracedLayer import numpy as np from paddle import _legacy_C_ops diff --git a/python/paddle/fluid/tests/unittests/test_traced_layer_err_msg.py b/python/paddle/fluid/tests/unittests/test_traced_layer_err_msg.py index 58bd77d733da2e93caec0da0adcacaf1dd21e105..c1642e9c1c923745dee318447c5567b46620b848 100644 --- a/python/paddle/fluid/tests/unittests/test_traced_layer_err_msg.py +++ b/python/paddle/fluid/tests/unittests/test_traced_layer_err_msg.py @@ -74,7 +74,7 @@ class TestTracedLayerErrMsg(unittest.TestCase): None, [in_x] ) self.assertEqual( - "The type of 'layer' in fluid.dygraph.jit.TracedLayer.trace must be fluid.dygraph.Layer, but received <{} 'NoneType'>.".format( + "The type of 'layer' in paddle.jit.TracedLayer.trace must be fluid.dygraph.Layer, but received <{} 'NoneType'>.".format( self.type_str ), str(e.exception), @@ -84,7 +84,7 @@ class TestTracedLayerErrMsg(unittest.TestCase): self.layer, 3 ) self.assertEqual( - "The type of 'each element of inputs' in fluid.dygraph.jit.TracedLayer.trace must be fluid.Variable, but received <{} 'int'>.".format( + "The type of 'each element of inputs' in paddle.jit.TracedLayer.trace must be fluid.Variable, but received <{} 'int'>.".format( self.type_str ), str(e.exception), @@ -94,7 +94,7 @@ class TestTracedLayerErrMsg(unittest.TestCase): self.layer, [True, 1] ) self.assertEqual( - "The type of 'each element of inputs' in fluid.dygraph.jit.TracedLayer.trace must be fluid.Variable, but received <{} 'bool'>.".format( + "The type of 'each element of inputs' in paddle.jit.TracedLayer.trace must be fluid.Variable, but received <{} 'bool'>.".format( self.type_str ), str(e.exception), @@ -120,7 +120,7 @@ class TestTracedLayerErrMsg(unittest.TestCase): with self.assertRaises(AssertionError) as e: traced_layer.set_strategy(1, fluid.ExecutionStrategy()) self.assertEqual( - "The type of 'build_strategy' in fluid.dygraph.jit.TracedLayer.set_strategy must be fluid.BuildStrategy, but received <{} 'int'>.".format( + "The type of 'build_strategy' in paddle.jit.TracedLayer.set_strategy must be fluid.BuildStrategy, but received <{} 'int'>.".format( self.type_str ), str(e.exception), @@ -129,7 +129,7 @@ class TestTracedLayerErrMsg(unittest.TestCase): with self.assertRaises(AssertionError) as e: traced_layer.set_strategy(fluid.BuildStrategy(), False) self.assertEqual( - "The type of 'exec_strategy' in fluid.dygraph.jit.TracedLayer.set_strategy must be fluid.ExecutionStrategy, but received <{} 'bool'>.".format( + "The type of 'exec_strategy' in paddle.jit.TracedLayer.set_strategy must be fluid.ExecutionStrategy, but received <{} 'bool'>.".format( self.type_str ), str(e.exception), @@ -158,7 +158,7 @@ class TestTracedLayerErrMsg(unittest.TestCase): with self.assertRaises(TypeError) as e: traced_layer.save_inference_model([0]) self.assertEqual( - "The type of 'path' in fluid.dygraph.jit.TracedLayer.save_inference_model must be <{} 'str'>, but received <{} 'list'>. ".format( + "The type of 'path' in paddle.jit.TracedLayer.save_inference_model must be <{} 'str'>, but received <{} 'list'>. ".format( self.type_str, self.type_str ), str(e.exception), @@ -166,7 +166,7 @@ class TestTracedLayerErrMsg(unittest.TestCase): with self.assertRaises(TypeError) as e: traced_layer.save_inference_model(path, [0], [None]) self.assertEqual( - "The type of 'each element of fetch' in fluid.dygraph.jit.TracedLayer.save_inference_model must be <{} 'int'>, but received <{} 'NoneType'>. ".format( + "The type of 'each element of fetch' in paddle.jit.TracedLayer.save_inference_model must be <{} 'int'>, but received <{} 'NoneType'>. ".format( self.type_str, self.type_str ), str(e.exception), @@ -174,7 +174,7 @@ class TestTracedLayerErrMsg(unittest.TestCase): with self.assertRaises(TypeError) as e: traced_layer.save_inference_model(path, [0], False) self.assertEqual( - "The type of 'fetch' in fluid.dygraph.jit.TracedLayer.save_inference_model must be (<{} 'NoneType'>, <{} 'list'>), but received <{} 'bool'>. ".format( + "The type of 'fetch' in paddle.jit.TracedLayer.save_inference_model must be (<{} 'NoneType'>, <{} 'list'>), but received <{} 'bool'>. ".format( self.type_str, self.type_str, self.type_str ), str(e.exception), @@ -182,7 +182,7 @@ class TestTracedLayerErrMsg(unittest.TestCase): with self.assertRaises(TypeError) as e: traced_layer.save_inference_model(path, [None], [0]) self.assertEqual( - "The type of 'each element of feed' in fluid.dygraph.jit.TracedLayer.save_inference_model must be <{} 'int'>, but received <{} 'NoneType'>. ".format( + "The type of 'each element of feed' in paddle.jit.TracedLayer.save_inference_model must be <{} 'int'>, but received <{} 'NoneType'>. ".format( self.type_str, self.type_str ), str(e.exception), @@ -190,7 +190,7 @@ class TestTracedLayerErrMsg(unittest.TestCase): with self.assertRaises(TypeError) as e: traced_layer.save_inference_model(path, True, [0]) self.assertEqual( - "The type of 'feed' in fluid.dygraph.jit.TracedLayer.save_inference_model must be (<{} 'NoneType'>, <{} 'list'>), but received <{} 'bool'>. ".format( + "The type of 'feed' in paddle.jit.TracedLayer.save_inference_model must be (<{} 'NoneType'>, <{} 'list'>), but received <{} 'bool'>. ".format( self.type_str, self.type_str, self.type_str ), str(e.exception), diff --git a/python/paddle/framework/io.py b/python/paddle/framework/io.py index d2975f80b32abcf2069290f9e0e2863761b1d4bf..7d1803c45ed29b6146730dfad11f7982bc3f9e16 100644 --- a/python/paddle/framework/io.py +++ b/python/paddle/framework/io.py @@ -33,7 +33,6 @@ from paddle.fluid.dygraph.io import ( _construct_params_and_buffers, _construct_program_holders, ) -from paddle.fluid.dygraph.jit import _SaveLoadConfig from paddle.fluid.framework import ( EagerParamBase, ParamBase, @@ -52,6 +51,7 @@ from paddle.fluid.io import ( _pickle_loads_mac, _unpack_saved_dict, ) +from paddle.jit.api import _SaveLoadConfig __all__ = [] diff --git a/python/paddle/hapi/dynamic_flops.py b/python/paddle/hapi/dynamic_flops.py index 624ee60a15cbc354ac3b82c904bfec2ce3e55923..677a7f2b732f6a1fd234ca27c66b94034732887d 100644 --- a/python/paddle/hapi/dynamic_flops.py +++ b/python/paddle/hapi/dynamic_flops.py @@ -17,7 +17,7 @@ import warnings import paddle.nn as nn import numpy as np from .static_flops import static_flops, Table -from paddle.fluid.dygraph.dygraph_to_static.program_translator import ( +from paddle.jit.dy2static.program_translator import ( unwrap_decorators, ) diff --git a/python/paddle/jit/__init__.py b/python/paddle/jit/__init__.py index a706d4d1211029a60f34dbb24bc03a0418e9030a..4f32b7e29c60d3939de76e07a3ed6ad73010fe51 100644 --- a/python/paddle/jit/__init__.py +++ b/python/paddle/jit/__init__.py @@ -13,26 +13,26 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ..fluid.dygraph.jit import save # noqa: F401 -from ..fluid.dygraph.jit import load # noqa: F401 -from ..fluid.dygraph.jit import TracedLayer # noqa: F401 -from ..fluid.dygraph.jit import set_code_level # noqa: F401 -from ..fluid.dygraph.jit import set_verbosity # noqa: F401 -from ..fluid.dygraph.jit import declarative as to_static # noqa: F401 -from ..fluid.dygraph.jit import not_to_static # noqa: F401 -from ..fluid.dygraph import ProgramTranslator # noqa: F401 -from ..fluid.dygraph.io import TranslatedLayer # noqa: F401 +from .api import save +from .api import load +from .api import TracedLayer +from .api import set_code_level +from .api import set_verbosity +from .api import declarative as to_static +from .api import not_to_static +from .api import TranslatedLayer -from . import dy2static # noqa: F401 +from . import dy2static +from .dy2static.program_translator import ProgramTranslator __all__ = [ # noqa 'save', 'load', - 'TracedLayer', 'to_static', 'ProgramTranslator', 'TranslatedLayer', 'set_code_level', 'set_verbosity', 'not_to_static', + 'TracedLayer', ] diff --git a/python/paddle/fluid/dygraph/jit.py b/python/paddle/jit/api.py similarity index 98% rename from python/paddle/fluid/dygraph/jit.py rename to python/paddle/jit/api.py index 042ddb25fc65efc6ce79824fb51ffb6ec4988664..8a2ed4ce1b8b87c83bd627c425fe34c101033782 100644 --- a/python/paddle/fluid/dygraph/jit.py +++ b/python/paddle/jit/api.py @@ -16,7 +16,6 @@ import os import pickle import warnings -import functools from collections import OrderedDict import inspect import threading @@ -44,7 +43,7 @@ from paddle.fluid.dygraph.dygraph_to_static.logging_utils import ( set_code_level, set_verbosity, ) -from paddle.fluid.dygraph.dygraph_to_static.program_translator import ( +from paddle.jit.dy2static.program_translator import ( ProgramTranslator, StaticFunction, unwrap_decorators, @@ -102,7 +101,7 @@ def _extract_vars(inputs, result_list, err_tag='inputs'): _extract_vars(var, result_list, err_tag) else: raise TypeError( - "The type of 'each element of {}' in fluid.dygraph.jit.TracedLayer.trace must be fluid.Variable, but received {}.".format( + "The type of 'each element of {}' in paddle.jit.TracedLayer.trace must be fluid.Variable, but received {}.".format( err_tag, type(inputs) ) ) @@ -139,7 +138,7 @@ def _dygraph_to_static_func_(dygraph_func): import paddle.fluid as fluid import numpy as np - from paddle.fluid.dygraph.jit import dygraph_to_static_func + from paddle.jit.api import dygraph_to_static_func @dygraph_to_static_func def func(x): @@ -1569,6 +1568,8 @@ class TracedLayer: Examples: .. code-block:: python: + import os + os.environ['FLAGS_enable_eager_mode'] = '0' import paddle class ExampleLayer(paddle.nn.Layer): @@ -1596,7 +1597,7 @@ class TracedLayer: """ assert isinstance( layer, Layer - ), "The type of 'layer' in fluid.dygraph.jit.TracedLayer.trace must be fluid.dygraph.Layer, but received {}.".format( + ), "The type of 'layer' in paddle.jit.TracedLayer.trace must be fluid.dygraph.Layer, but received {}.".format( type(layer) ) outs, prog, feed, fetch, parameters = _trace(layer, inputs) @@ -1619,6 +1620,8 @@ class TracedLayer: Examples: .. code-block:: python: + import os + os.environ['FLAGS_enable_eager_mode'] = '0' import paddle class ExampleLayer(paddle.nn.Layer): @@ -1647,12 +1650,12 @@ class TracedLayer: assert self._compiled_program is None, "Cannot set strategy after run" assert isinstance( build_strategy, (type(None), BuildStrategy) - ), "The type of 'build_strategy' in fluid.dygraph.jit.TracedLayer.set_strategy must be fluid.BuildStrategy, but received {}.".format( + ), "The type of 'build_strategy' in paddle.jit.TracedLayer.set_strategy must be fluid.BuildStrategy, but received {}.".format( type(build_strategy) ) assert isinstance( exec_strategy, (type(None), ExecutionStrategy) - ), "The type of 'exec_strategy' in fluid.dygraph.jit.TracedLayer.set_strategy must be fluid.ExecutionStrategy, but received {}.".format( + ), "The type of 'exec_strategy' in paddle.jit.TracedLayer.set_strategy must be fluid.ExecutionStrategy, but received {}.".format( type(exec_strategy) ) self._build_strategy = build_strategy @@ -1723,6 +1726,8 @@ class TracedLayer: Examples: .. code-block:: python: + import os + os.environ['FLAGS_enable_eager_mode'] = '0' import numpy as np import paddle @@ -1755,13 +1760,13 @@ class TracedLayer: path, "path", str, - "fluid.dygraph.jit.TracedLayer.save_inference_model", + "paddle.jit.TracedLayer.save_inference_model", ) check_type( feed, "feed", (type(None), list), - "fluid.dygraph.jit.TracedLayer.save_inference_model", + "paddle.jit.TracedLayer.save_inference_model", ) if isinstance(feed, list): for f in feed: @@ -1769,13 +1774,13 @@ class TracedLayer: f, "each element of feed", int, - "fluid.dygraph.jit.TracedLayer.save_inference_model", + "paddle.jit.TracedLayer.save_inference_model", ) check_type( fetch, "fetch", (type(None), list), - "fluid.dygraph.jit.TracedLayer.save_inference_model", + "paddle.jit.TracedLayer.save_inference_model", ) if isinstance(fetch, list): for f in fetch: @@ -1783,7 +1788,7 @@ class TracedLayer: f, "each element of fetch", int, - "fluid.dygraph.jit.TracedLayer.save_inference_model", + "paddle.jit.TracedLayer.save_inference_model", ) clip_extra = kwargs.get('clip_extra', True) # path check diff --git a/python/paddle/jit/dy2static/__init__.py b/python/paddle/jit/dy2static/__init__.py index 8cfc2ee6a36acda667626e86cc51c78ff946dbd8..605c3ea93bf48882abc596ad8d8ddb49cf7b6371 100644 --- a/python/paddle/jit/dy2static/__init__.py +++ b/python/paddle/jit/dy2static/__init__.py @@ -32,5 +32,8 @@ from .convert_operators import indexable as Indexable # noqa: F401 from .variable_trans_func import create_bool_as_type # noqa: F401 from .variable_trans_func import to_static_variable # noqa: F401 from .convert_operators import convert_shape_compare # noqa: F401 +from .assert_transformer import AssertTransformer +from .ast_transformer import DygraphToStaticAst +from .program_translator import convert_to_static __all__ = [] diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/assert_transformer.py b/python/paddle/jit/dy2static/assert_transformer.py similarity index 100% rename from python/paddle/fluid/dygraph/dygraph_to_static/assert_transformer.py rename to python/paddle/jit/dy2static/assert_transformer.py diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/ast_transformer.py b/python/paddle/jit/dy2static/ast_transformer.py similarity index 97% rename from python/paddle/fluid/dygraph/dygraph_to_static/ast_transformer.py rename to python/paddle/jit/dy2static/ast_transformer.py index 3ae91027f5aeedcb90b3db86e96f1f5970bfd507..975b2200ef0eb48d1d424ceca163ef9c0c275075 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/ast_transformer.py +++ b/python/paddle/jit/dy2static/ast_transformer.py @@ -18,14 +18,13 @@ # See details in https://github.com/serge-sans-paille/gast/ import os -from paddle.utils import gast from paddle.fluid.dygraph.dygraph_to_static.base_transformer import ( BaseTransformer, ) from paddle.fluid.dygraph.dygraph_to_static.early_return_transformer import ( EarlyReturnTransformer, ) -from paddle.fluid.dygraph.dygraph_to_static.assert_transformer import ( +from .assert_transformer import ( AssertTransformer, ) from paddle.fluid.dygraph.dygraph_to_static.basic_api_transformer import ( @@ -76,7 +75,6 @@ from paddle.fluid.dygraph.dygraph_to_static.decorator_transformer import ( from paddle.fluid.dygraph.dygraph_to_static import logging_utils from paddle.fluid.dygraph.dygraph_to_static.utils import ast_to_source_code -from paddle.fluid.dygraph.dygraph_to_static.utils import get_attribute_full_name __all__ = ['DygraphToStaticAst'] diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/program_translator.py b/python/paddle/jit/dy2static/program_translator.py similarity index 99% rename from python/paddle/fluid/dygraph/dygraph_to_static/program_translator.py rename to python/paddle/jit/dy2static/program_translator.py index 443242563132760b0135e8c8da09edffe31f71d0..ea4ecdbe03ca53b1c6887e8594e7b895b49f4c7f 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/program_translator.py +++ b/python/paddle/jit/dy2static/program_translator.py @@ -26,7 +26,6 @@ from paddle.fluid.data_feeder import check_type 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 paddle.fluid.dygraph.dygraph_to_static import DygraphToStaticAst from paddle.fluid.dygraph.dygraph_to_static import error from paddle.fluid.dygraph.dygraph_to_static import logging_utils from paddle.fluid.dygraph.dygraph_to_static.origin_info import ( @@ -59,7 +58,8 @@ from paddle.fluid.dygraph.dygraph_to_static.function_spec import ( get_buffers, get_parameters, ) -from paddle.fluid.wrapped_decorator import signature_safe_contextmanager + +from .ast_transformer import DygraphToStaticAst __all__ = ['ProgramTranslator', 'convert_to_static'] @@ -334,7 +334,7 @@ class StaticFunction: def train(self): if ( isinstance(self._class_instance, layers.Layer) - and self._class_instance.training == False + and self._class_instance.training is False ): raise RuntimeError( "Failed to switch train mode. {} is a Layer's method, " @@ -347,7 +347,7 @@ class StaticFunction: def eval(self): if ( isinstance(self._class_instance, layers.Layer) - and self._class_instance.training == True + and self._class_instance.training is True ): raise RuntimeError( "Failed to switch eval mode. {} is a Layer's method, " diff --git a/python/paddle/tests/test_model.py b/python/paddle/tests/test_model.py index 58c88e56482fa3188b56f70c97b757913cc8b72b..3ed4905c30750138ceea8f390566f3db5132d95d 100644 --- a/python/paddle/tests/test_model.py +++ b/python/paddle/tests/test_model.py @@ -31,10 +31,10 @@ from paddle.metric import Accuracy from paddle.vision.datasets import MNIST from paddle.vision.models import LeNet import paddle.vision.models as models -import paddle.fluid.dygraph.jit as jit +import paddle.jit as jit from paddle.io import DistributedBatchSampler, Dataset from paddle.hapi.model import prepare_distributed_context -from paddle.fluid.dygraph.dygraph_to_static.program_translator import ( +from paddle.jit.dy2static.program_translator import ( ProgramTranslator, )