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

Commit fe5f8ad

Browse files
author
Ryan Sepassi
committed
Add full system exercise to Travis
PiperOrigin-RevId: 170553043
1 parent ed7862c commit fe5f8ad

File tree

3 files changed

+64
-19
lines changed

3 files changed

+64
-19
lines changed

.travis.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,21 @@ before_install:
88
install:
99
- pip install tensorflow
1010
- pip install .[tests]
11+
env:
12+
- T2T_PROBLEM=algorithmic_reverse_binary40_test
13+
- T2T_DATA_DIR=/tmp/t2t-data
14+
- T2T_TRAIN_DIR=/tmp/t2t-train
1115
script:
1216
- pytest --ignore=tensor2tensor/utils/registry_test.py --ignore=tensor2tensor/utils/trainer_utils_test.py --ignore=tensor2tensor/problems_test.py
1317
- pytest tensor2tensor/utils/registry_test.py
1418
- pytest tensor2tensor/utils/trainer_utils_test.py
19+
- t2t-datagen 2>&1 | grep translate && echo passed
20+
- python -c "from tensor2tensor.models import transformer; print(transformer.Transformer.__name__)"
21+
- t2t-trainer --registry_help
22+
- mkdir $T2T_DATA_DIR
23+
- mkdir $T2T_TRAIN_DIR
24+
- t2t-datagen --problem=$T2T_PROBLEM --data_dir=$T2T_DATA_DIR
25+
- t2t-trainer --problems=$T2T_PROBLEM --data_dir=$T2T_DATA_DIR --model=transformer --hparams_set=transformer_tiny --train_steps=5 --eval_steps=5 --output_dir=$T2T_TRAIN_DIR
26+
- t2t-decoder --problems=$T2T_PROBLEM --data_dir=$T2T_DATA_DIR --model=transformer --hparams_set=transformer_tiny --output_dir=$T2T_TRAIN_DIR
1527
git:
16-
depth: 3
28+
depth: 3

tensor2tensor/data_generators/algorithmic.py

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ def num_shards(self):
6262
return 10
6363

6464
def generate_data(self, data_dir, _, task_id=-1):
65+
6566
def generator_eos(nbr_symbols, max_length, nbr_cases):
6667
"""Shift by NUM_RESERVED_IDS and append EOS token."""
6768
for case in self.generator(nbr_symbols, max_length, nbr_cases):
6869
new_case = {}
6970
for feature in case:
70-
new_case[feature] = [i + text_encoder.NUM_RESERVED_TOKENS
71-
for i in case[feature]] + [text_encoder.EOS_ID]
71+
new_case[feature] = [
72+
i + text_encoder.NUM_RESERVED_TOKENS for i in case[feature]
73+
] + [text_encoder.EOS_ID]
7274
yield new_case
7375

7476
utils.generate_dataset_and_shuffle(
@@ -154,10 +156,7 @@ def generator(self, nbr_symbols, max_length, nbr_cases):
154156
for _ in xrange(nbr_cases):
155157
l = np.random.randint(max_length) + 1
156158
inputs = [np.random.randint(nbr_symbols - shift) for _ in xrange(l)]
157-
yield {
158-
"inputs": inputs,
159-
"targets": [i + shift for i in inputs]
160-
}
159+
yield {"inputs": inputs, "targets": [i + shift for i in inputs]}
161160

162161
@property
163162
def dev_length(self):
@@ -191,10 +190,7 @@ def generator(self, nbr_symbols, max_length, nbr_cases):
191190
for _ in xrange(nbr_cases):
192191
l = np.random.randint(max_length) + 1
193192
inputs = [np.random.randint(nbr_symbols) for _ in xrange(l)]
194-
yield {
195-
"inputs": inputs,
196-
"targets": list(reversed(inputs))
197-
}
193+
yield {"inputs": inputs, "targets": list(reversed(inputs))}
198194

199195

200196
@registry.register_problem
@@ -272,10 +268,7 @@ def reverse_generator_nlplike(nbr_symbols,
272268
for _ in xrange(nbr_cases):
273269
l = int(abs(np.random.normal(loc=max_length / 2, scale=std_dev)) + 1)
274270
inputs = zipf_random_sample(distr_map, l)
275-
yield {
276-
"inputs": inputs,
277-
"targets": list(reversed(inputs))
278-
}
271+
yield {"inputs": inputs, "targets": list(reversed(inputs))}
279272

280273

281274
@registry.register_problem
@@ -287,8 +280,8 @@ def num_symbols(self):
287280
return 8000
288281

289282
def generator(self, nbr_symbols, max_length, nbr_cases):
290-
return reverse_generator_nlplike(
291-
nbr_symbols, max_length, nbr_cases, 10, 1.300)
283+
return reverse_generator_nlplike(nbr_symbols, max_length, nbr_cases, 10,
284+
1.300)
292285

293286
@property
294287
def train_length(self):
@@ -308,8 +301,8 @@ def num_symbols(self):
308301
return 32000
309302

310303
def generator(self, nbr_symbols, max_length, nbr_cases):
311-
return reverse_generator_nlplike(
312-
nbr_symbols, max_length, nbr_cases, 10, 1.050)
304+
return reverse_generator_nlplike(nbr_symbols, max_length, nbr_cases, 10,
305+
1.050)
313306

314307

315308
def lower_endian_to_number(l, base):
@@ -431,3 +424,28 @@ class AlgorithmicMultiplicationDecimal40(AlgorithmicMultiplicationBinary40):
431424
@property
432425
def num_symbols(self):
433426
return 10
427+
428+
429+
@registry.register_problem
430+
class AlgorithmicReverseBinary40Test(AlgorithmicReverseBinary40):
431+
"""Test Problem with tiny dataset."""
432+
433+
@property
434+
def train_length(self):
435+
return 10
436+
437+
@property
438+
def dev_length(self):
439+
return 10
440+
441+
@property
442+
def train_size(self):
443+
return 1000
444+
445+
@property
446+
def dev_size(self):
447+
return 100
448+
449+
@property
450+
def num_shards(self):
451+
return 1

tensor2tensor/tpu/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# coding=utf-8
2+
# Copyright 2017 The Tensor2Tensor Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+

0 commit comments

Comments
 (0)