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
ModelZoo
ResNet50_tensorflow
Commits
02cc984e
Commit
02cc984e
authored
Nov 05, 2019
by
A. Unique TensorFlower
Browse files
Internal change
PiperOrigin-RevId: 278754959
parent
0203278a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
2 deletions
+14
-2
official/staging/shakespeare/shakespeare_main.py
official/staging/shakespeare/shakespeare_main.py
+14
-2
No files found.
official/staging/shakespeare/shakespeare_main.py
View file @
02cc984e
...
...
@@ -57,7 +57,8 @@ def define_flags():
intra_op
=
False
,
synthetic_data
=
False
,
max_train_steps
=
False
,
dtype
=
False
,
dtype
=
True
,
loss_scale
=
True
,
enable_xla
=
True
,
force_v2_in_keras_compile
=
True
)
...
...
@@ -156,7 +157,8 @@ def build_model(vocab_size,
return_sequences
=
True
,
stateful
=
stateful
,
recurrent_initializer
=
'glorot_uniform'
),
tf
.
keras
.
layers
.
Dense
(
vocab_size
,
activation
=
'softmax'
)])
tf
.
keras
.
layers
.
Dense
(
vocab_size
),
tf
.
keras
.
layers
.
Softmax
(
dtype
=
tf
.
float32
)])
def
train_model
(
flags_obj
,
dataset
,
vocab_size
,
strategy
,
checkpoint_dir
=
None
):
...
...
@@ -178,6 +180,9 @@ def train_model(flags_obj, dataset, vocab_size, strategy, checkpoint_dir=None):
with
strategy_scope
:
model
=
build_model
(
vocab_size
=
vocab_size
,
batch_size
=
flags_obj
.
batch_size
,
use_cudnn
=
flags_obj
.
cudnn
)
# When keras_use_ctl is False, Model.fit() automatically applies
# loss scaling so we don't need to create a LossScaleOptimizer.
model
.
compile
(
optimizer
=
tf
.
keras
.
optimizers
.
Adam
(),
loss
=
tf
.
keras
.
losses
.
CategoricalCrossentropy
(),
...
...
@@ -260,6 +265,13 @@ def run(flags_obj):
'https://storage.googleapis.com/download.tensorflow.org/data/'
'shakespeare.txt'
)
if
flags_obj
.
dtype
==
'fp16'
:
policy
=
tf
.
keras
.
mixed_precision
.
experimental
.
Policy
(
'mixed_float16'
,
loss_scale
=
flags_core
.
get_loss_scale
(
flags_obj
,
default_for_fp16
=
'dynamic'
))
tf
.
keras
.
mixed_precision
.
experimental
.
set_policy
(
policy
)
keras_utils
.
set_session_config
(
enable_eager
=
flags_obj
.
enable_eager
,
enable_xla
=
flags_obj
.
enable_xla
)
...
...
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