Add python/util/is_in_graph_mode.py

PiperOrigin-RevId: 185260675
This commit is contained in:
A. Unique TensorFlower 2018-02-10 11:22:55 -08:00 committed by TensorFlower Gardener
parent 00c135cc5f
commit f669885e1c
3 changed files with 32 additions and 2 deletions

View File

@ -30,6 +30,7 @@ from tensorflow.python.framework import c_api_util
from tensorflow.python.framework import device as pydev
from tensorflow.python.framework import errors
from tensorflow.python.util import compat
from tensorflow.python.util import is_in_graph_mode
from tensorflow.python.util import tf_contextlib
GRAPH_MODE = 0
@ -599,3 +600,10 @@ def export_run_metadata():
A RunMetadata protocol buffer.
"""
return context().export_run_metadata()
# Not every user creates a Context via context.context()
# (for example, enable_eager_execution in python/framework/ops.py),
# but they do all import this file. Note that IS_IN_GRAPH_MODE and
# in_graph_mode are both parameterless functions.
is_in_graph_mode.IS_IN_GRAPH_MODE = in_graph_mode

View File

@ -22,9 +22,9 @@ import collections
import functools
import re
from tensorflow.python.eager import context
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.util import decorator_utils
from tensorflow.python.util import is_in_graph_mode
from tensorflow.python.util import tf_contextlib
from tensorflow.python.util import tf_decorator
from tensorflow.python.util import tf_inspect
@ -400,7 +400,7 @@ def deprecated_args(date, instructions, *deprecated_arg_names_or_tuples,
"""Deprecation wrapper."""
# TODO(apassos) figure out a way to have reasonable performance with
# deprecation warnings and eager mode.
if context.in_graph_mode() and _PRINT_DEPRECATION_WARNINGS:
if is_in_graph_mode.IS_IN_GRAPH_MODE() and _PRINT_DEPRECATION_WARNINGS:
invalid_args = []
named_args = tf_inspect.getcallargs(func, *args, **kwargs)
for arg_name, spec in iter(deprecated_positions.items()):

View File

@ -0,0 +1,22 @@
# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""A function that tells you if the program is running in graph mode."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
# Call IS_IN_GRAPH_MODE() when you want to know whether the thread is in
# graph mode. By default, we always are.
IS_IN_GRAPH_MODE = lambda: True