Skip to content

Commit 56c3ac7

Browse files
[TF:XLA] Change error type in XLA for uninitialized ResourceVariable.
This is to match TensorFlow Classic's implementation and matches the actual error condition more closely. PiperOrigin-RevId: 231250467
1 parent 819e55e commit 56c3ac7

File tree

3 files changed

+3
-4
lines changed

3 files changed

+3
-4
lines changed

tensorflow/compiler/tests/variable_ops_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ def testSliceAssign(self):
485485
checker2[None] = [6] # new axis
486486

487487
def testUninitialized(self):
488-
with self.assertRaisesRegexp(errors.InvalidArgumentError,
488+
with self.assertRaisesRegexp(errors.FailedPreconditionError,
489489
"uninitialized variable"):
490490
with self.test_session() as sess, self.test_scope():
491491
v = resource_variable_ops.ResourceVariable([1, 2])

tensorflow/compiler/tf2xla/xla_op_kernel.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ Status ReadVariableInputTensor(const Tensor& tensor, DataType type,
354354
TF_RET_CHECK(variable != nullptr);
355355
TF_RET_CHECK(variable->kind() == XlaResource::kVariable);
356356
if (!variable->initialized()) {
357-
return errors::InvalidArgument("Read of uninitialized variable ",
358-
variable->name());
357+
return errors::FailedPrecondition("Read of uninitialized variable ",
358+
variable->name());
359359
}
360360
if (variable->type() != type) {
361361
return errors::InvalidArgument(

tensorflow/python/kernel_tests/resource_variable_ops_test.py

-1
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,6 @@ def testAssignSubMethod(self):
745745

746746
@test_util.run_in_graph_and_eager_modes
747747
@test_util.run_v1_only("b/120545219")
748-
@test_util.disable_xla("This test never passed for XLA")
749748
def testDestroyResource(self):
750749
v = resource_variable_ops.ResourceVariable(3.0, name="var0")
751750
self.evaluate(variables.global_variables_initializer())

0 commit comments

Comments
 (0)