Skip to content

Commit

Permalink
Fix undefined behavior in tf.raw_ops.Switch in eager mode.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 332578058
Change-Id: I9727571d2f21476b10d8aa27c1b7176564b76ac9
  • Loading branch information
mihaimaruseac committed Sep 20, 2020
1 parent d8c69c2 commit 92d5b97
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tensorflow/core/common_runtime/eager/kernel_and_device.cc
Expand Up @@ -307,7 +307,12 @@ Status KernelAndDeviceOp::Run(
if (outputs != nullptr) {
outputs->clear();
for (int i = 0; i < context.num_outputs(); ++i) {
outputs->push_back(Tensor(*context.mutable_output(i)));
const auto* output_tensor = context.mutable_output(i);
if (output_tensor != nullptr) {
outputs->push_back(Tensor(*output_tensor));
} else {
outputs->push_back(Tensor());
}
}
}
return Status::OK();
Expand Down
8 changes: 8 additions & 0 deletions tensorflow/python/kernel_tests/control_flow_ops_py_test.py
Expand Up @@ -4581,6 +4581,14 @@ def testUInt64SwitchMerge(self):
result = control_flow_ops.merge([v_f, v_t])
self.evaluate(result)

def testSwitchEagerMode(self):
if not context.executing_eagerly():
return
input_data = [1, 2, 3, 4]
vf, vt = control_flow_ops.switch(input_data, False)
self.assertAllEqual(vf, input_data)
self.assertAllEqual(vt, [])

@test_util.run_deprecated_v1
def testQIntArgAndRet(self):

Expand Down

0 comments on commit 92d5b97

Please sign in to comment.