diff --git a/paddle/fluid/pybind/op_function_generator.h b/paddle/fluid/pybind/op_function_generator.h index 65b5beb865d1c267d50e3251d5a0e711942f737a..a4e56d1508038cda5f00af7637a505988fddb4a8 100644 --- a/paddle/fluid/pybind/op_function_generator.h +++ b/paddle/fluid/pybind/op_function_generator.h @@ -98,6 +98,9 @@ std::map> op_ins_map = { "CustomDistAlias", "CustomDistAliasProbs"}}, {"check_finite_and_unscale", {"X", "Scale", "FloatStatus"}}, {"group_norm", {"X", "Scale", "Bias"}}, + {"linear_chain_crf", {"Emission", "Transition", "Label", "Length"}}, + {"crf_decoding", {"Emission", "Transition", "Label", "Length"}}, + {"chunk_eval", {"Inference", "Label", "SeqLength"}}, }; // NOTE(zhiqiu): Like op_ins_map. 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 ab6a82808eb6fc34d4dd23acea93be83123dbac0..88c6060abf7d9d05d7c975b5942cb11e884ffd52 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 @@ -27,6 +27,8 @@ from paddle.fluid.dygraph import to_variable from paddle.fluid.dygraph import Embedding, Linear, GRUUnit from paddle.fluid.dygraph import declarative, ProgramTranslator from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX +from paddle.fluid.framework import _non_static_mode +from paddle import _C_ops SEED = 2020 @@ -167,6 +169,11 @@ class LinearChainCRF(fluid.dygraph.Layer): self._transition = value def forward(self, input, label, length=None): + if _non_static_mode(): + _, _, _, log_likelihood = _C_ops.linear_chain_crf( + input, self._transition, label, length, "is_test", + self._is_test) + return log_likelihood alpha = self._helper.create_variable_for_type_inference( dtype=self._dtype) @@ -218,6 +225,9 @@ class CRFDecoding(fluid.dygraph.Layer): self._transition = value def forward(self, input, label=None, length=None): + if _non_static_mode(): + return _C_ops.crf_decoding(input, self._transition, label, length, + "is_test", self._is_test) viterbi_path = self._helper.create_variable_for_type_inference( dtype=self._dtype) @@ -245,6 +255,11 @@ class ChunkEval(fluid.dygraph.Layer): self.excluded_chunk_types = excluded_chunk_types def forward(self, input, label, seq_length=None): + if _non_static_mode(): + return _C_ops.chunk_eval( + input, label, seq_length, "num_chunk_types", + self.num_chunk_types, "chunk_scheme", self.chunk_scheme, + "excluded_chunk_types", self.excluded_chunk_types or []) precision = self._helper.create_variable_for_type_inference( dtype="float32") 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 d4c41781078b760feadbb5e2c928968414d17063..d2c43c31a8839a4acfc66feb981b5e4309d66e42 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 @@ -232,7 +232,9 @@ class TestEnableDeclarative(unittest.TestCase): dygraph_func = self.program_translator.get_func(simple_func) self.assertTrue(callable(dygraph_func)) dygraph_output = dygraph_func(self.x, self.weight) - self.assertTrue(isinstance(dygraph_output, fluid.core.VarBase)) + self.assertTrue( + isinstance(dygraph_output, (fluid.core.VarBase, + fluid.core.eager.Tensor))) def test_enable_disable_get_program(self): @@ -254,7 +256,9 @@ class TestEnableDeclarative(unittest.TestCase): with fluid.dygraph.guard(): dygraph_output = self.program_translator.get_program( simple_func, self.x, self.weight) - self.assertTrue(isinstance(dygraph_output, fluid.core.VarBase)) + self.assertTrue( + isinstance(dygraph_output, (fluid.core.VarBase, + fluid.core.eager.Tensor))) def test_enable_disable_declarative(self):