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
7a69f962
Commit
7a69f962
authored
Dec 17, 2019
by
Chris Jones
Committed by
A. Unique TensorFlower
Dec 17, 2019
Browse files
Internal change
PiperOrigin-RevId: 285974579
parent
a19f2f8b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
+9
-7
official/transformer/v2/translate.py
official/transformer/v2/translate.py
+9
-7
No files found.
official/transformer/v2/translate.py
View file @
7a69f962
...
@@ -21,7 +21,6 @@ from __future__ import print_function
...
@@ -21,7 +21,6 @@ from __future__ import print_function
import
numpy
as
np
import
numpy
as
np
import
tensorflow
as
tf
import
tensorflow
as
tf
from
tensorflow.python.distribute
import
values
from
official.transformer.utils
import
tokenizer
from
official.transformer.utils
import
tokenizer
_EXTRA_DECODE_LENGTH
=
100
_EXTRA_DECODE_LENGTH
=
100
...
@@ -144,12 +143,15 @@ def translate_file(model,
...
@@ -144,12 +143,15 @@ def translate_file(model,
text
=
np
.
reshape
(
text
,
[
num_replicas
,
local_batch_size
,
-
1
])
text
=
np
.
reshape
(
text
,
[
num_replicas
,
local_batch_size
,
-
1
])
# Add tag to the input of each replica with the reordering logic after
# Add tag to the input of each replica with the reordering logic after
# outputs, to ensure the output order matches the input order.
# outputs, to ensure the output order matches the input order.
text
=
[
text
=
tf
.
constant
(
text
)
[
tf
.
convert_to_tensor
(
tag
),
tf
.
convert_to_tensor
(
per_replica_text
)]
for
tag
,
per_replica_text
in
enumerate
(
text
)
@
tf
.
function
]
def
text_as_per_replica
():
# pylint: disable=protected-access
replica_context
=
tf
.
distribute
.
get_replica_context
()
text
=
values
.
PerReplica
(
distribution_strategy
.
extended
.
_device_map
,
text
)
replica_id
=
replica_context
.
replica_id_in_sync_group
return
replica_id
,
text
[
replica_id
]
text
=
distribution_strategy
.
experimental_run_v2
(
text_as_per_replica
)
outputs
=
distribution_strategy
.
experimental_local_results
(
outputs
=
distribution_strategy
.
experimental_local_results
(
predict_step
(
text
))
predict_step
(
text
))
tags
,
unordered_val_outputs
=
outputs
[
0
]
tags
,
unordered_val_outputs
=
outputs
[
0
]
...
...
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