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

Commit 512c9a2

Browse files
afrozenatorCopybara-Service
authored andcommitted
Migrate away from contrib.HParams to the newly forked over one.
PiperOrigin-RevId: 231998023
1 parent d45060a commit 512c9a2

29 files changed

+88
-67
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ and are registered with
383383
**Hyperparameter sets** are defined and registered in code with
384384
[`@registry.register_hparams`](https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/utils/registry.py)
385385
and are encoded in
386-
[`tf.contrib.training.HParams`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/training/python/training/hparam.py)
386+
[`HParams`](https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/utils/hparam.py)
387387
objects. The `HParams` are available to both the problem specification and the
388388
model. A basic set of hyperparameters are defined in
389389
[`common_hparams.py`](https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/layers/common_hparams.py)

docs/walkthrough.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ and are registered with
383383
**Hyperparameter sets** are defined and registered in code with
384384
[`@registry.register_hparams`](https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/utils/registry.py)
385385
and are encoded in
386-
[`tf.contrib.training.HParams`](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/training/python/training/hparam.py)
386+
[`HParams`](https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/utils/hparam.py)
387387
objects. The `HParams` are available to both the problem specification and the
388388
model. A basic set of hyperparameters are defined in
389389
[`common_hparams.py`](https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/layers/common_hparams.py)

tensor2tensor/data_generators/celeba_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from absl.testing import parameterized
2323
from tensor2tensor.data_generators import celeba
24+
from tensor2tensor.utils.hparam import HParams
2425

2526
import tensorflow as tf
2627

@@ -34,7 +35,7 @@ class CelebaTest(parameterized.TestCase, tf.test.TestCase):
3435
def testCelebaMultiResolutionPreprocessExample(self, resize_method):
3536
example = {"inputs": tf.random_uniform([218, 178, 3], minval=-1.)}
3637
mode = tf.estimator.ModeKeys.TRAIN
37-
hparams = tf.contrib.training.HParams(resolutions=[8, 16, 32])
38+
hparams = HParams(resolutions=[8, 16, 32])
3839
if resize_method is not None:
3940
hparams.resize_method = resize_method
4041

tensor2tensor/data_generators/imagenet_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from absl.testing import parameterized
2323
from tensor2tensor.data_generators import imagenet
24+
from tensor2tensor.utils.hparam import HParams
2425

2526
import tensorflow as tf
2627

@@ -34,7 +35,7 @@ class ImagenetTest(parameterized.TestCase, tf.test.TestCase):
3435
def testImagenetMultiResolutionPreprocessExample(self, resize_method):
3536
example = {"inputs": tf.random_uniform([64, 64, 3], minval=-1.)}
3637
mode = tf.estimator.ModeKeys.TRAIN
37-
hparams = tf.contrib.training.HParams(resolutions=[8, 16, 32])
38+
hparams = HParams(resolutions=[8, 16, 32])
3839
if resize_method is not None:
3940
hparams.resize_method = resize_method
4041

tensor2tensor/data_generators/mscoco_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from absl.testing import parameterized
2323
from tensor2tensor.data_generators import mscoco
24+
from tensor2tensor.utils.hparam import HParams
2425

2526
import tensorflow as tf
2627

@@ -34,7 +35,7 @@ class MscocoTest(parameterized.TestCase, tf.test.TestCase):
3435
def testMsCocoMultiResolutionPreprocessExample(self, resize_method):
3536
example = {"inputs": tf.random_uniform([400, 400, 3], minval=-1.)}
3637
mode = tf.estimator.ModeKeys.TRAIN
37-
hparams = tf.contrib.training.HParams(resolutions=[8, 16, 32])
38+
hparams = HParams(resolutions=[8, 16, 32])
3839
if resize_method is not None:
3940
hparams.resize_method = resize_method
4041

tensor2tensor/data_generators/problem.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from tensor2tensor.utils import data_reader
3030
from tensor2tensor.utils import metrics
3131
from tensor2tensor.utils import mlperf_log
32+
from tensor2tensor.utils.hparam import HParams
3233

3334
import tensorflow as tf
3435
from tensorflow.contrib.tpu.python.tpu import tpu_config
@@ -130,7 +131,7 @@ class TaskID(object):
130131

131132

132133
def default_model_hparams():
133-
return tf.contrib.training.HParams(
134+
return HParams(
134135
max_input_seq_length=0,
135136
max_target_seq_length=0,
136137
prepend_mode="none",
@@ -596,7 +597,7 @@ def dataset(self,
596597
output_buffer_size: int, how many elements to prefetch at end of pipeline.
597598
shuffle_files: whether to shuffle input files. Default behavior (i.e. when
598599
shuffle_files=None) is to shuffle if mode == TRAIN.
599-
hparams: tf.contrib.training.HParams; hparams to be passed to
600+
hparams: HParams; hparams to be passed to
600601
Problem.preprocess_example and Problem.hparams. If None, will use a
601602
default set that is a no-op.
602603
preprocess: bool, whether to map the Dataset through
@@ -992,9 +993,9 @@ def _create_modalities(problem_hparams, model_hparams):
992993
"""Creates modalities and overrides any according to model hparams.
993994
994995
Args:
995-
problem_hparams: tf.contrib.training.HParams for the Problem. It must have
996+
problem_hparams: HParams for the Problem. It must have
996997
modality which is a dict of strings to ModalityTypes or Modality classes.
997-
model_hparams: tf.contrib.training.HParams for the model. It may have
998+
model_hparams: HParams for the model. It may have
998999
input_modalities and target_modality, which will override
9991000
problem_hparams' modality input and target keys.
10001001
@@ -1024,7 +1025,7 @@ def _create_modalities(problem_hparams, model_hparams):
10241025

10251026
def _default_hparams():
10261027
"""A set of basic model hyperparameters."""
1027-
return tf.contrib.training.HParams(
1028+
return HParams(
10281029
# Use this parameter to get comparable perplexity numbers with different
10291030
# tokenizations. This value should be set to the ratio of the number of
10301031
# tokens in the test set according to the tokenization used to the number

tensor2tensor/data_generators/video_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def convert_videos_to_summaries(input_videos, output_videos, target_videos,
115115
output_videos: 5-D NumPy array, (NTHWC) model predictions.
116116
target_videos: 5-D NumPy array, (NTHWC) target frames.
117117
tag: tf summary tag.
118-
decode_hparams: tf.contrib.training.HParams.
118+
decode_hparams: HParams.
119119
display_ground_truth: Whether or not to display ground truth videos.
120120
Returns:
121121
summaries: a list of tf frame-by-frame and video summaries.
@@ -274,7 +274,7 @@ def max_frames_per_video(self, hparams):
274274
hparams.video_num_target_frames.
275275
276276
Args:
277-
hparams: tf.contrib.training.HParams.
277+
hparams: HParams.
278278
Returns:
279279
num_frames: int.
280280
"""

tensor2tensor/layers/common_hparams.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
from __future__ import print_function
2121
from six.moves import zip # pylint: disable=redefined-builtin
2222
from tensor2tensor.utils import registry
23+
from tensor2tensor.utils.hparam import HParams
2324

2425
import tensorflow as tf
2526

2627

2728
@registry.register_hparams("basic_1")
2829
def basic_params1():
2930
"""A set of basic hyperparameters."""
30-
return tf.contrib.training.HParams(
31+
return HParams(
3132
# If the problem consists of variable-length sequences
3233
# (see problem.batch_size_means_tokens()), then this is the number
3334
# of tokens per batch per GPU or per TPU core. Otherwise, this is

tensor2tensor/layers/common_image_attention.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def postprocess_image(x, rows, cols, hparams):
477477
number of elements in x is batch * rows * cols * hparams.hidden_size.
478478
rows: Integer representing number of rows in a 2-D data point.
479479
cols: Integer representing number of columns in a 2-D data point.
480-
hparams: tf.contrib.training.HParams set.
480+
hparams: HParams set.
481481
482482
Returns:
483483
Tensor of shape [batch, rows, cols, depth], where depth is
@@ -639,7 +639,7 @@ def create_output(decoder_output, rows, cols, targets, hparams):
639639
cols: Integer representing number of columns in a 2-D data point.
640640
targets: Tensor of shape [batch, hparams.img_len, hparams.img_len,
641641
hparams.num_channels].
642-
hparams: tf.contrib.training.HParams set.
642+
hparams: HParams set.
643643
644644
Returns:
645645
Tensor of shape [batch, hparams.img_len, hparams.img_len,

tensor2tensor/layers/common_image_attention_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from absl.testing import parameterized
2323
from tensor2tensor.layers import common_hparams
2424
from tensor2tensor.layers import common_image_attention
25+
from tensor2tensor.utils.hparam import HParams
2526

2627
import tensorflow as tf
2728

@@ -36,7 +37,7 @@ def testPostProcessImageTrainMode(self, likelihood, num_mixtures, depth):
3637
batch = 1
3738
rows = 8
3839
cols = 24
39-
hparams = tf.contrib.training.HParams(
40+
hparams = HParams(
4041
hidden_size=2,
4142
likelihood=likelihood,
4243
mode=tf.estimator.ModeKeys.TRAIN,
@@ -58,7 +59,7 @@ def testPostProcessImageInferMode(self, likelihood, num_mixtures, depth):
5859
cols = 24
5960
block_length = 4
6061
block_width = 2
61-
hparams = tf.contrib.training.HParams(
62+
hparams = HParams(
6263
block_raster_scan=True,
6364
hidden_size=2,
6465
likelihood=likelihood,
@@ -90,7 +91,7 @@ def testCreateOutputTrainMode(self, likelihood, num_mixtures, depth):
9091
cols = channels * width
9192
else:
9293
cols = width
93-
hparams = tf.contrib.training.HParams(
94+
hparams = HParams(
9495
hidden_size=2,
9596
likelihood=likelihood,
9697
mode=tf.estimator.ModeKeys.TRAIN,

0 commit comments

Comments
 (0)