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

Commit af52f5f

Browse files
Merge branch 'master' into master
2 parents 2ced78d + cd222d3 commit af52f5f

File tree

99 files changed

+5990
-2054
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+5990
-2054
lines changed

README.md

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,25 @@ send along a pull request to add your dataset or model.
2323
See [our contribution
2424
doc](CONTRIBUTING.md) for details and our [open
2525
issues](https://github.com/tensorflow/tensor2tensor/issues).
26-
And chat with us and other users on
27-
[Gitter](https://gitter.im/tensor2tensor/Lobby).
26+
You can chat with us and other users on
27+
[Gitter](https://gitter.im/tensor2tensor/Lobby) and please join our
28+
[Google Group](https://groups.google.com/forum/#!forum/tensor2tensor) to keep up
29+
with T2T announcements.
30+
31+
Here is a one-command version that installs tensor2tensor, downloads the data,
32+
trains an English-German translation model, and lets you use it interactively:
33+
```
34+
pip install tensor2tensor && t2t-trainer \
35+
--generate_data \
36+
--data_dir=~/t2t_data \
37+
--problems=wmt_ende_tokens_32k \
38+
--model=transformer \
39+
--hparams_set=transformer_base_single_gpu \
40+
--output_dir=~/t2t_train/base \
41+
--decode_interactive
42+
```
43+
44+
See the [Walkthrough](#walkthrough) below for more details on each step.
2845

2946
### Contents
3047

@@ -69,11 +86,8 @@ mkdir -p $DATA_DIR $TMP_DIR $TRAIN_DIR
6986
t2t-datagen \
7087
--data_dir=$DATA_DIR \
7188
--tmp_dir=$TMP_DIR \
72-
--num_shards=100 \
7389
--problem=$PROBLEM
7490
75-
cp $TMP_DIR/tokens.vocab.* $DATA_DIR
76-
7791
# Train
7892
# * If you run out of memory, add --hparams='batch_size=2048' or even 1024.
7993
t2t-trainer \
@@ -153,7 +167,7 @@ python -c "from tensor2tensor.models.transformer import Transformer"
153167
specification.
154168
* Support for multi-GPU machines and synchronous (1 master, many workers) and
155169
asynchrounous (independent workers synchronizing through a parameter server)
156-
distributed training.
170+
[distributed training](https://github.com/tensorflow/tensor2tensor/tree/master/docs/distributed_training.md).
157171
* Easily swap amongst datasets and models by command-line flag with the data
158172
generation script `t2t-datagen` and the training script `t2t-trainer`.
159173

@@ -173,8 +187,10 @@ and many common sequence datasets are already available for generation and use.
173187

174188
**Problems** define training-time hyperparameters for the dataset and task,
175189
mainly by setting input and output **modalities** (e.g. symbol, image, audio,
176-
label) and vocabularies, if applicable. All problems are defined in
177-
[`problem_hparams.py`](https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/data_generators/problem_hparams.py).
190+
label) and vocabularies, if applicable. All problems are defined either in
191+
[`problem_hparams.py`](https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/data_generators/problem_hparams.py)
192+
or are registered with `@registry.register_problem` (run `t2t-datagen` to see
193+
the list of all available problems).
178194
**Modalities**, defined in
179195
[`modality.py`](https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/utils/modality.py),
180196
abstract away the input and output data types so that **models** may deal with
@@ -211,7 +227,7 @@ inference. Users can easily switch between problems, models, and hyperparameter
211227
sets by using the `--model`, `--problems`, and `--hparams_set` flags. Specific
212228
hyperparameters can be overridden with the `--hparams` flag. `--schedule` and
213229
related flags control local and distributed training/evaluation
214-
([distributed training documentation](https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/docs/distributed_training.md)).
230+
([distributed training documentation](https://github.com/tensorflow/tensor2tensor/tree/master/docs/distributed_training.md)).
215231

216232
---
217233

@@ -222,7 +238,7 @@ enables easily adding new ones and easily swapping amongst them by command-line
222238
flag. You can add your own components without editing the T2T codebase by
223239
specifying the `--t2t_usr_dir` flag in `t2t-trainer`.
224240

225-
You can currently do so for models, hyperparameter sets, and modalities. Please
241+
You can do so for models, hyperparameter sets, modalities, and problems. Please
226242
do submit a pull request if your component might be useful to others.
227243

228244
Here's an example with a new hyperparameter set:
@@ -242,7 +258,7 @@ def transformer_my_very_own_hparams_set():
242258

243259
```python
244260
# In ~/usr/t2t_usr/__init__.py
245-
import my_registrations
261+
from . import my_registrations
246262
```
247263

248264
```
@@ -253,9 +269,18 @@ You'll see under the registered HParams your
253269
`transformer_my_very_own_hparams_set`, which you can directly use on the command
254270
line with the `--hparams_set` flag.
255271

272+
`t2t-datagen` also supports the `--t2t_usr_dir` flag for `Problem`
273+
registrations.
274+
256275
## Adding a dataset
257276

258-
See the [data generators
277+
To add a new dataset, subclass
278+
[`Problem`](https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/data_generators/problem.py)
279+
and register it with `@registry.register_problem`. See
280+
[`WMTEnDeTokens8k`](https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/data_generators/wmt.py)
281+
for an example.
282+
283+
Also see the [data generators
259284
README](https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/data_generators/README.md).
260285

261286
---

tensor2tensor/docs/distributed_training.md renamed to docs/distributed_training.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,54 @@ along with a set of flags.
1010

1111
## `TF_CONFIG`
1212

13-
Both workers and parameter servers must have the `TF_CONFIG` environment
13+
Both masters and parameter servers must have the `TF_CONFIG` environment
1414
variable set.
1515

1616
The `TF_CONFIG` environment variable is a json-encoded string with the addresses
17-
of the workers and parameter servers (in the `'cluster'` key) and the
17+
of the masters and parameter servers (in the `'cluster'` key) and the
1818
identification of the current task (in the `'task'` key).
1919

2020
For example:
2121

2222
```
2323
cluster = {
2424
'ps': ['host1:2222', 'host2:2222'],
25-
'worker': ['host3:2222', 'host4:2222', 'host5:2222']
25+
'master': ['host3:2222', 'host4:2222', 'host5:2222']
2626
}
2727
os.environ['TF_CONFIG'] = json.dumps({
2828
'cluster': cluster,
29-
'task': {'type': 'worker', 'index': 1}
29+
'task': {'type': 'master', 'index': 1},
30+
'environment': 'cloud',
3031
})
3132
```
3233

3334
## Command-line flags
3435

35-
The following T2T command-line flags must also be set on the workers for
36+
The following T2T command-line flags must also be set on the masters for
3637
distributed training:
3738

3839
- `--master=grpc://$ADDRESS`
39-
- `--worker_replicas=$NUM_WORKERS`
40-
- `--worker_gpu=$NUM_GPUS_PER_WORKER`
41-
- `--worker_id=$WORKER_ID`
40+
- `--worker_replicas=$NUM_MASTERS`
41+
- `--worker_gpu=$NUM_GPUS_PER_MASTER`
42+
- `--worker_id=$MASTER_ID`
43+
- `--worker_job='/job:master'`
4244
- `--ps_replicas=$NUM_PS`
4345
- `--ps_gpu=$NUM_GPUS_PER_PS`
4446
- `--schedule=train`
4547
- `--sync`, if you want synchronous training, i.e. for there to be a single
46-
master worker coordinating the work across "ps" jobs (yes, the naming is
47-
unfortunate). If not set, then each worker operates independently while
48-
variables are shared on the parameter servers.
48+
master coordinating the work across "ps" jobs. If not set, then each master
49+
operates independently while variables are shared on the parameter servers.
4950

50-
Parameter servers only need `--schedule=run_std_server`.
51+
Parameter servers only need `--master=grpc://$ADDRESS` and
52+
`--schedule=run_std_server`.
5153

5254
## Utility to produce `TF_CONFIG` and flags
5355

54-
[`bin/make_tf_configs.py`](https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/bin/make_tf_configs.py))
56+
[`t2t-make-tf-configs`](https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/bin/t2t-make-tf-configs))
5557
generates the `TF_CONFIG` json strings and the above-mentioned command-line
56-
flags for the workers and parameter servers.
58+
flags for the masters and parameter servers.
5759

58-
Given a set of worker and parameter server addresses, the script outputs, for
60+
Given a set of master and parameter server addresses, the script outputs, for
5961
each job, a line with the `TF_CONFIG` environment variable and the command-line
6062
flags necessary for distributed training. For each job, you should invoke the
6163
`t2t-trainer` with the `TF_CONFIG` value and flags that are output.
@@ -66,6 +68,9 @@ For example:
6668
TF_CONFIG=$JOB_TF_CONFIG t2t-trainer $JOB_FLAGS --model=transformer ...
6769
```
6870

71+
Modify the `--worker_gpu` and `--ps_gpu` flags, which specify how many gpus are
72+
on each master and ps, respectively, as needed for your machine/cluster setup.
73+
6974
## Command-line flags for eval jobs
7075

7176
Eval jobs should set the following flags and do not need the `TF_CONFIG`

docs/index.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# T2T: Tensor2Tensor Transformers
2+
3+
Check us out on
4+
<a href=https://github.com/tensorflow/tensor2tensor>
5+
GitHub
6+
<img src="https://github.com/favicon.ico" width="16">
7+
</a>
8+
.
9+
10+
[![PyPI
11+
version](https://badge.fury.io/py/tensor2tensor.svg)](https://badge.fury.io/py/tensor2tensor)
12+
[![GitHub
13+
Issues](https://img.shields.io/github/issues/tensorflow/tensor2tensor.svg)](https://github.com/tensorflow/tensor2tensor/issues)
14+
[![Contributions
15+
welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg)](CONTRIBUTING.md)
16+
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/tensor2tensor/Lobby)
17+
[![License](https://img.shields.io/badge/License-Apache%202.0-brightgreen.svg)](https://opensource.org/licenses/Apache-2.0)
18+
19+
See our
20+
[README](https://github.com/tensorflow/tensor2tensor/tree/master/tensor2tensor/README.md)
21+
for documentation.
22+
23+
More documentation and tutorials coming soon...

setup.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55

66
setup(
77
name='tensor2tensor',
8-
version='1.0.12',
8+
version='1.1.3',
99
description='Tensor2Tensor',
1010
author='Google Inc.',
1111
author_email='no-reply@google.com',
1212
url='http://github.com/tensorflow/tensor2tensor',
1313
license='Apache 2.0',
1414
packages=find_packages(),
15-
scripts=['tensor2tensor/bin/t2t-trainer', 'tensor2tensor/bin/t2t-datagen'],
15+
package_data={'tensor2tensor.data_generators': ['test_data/*']},
16+
scripts=[
17+
'tensor2tensor/bin/t2t-trainer',
18+
'tensor2tensor/bin/t2t-datagen',
19+
'tensor2tensor/bin/t2t-make-tf-configs',
20+
],
1621
install_requires=[
1722
'numpy',
1823
'sympy',
@@ -22,6 +27,8 @@
2227
'tensorflow': ['tensorflow>=1.2.0rc1'],
2328
'tensorflow_gpu': ['tensorflow-gpu>=1.2.0rc1'],
2429
},
30+
tests_require=['nose'],
31+
test_suite='nose.collector',
2532
classifiers=[
2633
'Development Status :: 4 - Beta',
2734
'Intended Audience :: Developers',

tensor2tensor/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Copyright 2017 Google Inc.
1+
# coding=utf-8
2+
# Copyright 2017 The Tensor2Tensor Authors.
23
#
34
# Licensed under the Apache License, Version 2.0 (the "License");
45
# you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)