Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Commit

Permalink
In files where we explicitly import tf.compat.v1, don't qualify acces…
Browse files Browse the repository at this point in the history
…s of tf.compat.v1 again.

PiperOrigin-RevId: 289135863
  • Loading branch information
afrozenator authored and copybara-github committed Jan 10, 2020
1 parent 8b0e689 commit e908bcf
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 21 deletions.
8 changes: 4 additions & 4 deletions tensor2tensor/data_generators/generator_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,18 +867,18 @@ def dict_pack(example):

def _standardize(self, dataset, keys):
"""Force dataset structure into a tuple of Tensors."""
shapes = tf.compat.v1.data.get_output_shapes(dataset)
shapes = tf.data.get_output_shapes(dataset)

if isinstance(shapes, dict):
keys = keys or tuple(shapes.keys())
dataset = dataset.map(lambda x: tuple(x[k] for k in keys))
shapes = tf.compat.v1.data.get_output_shapes(dataset)
shapes = tf.data.get_output_shapes(dataset)

if not all(isinstance(i, tf.TensorShape) for i in shapes):
# Internally this class expects tuples of Tensors, even for the degenerate
# case of a single sequence.
dataset = dataset.map(lambda x: (x,))
shapes = tf.compat.v1.data.get_output_shapes(dataset)
shapes = tf.data.get_output_shapes(dataset)

for s in shapes:
if not s.is_compatible_with(tf.TensorShape([None])):
Expand All @@ -890,7 +890,7 @@ def _standardize(self, dataset, keys):
if self._chop_long_sequences and len(shapes) != 1:
raise ValueError("chop_long_sequences expects a single sequence dataset.")

token_types = tf.compat.v1.data.get_output_types(dataset)
token_types = tf.data.get_output_types(dataset)
if len(set(token_types)) > 1:
raise ValueError("Inconsistent dtypes: {}".format(token_types))

Expand Down
2 changes: 1 addition & 1 deletion tensor2tensor/data_generators/problem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from tensor2tensor.utils import test_utils

import tensorflow.compat.v1 as tf
tf.compat.v1.enable_eager_execution()
tf.enable_eager_execution()


def assert_tensors_equal(sess, t1, t2, n):
Expand Down
2 changes: 1 addition & 1 deletion tensor2tensor/layers/common_video_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from tensor2tensor.utils import test_utils

import tensorflow.compat.v1 as tf
tf.compat.v1.enable_eager_execution()
tf.enable_eager_execution()


class CommonVideoTest(parameterized.TestCase, tf.test.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tensor2tensor/layers/discretization_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from tensor2tensor.utils import test_utils

import tensorflow.compat.v1 as tf
tf.compat.v1.enable_eager_execution()
tf.enable_eager_execution()


class DiscretizationTest(tf.test.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tensor2tensor/layers/latent_layers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from tensor2tensor.utils import test_utils

import tensorflow.compat.v1 as tf
tf.compat.v1.enable_eager_execution()
tf.enable_eager_execution()


def imagetransformer_latent_tiny():
Expand Down
2 changes: 1 addition & 1 deletion tensor2tensor/layers/modalities_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from tensor2tensor.utils import test_utils

import tensorflow.compat.v1 as tf
tf.compat.v1.enable_eager_execution()
tf.enable_eager_execution()


class ModalityTest(tf.test.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tensor2tensor/layers/ngram_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from tensor2tensor.utils import test_utils

import tensorflow.compat.v1 as tf
tf.compat.v1.enable_eager_execution()
tf.enable_eager_execution()


class NGramTest(tf.test.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tensor2tensor/utils/adafactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import tensorflow.compat.v1 as tf


class AdafactorOptimizer(tf.compat.v1.train.Optimizer):
class AdafactorOptimizer(tf.train.Optimizer):
"""Optimizer that implements the Adafactor algorithm.
Adafactor is described in https://arxiv.org/abs/1804.04235.
Expand Down
2 changes: 1 addition & 1 deletion tensor2tensor/utils/multistep_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import tensorflow.compat.v1 as tf


class MultistepAdamOptimizer(tf.compat.v1.train.AdamOptimizer):
class MultistepAdamOptimizer(tf.train.AdamOptimizer):
"""Adam with SGD updates every n steps with accumulated gradients."""

def __init__(self, learning_rate=0.001, beta1=0.9, beta2=0.999, epsilon=1e-8,
Expand Down
2 changes: 1 addition & 1 deletion tensor2tensor/utils/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def _register_base_optimizer(name, opt):
_register_base_optimizer(_name, _opt)


class ConditionalOptimizer(tf.compat.v1.train.Optimizer):
class ConditionalOptimizer(tf.train.Optimizer):
"""Conditional optimizer."""

def __init__(self, optimizer_name, lr, hparams, use_tpu=False): # pylint: disable=super-init-not-called
Expand Down
2 changes: 1 addition & 1 deletion tensor2tensor/utils/t2t_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from tensor2tensor.utils import test_utils

import tensorflow.compat.v1 as tf
tf.compat.v1.enable_eager_execution()
tf.enable_eager_execution()


class T2TModelTest(tf.test.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tensor2tensor/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def run_in_graph_and_eager_modes(func=None,
For example, consider the following unittest:
```python
tf.compat.v1.enable_eager_execution()
tf.enable_eager_execution()
class SomeTest(tf.test.TestCase):
Expand Down Expand Up @@ -120,5 +120,5 @@ def decorated(self, *args, **kwargs):


def test_main():
tf.compat.v1.enable_eager_execution()
tf.enable_eager_execution()
tf.test.main()
3 changes: 1 addition & 2 deletions tensor2tensor/utils/test_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
from tensor2tensor.utils import test_utils

import tensorflow.compat.v1 as tf

tf.compat.v1.enable_eager_execution()
tf.enable_eager_execution()


class RunInGraphAndEagerTest(tf.test.TestCase):
Expand Down
6 changes: 3 additions & 3 deletions tensor2tensor/utils/yellowfin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@


# Values for gate_gradients.
GATE_NONE = tf.compat.v1.train.Optimizer.GATE_NONE
GATE_OP = tf.compat.v1.train.Optimizer.GATE_OP
GATE_GRAPH = tf.compat.v1.train.Optimizer.GATE_GRAPH
GATE_NONE = tf.train.Optimizer.GATE_NONE
GATE_OP = tf.train.Optimizer.GATE_OP
GATE_GRAPH = tf.train.Optimizer.GATE_GRAPH


class YellowFinOptimizer(object):
Expand Down

0 comments on commit e908bcf

Please sign in to comment.