Repository navigation
Fix tf.tuple() to reject nested structures consistently - #124931
copybara-service[bot] merged 1 commit into
Conversation
|
Note Gemini is unable to generate a review for this pull request due to the file types involved not being currently supported. |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
745dc73 to
86277c2
Compare
86277c2 to
6d79433
Compare
dmiltr3
left a comment
There was a problem hiding this comment.
Code Review Feedback
1. Missing Test Class Declaration and Indentation in tensorflow/python/ops/control_flow_ops_test.py
In control_flow_ops_test.py, the new test methods are added directly after WithDependenciesTestCase.testListDependencies without a class declaration (class TupleTestCase(test_util.TensorFlowTestCase): or class TupleTest), causing the tests to be appended to WithDependenciesTestCase with 4-space indentation rather than in their own test class with the standard 2-space indentation.
Please define a dedicated test class TupleTestCase (or TupleTest) using 2-space indentation.
2. Remove Unused Variable in testNestedListRaisesTypeError
In testNestedListRaisesTypeError, c = constant_op.constant(3.0) is defined but not used in the test assertion.
3. Recommended Test Suite Structure
Here is the updated test case implementation verifying nested structures as well as valid flat sequences:
class TupleTestCase(test_util.TensorFlowTestCase):
@test_util.run_in_graph_and_eager_modes
def testNestedTupleRaisesTypeError(self):
a = constant_op.constant(1.0)
b = constant_op.constant(2.0)
c = constant_op.constant(3.0)
with self.assertRaises(TypeError):
control_flow_ops.tuple(((a, b), c))
@test_util.run_in_graph_and_eager_modes
def testNestedListRaisesTypeError(self):
a = constant_op.constant(1.0)
b = constant_op.constant(2.0)
with self.assertRaises(TypeError):
control_flow_ops.tuple([[a, b]])
@test_util.run_in_graph_and_eager_modes
def testDictElementRaisesTypeError(self):
a = constant_op.constant(1.0)
b = constant_op.constant(2.0)
with self.assertRaises(TypeError):
control_flow_ops.tuple([{"x": a}, b])
@test_util.run_in_graph_and_eager_modes
def testFlatSequenceSucceeds(self):
a = constant_op.constant(1.0)
b = constant_op.constant(2.0)
res = control_flow_ops.tuple([a, b])
self.assertLen(res, 2)6d79433 to
fa75856
Compare
|
@dmiltr3 Addressed all three points:
Verified: 4/4 tests pass. |
6eb8b68
into
tensorflow:master
Fixes #124879
tf.tuple() only supports a flat list of tensors (per its docstring), but
eager mode skips validation entirely while graph/XLA mode implicitly stacks
nested elements via convert_to_tensor, causing a confusing Pack shape error.
Both eager and graph modes now raise the same clear TypeError for nested input
via a nest.is_nested() check applied before the eager/graph branch. Flat-list
(documented) usage is unaffected.
Added TupleTest in control_flow_ops_test.py covering nested tuple, nested list,
and dict-element cases in both eager and graph mode.