Skip to content

Fix tf.tuple() AttributeError for tf.Variable inputs under tf.function - #125420

Merged
copybara-service[bot] merged 1 commit into
tensorflow:masterfrom
AnupamKumar-1:fix-tuple-repeated-variable-125397
Aug 21, 2026
Merged

copybara-service[bot] merged 1 commit into
tensorflow:masterfrom
AnupamKumar-1:fix-tuple-repeated-variable-125397

Conversation

@AnupamKumar-1

Copy link
Copy Markdown
Contributor

Fixes #125397

tuple() skipped ops.convert_to_tensor() for tf.Variable inputs because
tensor_util.is_tf_type() treated them as already graph-safe, leaving
the raw eager handle uncaptured. Calling .op on it then raised
"Tensor.op is undefined when eager execution is enabled" under
tf.function/jit_compile.

Fix: only skip conversion for real Tensor/IndexedSlices instances, so
Variables always go through convert_to_tensor().

Added testRepeatedVariableUnderTFFunction to TupleTestCase covering
the issue's repro.

@google-ml-butler google-ml-butler Bot added the size:S CL Change Size: Small label Aug 16, 2026
@google-ml-butler
google-ml-butler Bot requested a review from cantonios August 16, 2026 19:08
@google-ml-butler google-ml-butler Bot added the awaiting review Pull request awaiting review label Aug 16, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates 'control_flow_ops.tuple' to explicitly check for 'Tensor' and 'IndexedSlices' instances instead of using 'tensor_util.is_tf_type', and adds a test case to verify repeated variables under 'tf.function'. The review feedback recommends simplifying the new test by returning the tuple directly instead of using 'array_ops.identity' on a list of tensors, which is non-idiomatic and error-prone.

@github-project-automation github-project-automation Bot moved this from Assigned Reviewer to Approved by Reviewer in PR Queue Aug 17, 2026
@google-ml-butler google-ml-butler Bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Aug 17, 2026
@nithyak0204 nithyak0204 added ready to pull PR ready for merge process and removed ready to pull PR ready for merge process awaiting review Pull request awaiting review labels Aug 18, 2026
@AnupamKumar-1

Copy link
Copy Markdown
Contributor Author

Hi @nithyak0204 , just wanted to check if there’s anything pending for the merge. All checks seem to be passing.

@nithyak0204

Copy link
Copy Markdown

Hi @AnupamKumar-1, This PR is waiting for internal approvals. We are working on it. Thank you!

@copybara-service
copybara-service Bot merged commit a78d19e into tensorflow:master Aug 21, 2026
20 checks passed
@github-project-automation github-project-automation Bot moved this from Approved by Reviewer to Merged in PR Queue Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:ops OPs related issues kokoro:force-run Tests on submitted change prtype:bugfix PR to fix a bug ready to pull PR ready for merge process size:S CL Change Size: Small

Projects

Status: Merged

4 participants