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

Commit 758991d

Browse files
authored
Merge pull request #482 from rsepassi/push
v1.4
2 parents 5c80095 + bac1321 commit 758991d

File tree

96 files changed

+8664
-2637
lines changed

Some content is hidden

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

96 files changed

+8664
-2637
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ env:
1414
- T2T_DATA_DIR=/tmp/t2t-data
1515
- T2T_TRAIN_DIR=/tmp/t2t-train
1616
script:
17-
- pytest --ignore=tensor2tensor/utils/registry_test.py --ignore=tensor2tensor/utils/trainer_utils_test.py --ignore=tensor2tensor/problems_test.py --ignore=tensor2tensor/tpu/tpu_trainer_lib_test.py
17+
- pytest --ignore=tensor2tensor/utils/registry_test.py --ignore=tensor2tensor/problems_test.py --ignore=tensor2tensor/tpu/tpu_trainer_lib_test.py
1818
- pytest tensor2tensor/utils/registry_test.py
19-
- pytest tensor2tensor/utils/trainer_utils_test.py
19+
- pytest tensor2tensor/tpu/tpu_trainer_lib_test.py
2020
- t2t-datagen 2>&1 | grep translate && echo passed
2121
- python -c "from tensor2tensor.models import transformer; print(transformer.Transformer.__name__)"
2222
- t2t-trainer --registry_help

README.md

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# T2T: Tensor2Tensor Transformers
1+
# Tensor2Tensor
22

33
[![PyPI
44
version](https://badge.fury.io/py/tensor2tensor.svg)](https://badge.fury.io/py/tensor2tensor)
@@ -10,11 +10,18 @@ welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg)](CO
1010
[![License](https://img.shields.io/badge/License-Apache%202.0-brightgreen.svg)](https://opensource.org/licenses/Apache-2.0)
1111
[![Travis](https://img.shields.io/travis/tensorflow/tensor2tensor.svg)](https://travis-ci.org/tensorflow/tensor2tensor)
1212

13-
[T2T](https://github.com/tensorflow/tensor2tensor) is a modular and extensible
14-
library and binaries for supervised learning with TensorFlow and with support
15-
for sequence tasks. It is actively used and maintained by researchers and
16-
engineers within the Google Brain team. You can read more about Tensor2Tensor in
17-
the recent [Google Research Blog post introducing
13+
[Tensor2Tensor](https://github.com/tensorflow/tensor2tensor), or
14+
[T2T](https://github.com/tensorflow/tensor2tensor) for short, is a library
15+
of deep learning models and datasets. It has binaries to train the models and
16+
to download and prepare the data for you. T2T is modular and extensible and can
17+
be used in [notebooks](https://goo.gl/wkHexj) for prototyping your own models
18+
or running existing ones on your data. It is actively used and maintained by
19+
researchers and engineers within
20+
the [Google Brain team](https://research.google.com/teams/brain/) and was used
21+
to develop state-of-the-art models for translation (see
22+
[Attention Is All You Need](https://arxiv.org/abs/1706.03762)), summarization,
23+
image generation and other tasks. You can read
24+
more about T2T in the [Google Research Blog post introducing
1825
it](https://research.googleblog.com/2017/06/accelerating-deep-learning-research.html).
1926

2027
We're eager to collaborate with you on extending T2T, so please feel
@@ -29,8 +36,14 @@ You can chat with us and other users on
2936
[Google Group](https://groups.google.com/forum/#!forum/tensor2tensor) to keep up
3037
with T2T announcements.
3138

32-
Here is a one-command version that installs tensor2tensor, downloads the data,
39+
### Quick Start
40+
41+
[This iPython notebook](https://goo.gl/wkHexj) explains T2T and runs in your
42+
browser using a free VM from Google, no installation needed.
43+
44+
Alternatively, here is a one-command version that installs T2T, downloads data,
3345
trains an English-German translation model, and evaluates it:
46+
3447
```
3548
pip install tensor2tensor && t2t-trainer \
3649
--generate_data \
@@ -53,11 +66,17 @@ t2t-decoder \
5366
--decode_interactive
5467
```
5568

56-
See the [Walkthrough](#walkthrough) below for more details on each step.
69+
See the [Walkthrough](#walkthrough) below for more details on each step
70+
and [Suggested Models](#suggested-models) for well performing models
71+
on common tasks.
5772

5873
### Contents
5974

6075
* [Walkthrough](#walkthrough)
76+
* [Suggested Models](#suggested-models)
77+
* [Translation](#translation)
78+
* [Summarization](#summarization)
79+
* [Image Classification](#image-classification)
6180
* [Installation](#installation)
6281
* [Features](#features)
6382
* [T2T Overview](#t2t-overview)
@@ -132,6 +151,33 @@ cat $DECODE_FILE.$MODEL.$HPARAMS.beam$BEAM_SIZE.alpha$ALPHA.decodes
132151

133152
---
134153

154+
## Suggested Models
155+
156+
Here are some combinations of models, hparams and problems that we found
157+
work well, so we suggest to use them if you're interested in that problem.
158+
159+
### Translation
160+
161+
For translation, esp. English-German and English-French, we suggest to use
162+
the Transformer model in base or big configurations, i.e.
163+
for `--problems=translate_ende_wmt32k` use `--model=transformer` and
164+
`--hparams_set=transformer_base`. When trained on 8 GPUs for 300K steps
165+
this should reach a BLEU score of about 28.
166+
167+
### Summarization
168+
169+
For summarization suggest to use the Transformer model in prepend mode, i.e.
170+
for `--problems=summarize_cnn_dailymail32k` use `--model=transformer` and
171+
`--hparams_set=transformer_prepend`.
172+
173+
### Image Classification
174+
175+
For image classification suggest to use the ResNet or Xception, i.e.
176+
for `--problems=image_imagenet` use `--model=resnet50` and
177+
`--hparams_set=resnet_base` or `--model=xception` and
178+
`--hparams_set=xception_base`.
179+
180+
135181
## Installation
136182

137183
```

docs/cloud_tpu.md

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
Tensor2Tensor supports running on Google Cloud Platforms TPUs, chips specialized
44
for ML training.
55

6-
Not all models are supported but we've tested so far with Transformer (sequence
7-
model) as well as Xception (image model).
6+
Models and hparams that are known to work on TPU:
7+
* `transformer` with `transformer_tpu`
8+
* `xception` with `xception_base`
9+
* `resnet50` with `resnet_base`
810

911
To run on TPUs, you need to be part of the alpha program; if you're not, these
1012
commands won't work for you currently, but access will expand soon, so get
1113
excited for your future ML supercomputers in the cloud.
1214

1315
## Tutorial: Transformer En-De translation on TPU
1416

17+
Update `gcloud`: `gcloud components update`
18+
1519
Set your default zone to a TPU-enabled zone. TPU machines are only available in
1620
certain zones for now.
1721
```
@@ -40,29 +44,32 @@ gcloud alpha compute tpus create \
4044
To see all TPU instances running: `gcloud alpha compute tpus list`. The
4145
`TPU_IP` should be unique amongst the list and follow the format `10.240.i.2`.
4246

43-
Generate data to GCS
44-
If you already have the data locally, use `gsutil cp` to cp to GCS.
47+
SSH in with port forwarding for TensorBoard
4548
```
46-
DATA_DIR=gs://my-bucket/t2t/data/
47-
t2t-datagen --problem=translate_ende_wmt8k --data_dir=$DATA_DIR
49+
gcloud compute ssh $USER-vm -- -L 6006:localhost:6006
4850
```
4951

50-
SSH in with port forwarding for TensorBoard
52+
Now that you're on the cloud instance, install T2T:
5153
```
52-
gcloud compute ssh $USER-vm -L 6006:localhost:6006
54+
pip install tensor2tensor --user
55+
# If your python bin dir isn't already in your path
56+
export PATH=$HOME/.local/bin:$PATH
5357
```
5458

55-
Now that you're on the cloud instance, install T2T:
59+
Generate data to GCS
60+
If you already have the data, use `gsutil cp` to copy to GCS.
5661
```
57-
pip install tensor2tensor
62+
GCS_BUCKET=gs://my-bucket
63+
DATA_DIR=$GCS_BUCKET/t2t/data/
64+
t2t-datagen --problem=translate_ende_wmt8k --data_dir=$DATA_DIR
5865
```
5966

6067
Setup some vars used below. `TPU_IP` and `DATA_DIR` should be the same as what
6168
was used above. Note that the `DATA_DIR` and `OUT_DIR` must be GCS buckets.
6269
```
6370
TPU_IP=<IP of TPU machine>
64-
DATA_DIR=gs://my-bucket/t2t/data/
65-
OUT_DIR=gs://my-bucket/t2t/training/
71+
DATA_DIR=$GCS_BUCKET/t2t/data/
72+
OUT_DIR=$GCS_BUCKET/t2t/training/
6673
TPU_MASTER=grpc://$TPU_IP:8470
6774
```
6875

@@ -73,25 +80,26 @@ tensorboard --logdir=$OUT_DIR > /tmp/tensorboard_logs.txt 2>&1 &
7380

7481
Train and evaluate.
7582
```
76-
t2t-tpu-trainer \
77-
--master=$TPU_MASTER \
78-
--data_dir=$DATA_DIR \
79-
--output_dir=$OUT_DIR \
80-
--problems=translate_ende_wmt8k \
83+
t2t-trainer \
8184
--model=transformer \
82-
--hparams_set=transformer_tiny_tpu \
85+
--hparams_set=transformer_tpu \
86+
--problems=translate_ende_wmt8k \
8387
--train_steps=10 \
8488
--eval_steps=10 \
8589
--local_eval_frequency=10 \
86-
--iterations_per_loop=10
90+
--iterations_per_loop=10 \
91+
--master=$TPU_MASTER \
92+
--use_tpu=True \
93+
--data_dir=$DATA_DIR \
94+
--output_dir=$OUT_DIR
8795
```
8896

8997
The above command will train for 10 steps, then evaluate for 10 steps. You can
9098
(and should) increase the number of total training steps with the
9199
`--train_steps` flag. Evaluation will happen every `--local_eval_frequency`
92100
steps, each time for `--eval_steps`. When you increase then number of training
93101
steps, also increase `--iterations_per_loop`, which controls how frequently the
94-
TPU machine returns control to the Python code (1000 seems like a fine number).
102+
TPU machine returns control to the host machine (1000 seems like a fine number).
95103

96104
Back on your local machine, open your browser and navigate to `localhost:6006`
97105
for TensorBoard.

0 commit comments

Comments
 (0)