"doc/git@developer.sourcefind.cn:OpenDAS/ktransformers.git" did not exist on "e961adde15541137d17cd8f14661fe824f0d8908"
Commit 7a69f962 authored by Chris Jones's avatar Chris Jones Committed by A. Unique TensorFlower
Browse files

Internal change

PiperOrigin-RevId: 285974579
parent a19f2f8b
...@@ -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]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment