Skip to content

Commit 4f50e2f

Browse files
crccwtensorflower-gardener
authored andcommitted
Workaround a known issue with control dependency on external tensors
This fix tensorflow_models/official/nlp/bert/run_pretraining failure with explicit allreduce. PiperOrigin-RevId: 338521478
1 parent 2b436a1 commit 4f50e2f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

official/nlp/optimization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def _resource_apply_dense(self, grad, var, apply_state=None):
199199
# backward pass.
200200
# TODO(b/171088214): Remove it after the control dependency in
201201
# nested function is fixed.
202-
with tf.control_dependencies([grad]):
202+
with tf.control_dependencies([tf.identity(grad)]):
203203
lr_t, kwargs = self._get_lr(var.device, var.dtype.base_dtype, apply_state)
204204
decay = self._decay_weights_op(var, lr_t, apply_state)
205205
with tf.control_dependencies([decay]):
@@ -212,7 +212,7 @@ def _resource_apply_sparse(self, grad, var, indices, apply_state=None):
212212
# backward pass.
213213
# TODO(b/171088214): Remove it after the control dependency in
214214
# nested function is fixed.
215-
with tf.control_dependencies([grad]):
215+
with tf.control_dependencies([tf.identity(grad)]):
216216
lr_t, kwargs = self._get_lr(var.device, var.dtype.base_dtype, apply_state)
217217
decay = self._decay_weights_op(var, lr_t, apply_state)
218218
with tf.control_dependencies([decay]):

0 commit comments

Comments
 (0)