Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Colab TPU support with Colab Notebook and modified repo #47

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
7b5ca13
Update run_classifier for Colab Notebook
aditya-malte Jun 24, 2019
c6940a0
Update README.md
aditya-malte Jun 24, 2019
2c99d47
Update README.md
aditya-malte Jun 24, 2019
1b611c7
Created using Colaboratory
aditya-malte Jun 24, 2019
1148285
Delete End_To_End_Finetuning_of_XLNet_Using_TPU.ipynb
aditya-malte Jun 24, 2019
8cf416a
Created using Colaboratory
aditya-malte Jun 24, 2019
6fff1c4
Update README.md
aditya-malte Jun 24, 2019
aa4fca0
Update README.md
aditya-malte Jun 24, 2019
eb281a5
Update README.md
aditya-malte Jun 24, 2019
6dff4dd
Update README.md
aditya-malte Jun 24, 2019
e39d69c
Delete End_To_End_Finetuning_of_XLNet_Using_TPU.ipynb
aditya-malte Jun 24, 2019
b4dbbd1
Created using Colaboratory
aditya-malte Jun 24, 2019
6d29c2b
Created using Colaboratory
aditya-malte Jun 24, 2019
cf2e34b
Update Colab_XLNet_FineTuning.ipynb
aditya-malte Jun 24, 2019
153ec6e
Update Colab_XLNet_FineTuning.ipynb
aditya-malte Jun 24, 2019
9dd3cec
Solved MODEL_DIR, OUTPUT_DIR glitch
aditya-malte Jun 24, 2019
8846486
final working version
aditya-malte Jun 24, 2019
12ce751
Update README.md
aditya-malte Jun 27, 2019
17331a4
Update run_classifier.py
aditya-malte Jun 27, 2019
c5a4f67
Update README.md
aditya-malte Jul 2, 2019
c0f03ce
Update run_classifier.py
aditya-malte Jul 2, 2019
b2d565e
Update run_classifier.py
aditya-malte Jul 2, 2019
4ae4e67
Update model_utils.py
aditya-malte Jul 2, 2019
2162652
Created using Colaboratory
aditya-malte Jul 2, 2019
d68f71a
Update run_classifier.py
aditya-malte Jul 2, 2019
02a2d12
Created using Colaboratory
aditya-malte Jul 2, 2019
d4021b8
Created using Colaboratory
aditya-malte Jul 2, 2019
ad5589f
Created using Colaboratory
aditya-malte Jul 2, 2019
6152808
Created using Colaboratory
aditya-malte Jul 2, 2019
63498aa
Created using Colaboratory
aditya-malte Jul 2, 2019
303a5a0
Changed "my_bert_5" to "YOUR_BUCKET_NAME"
aditya-malte Jul 2, 2019
3af75af
Created using Colaboratory
aditya-malte Jul 2, 2019
9d8a93f
Update Colab_XLNet_FineTuning.ipynb
aditya-malte Jul 2, 2019
f9e5722
Created using Colaboratory
aditya-malte Jul 2, 2019
55b4348
Created using Colaboratory
aditya-malte Jul 2, 2019
fe7f6aa
Created using Colaboratory
aditya-malte Jul 2, 2019
c2755f3
Created using Colaboratory
aditya-malte Jul 2, 2019
20527b3
Minor Update
aditya-malte Jul 3, 2019
0989600
Merge pull request #1 from zihangdai/master
aditya-malte Jul 7, 2019
56bf1df
Created using Colaboratory
aditya-malte Jul 7, 2019
eb70138
Rename Colab_XLNet_FineTuning.ipynb to colab_imdb_tpu
aditya-malte Jul 7, 2019
cb3bd8f
Delete Colab_XLNet_FineTuning.ipynb
aditya-malte Jul 7, 2019
7be4590
Rename colab_imdb_tpu to colab_imdb_tpu.ipynb
aditya-malte Jul 7, 2019
f84f08c
Update run_classifier.py
aditya-malte Jul 7, 2019
ade6ab7
Update run_classifier.py
aditya-malte Jul 7, 2019
58b930f
Update run_classifier.py
aditya-malte Jul 7, 2019
6efef37
Update README.md
aditya-malte Jul 7, 2019
6485463
Fixed colab link
aditya-malte Jul 14, 2019
e73f0bd
Update
aditya-malte Jul 14, 2019
c5b0d01
Update README.md
aditya-malte Jul 17, 2019
659b7e0
Sync readme with original
aditya-malte Jul 20, 2019
6f86c65
Merge pull request #2 from zihangdai/master
aditya-malte Jul 20, 2019
14bf36a
Update train.py
cedspam Oct 22, 2019
2bd42dd
Merge pull request #6 from cedspam/patch-1
aditya-malte Feb 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,10 @@ To run the code:
- The SOTA performance (accuracy 81.75) of RACE is produced using XLNet-Large with sequence length 512 and batch size 32, which requires a large TPU v3-32 in the pod setting. Please refer to the script `script/tpu_race_large_bsz32.sh` for this setting.
- Using XLNet-Large with sequence length 512 and batch size 8 on a TPU v3-8 can give you an accuracy of around 80.3 (see `script/tpu_race_large_bsz8.sh`).

### Using Google Colab
### Using Google Colab(TPU/GPU)

[An example](notebooks/colab_imdb_gpu.ipynb) of using Google Colab with GPUs has been provided. Note that since the hardware is constrained in the example, the results are worse than the best we can get. It mainly serves as an example and should be modified accordingly to maximize performance.
[An example](notebooks/colab_imdb_tpu.ipynb) of using Google Colab with TPUs has also been provided. The TPU's higher memory capacity allows us to achieve better perfomance.


## Custom Usage of XLNet
Expand Down
16 changes: 16 additions & 0 deletions model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def configure_tpu(FLAGS):
strategy.num_replicas_in_sync)

per_host_input = tf.contrib.tpu.InputPipelineConfig.PER_HOST_V2


run_config = tf.contrib.tpu.RunConfig(
master=master,
model_dir=FLAGS.model_dir,
Expand All @@ -54,6 +56,20 @@ def configure_tpu(FLAGS):
save_checkpoints_steps=FLAGS.save_steps,
train_distribute=strategy
)

if FLAGS.use_colab_tpu:
tpu_cluster_resolver = tf.contrib.cluster_resolver.TPUClusterResolver(FLAGS.tpu_address)
is_per_host = tf.contrib.tpu.InputPipelineConfig.PER_HOST_V2
run_config = tf.contrib.tpu.RunConfig(
cluster=tpu_cluster_resolver,
model_dir=FLAGS.output_dir,
save_checkpoints_steps=FLAGS.save_steps,
keep_checkpoint_max=FLAGS.max_save,
tpu_config=tf.contrib.tpu.TPUConfig(
iterations_per_loop=FLAGS.iterations,
num_shards=8,
per_host_input_for_training=is_per_host))

return run_config


Expand Down
Loading