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 bd7f51d89b2014b143878e5351e48118d2d749b6..a6b207bb9937f0471ea03e3acb7453e2af512ecf 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 @@ -19,6 +19,7 @@ __all__ = ['convert_call'] import collections import copy import functools +import logging import inspect import pdb import re @@ -35,7 +36,9 @@ from paddle.fluid.dygraph.dygraph_to_static.program_translator import unwrap_dec from paddle.fluid.dygraph.layers import Layer # TODO(liym27): A better way to do this. -BUILTIN_LIKELY_MODULES = [collections, pdb, copy, inspect, re, six, numpy] +BUILTIN_LIKELY_MODULES = [ + collections, pdb, copy, inspect, re, six, numpy, logging +] translator_logger = TranslatorLogger() diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_recursive_call.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_recursive_call.py index 18645efad20a27386c9880516298f7fcc4962e23..ab524b1c32eab2f2397c4fa3ab4778bfce236c71 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_recursive_call.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_recursive_call.py @@ -16,6 +16,7 @@ from __future__ import print_function import unittest +import logging import numpy as np import paddle.fluid as fluid @@ -49,6 +50,16 @@ def nested_func(x_v): return res +@declarative +def dyfunc_with_third_library_logging(x_v): + logging.info('test dyfunc_with_third_library_logging') + if fluid.layers.mean(x_v).numpy()[0] > 5: + x_v = x_v - 1 + else: + x_v = x_v + 1 + return x_v + + class TestRecursiveCall1(unittest.TestCase): def setUp(self): self.input = np.random.random([10, 16]).astype('float32') @@ -163,5 +174,16 @@ class TestRecursiveCall2(unittest.TestCase): static_res)) +class TestThirdPartyLibrary(TestRecursiveCall2): + def _run(self): + with fluid.dygraph.guard(): + self.dygraph_func = dyfunc_with_third_library_logging + fluid.default_startup_program.random_seed = SEED + fluid.default_main_program.random_seed = SEED + data = fluid.dygraph.to_variable(self.input) + res = self.dygraph_func(data) + return res.numpy() + + if __name__ == '__main__': unittest.main()