[Dy2Stat-log] Call warnings.warn() to display the warning-message only once when calling StaticFunc.__call__ or ProgramTranslator().get_output (#28260)

revert-27871-prv-conv-grad-opt
liym27 4 years ago committed by GitHub
parent 96ae48b751
commit b1eb28d74b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -20,6 +20,7 @@ import inspect
import six import six
import textwrap import textwrap
import threading import threading
import warnings
import weakref import weakref
from paddle.fluid import framework from paddle.fluid import framework
@ -298,7 +299,11 @@ class StaticFunction(object):
# 1. call dygraph function directly if not enable `declarative` # 1. call dygraph function directly if not enable `declarative`
if not self._program_trans.enable_to_static: if not self._program_trans.enable_to_static:
logging_utils.warn( # NOTE(liym27):
# Here calls `warnings.warn` but not `logging_utils.warn` because by default warnings.warn(message)
# will show up **only once**. StaticFunction.__call__ will run many times, it is appropriate to
# display this warning message only once.
warnings.warn(
"The decorator '@paddle.jit.to_static' does NOT work when setting ProgramTranslator.enable to False. " "The decorator '@paddle.jit.to_static' does NOT work when setting ProgramTranslator.enable to False. "
"We will just return dygraph output. If you would like to get static graph output, please call API " "We will just return dygraph output. If you would like to get static graph output, please call API "
"ProgramTranslator.enable(True)") "ProgramTranslator.enable(True)")
@ -831,7 +836,9 @@ class ProgramTranslator(object):
), "Input dygraph_func is not a callable in ProgramTranslator.get_output" ), "Input dygraph_func is not a callable in ProgramTranslator.get_output"
if not self.enable_to_static: if not self.enable_to_static:
logging_utils.warn( # Here calls `warnings.warn` but not `logging_utils.warn` because by default warnings.warn(message)
# will show up **only once**.
warnings.warn(
"The ProgramTranslator.get_output doesn't work when setting ProgramTranslator.enable to False. " "The ProgramTranslator.get_output doesn't work when setting ProgramTranslator.enable to False. "
"We will just return dygraph output. " "We will just return dygraph output. "
"Please call ProgramTranslator.enable(True) if you would like to get static output." "Please call ProgramTranslator.enable(True) if you would like to get static output."

Loading…
Cancel
Save