Make tf2.enabled() available in the __internal__ namespace.

PiperOrigin-RevId: 338765979
Change-Id: Ifa8bbd78f468e0443de38fb4391e831e235e31f3
This commit is contained in:
Francois Chollet 2020-10-23 16:31:11 -07:00 committed by TensorFlower Gardener
parent 09338295b0
commit 1f60c85014
4 changed files with 19 additions and 4 deletions

View File

@ -24,24 +24,27 @@ from __future__ import print_function
import os
from tensorflow.python.util.tf_export import tf_export
_force_enable = None
def enable():
#Enables v2 behaviors.
# Enables v2 behaviors.
global _force_enable
_force_enable = True
def disable():
#Disables v2 behaviors.
# Disables v2 behaviors.
global _force_enable
_force_enable = False
@tf_export("__internal__.tf2.enabled", v1=[])
def enabled():
#Returns True iff TensorFlow 2.0 behavior should be enabled.
# Returns True iff TensorFlow 2.0 behavior should be enabled.
if _force_enable is None:
return os.getenv("TF2_BEHAVIOR", "0") != "0"
return _force_enable

View File

@ -11,6 +11,7 @@ TENSORFLOW_API_INIT_FILES = [
"__internal__/distribute/multi_process_runner/__init__.py",
"__internal__/test/__init__.py",
"__internal__/test/combinations/__init__.py",
"__internal__/tf2/__init__.py",
"__internal__/tracking/__init__.py",
"__operators__/__init__.py",
"audio/__init__.py",

View File

@ -16,6 +16,10 @@ tf_module {
name: "test"
mtype: "<type \'module\'>"
}
member {
name: "tf2"
mtype: "<type \'module\'>"
}
member {
name: "tracking"
mtype: "<type \'module\'>"

View File

@ -0,0 +1,7 @@
path: "tensorflow.__internal__.tf2"
tf_module {
member_method {
name: "enabled"
argspec: "args=[], varargs=None, keywords=None, defaults=None"
}
}