Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
376e65a6
"EDK2/git@developer.sourcefind.cn:dadigang/Ventoy.git" did not exist on "a5c706511b84eb0f9e5f042f18f2f3c9602977c4"
Commit
376e65a6
authored
Oct 13, 2019
by
Timothy Liu
Browse files
Added automatic mixed precision and XLA options to run_tf_glue.py
parent
86f23a19
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
2 deletions
+10
-2
examples/run_tf_glue.py
examples/run_tf_glue.py
+10
-2
No files found.
examples/run_tf_glue.py
View file @
376e65a6
...
...
@@ -6,6 +6,11 @@ from transformers import BertTokenizer, TFBertForSequenceClassification, glue_co
# script parameters
BATCH_SIZE
=
32
EVAL_BATCH_SIZE
=
BATCH_SIZE
*
2
USE_XLA
=
False
USE_AMP
=
False
tf
.
config
.
optimizer
.
set_jit
(
USE_XLA
)
tf
.
config
.
optimizer
.
set_experimental_options
({
"auto_mixed_precision"
:
USE_AMP
})
# Load tokenizer and model from pretrained model/vocabulary
tokenizer
=
BertTokenizer
.
from_pretrained
(
'bert-base-cased'
)
...
...
@@ -23,10 +28,13 @@ train_dataset = train_dataset.shuffle(128).batch(BATCH_SIZE).repeat(-1)
valid_dataset
=
valid_dataset
.
batch
(
EVAL_BATCH_SIZE
)
# Prepare training: Compile tf.keras model with optimizer, loss and learning rate schedule
optimizer
=
tf
.
keras
.
optimizers
.
Adam
(
learning_rate
=
3e-5
,
epsilon
=
1e-08
)
opt
=
tf
.
keras
.
optimizers
.
Adam
(
learning_rate
=
3e-5
,
epsilon
=
1e-08
)
if
USE_AMP
:
# loss scaling is currently required when using mixed precision
opt
=
tf
.
keras
.
mixed_precision
.
experimental
.
LossScaleOptimizer
(
opt
,
'dynamic'
)
loss
=
tf
.
keras
.
losses
.
SparseCategoricalCrossentropy
(
from_logits
=
True
)
metric
=
tf
.
keras
.
metrics
.
SparseCategoricalAccuracy
(
'accuracy'
)
model
.
compile
(
optimizer
=
opt
imizer
,
loss
=
loss
,
metrics
=
[
metric
])
model
.
compile
(
optimizer
=
opt
,
loss
=
loss
,
metrics
=
[
metric
])
# Train and evaluate using tf.keras.Model.fit()
train_steps
=
train_examples
//
BATCH_SIZE
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment