Skip to content

fix(array_ops): align eager and compiled graph behavior for single tensor tf.stack - #125381

Open
SparshGarg999 wants to merge 2 commits into
tensorflow:masterfrom
SparshGarg999:fix-tf-stack-single-tensor
Open

fix(array_ops): align eager and compiled graph behavior for single tensor tf.stack#125381
SparshGarg999 wants to merge 2 commits into
tensorflow:masterfrom
SparshGarg999:fix-tf-stack-single-tensor

Conversation

@SparshGarg999

Copy link
Copy Markdown
Contributor

Fixes #125374

Description

Calling tf.stack with a single bare Tensor (rather than a list or tuple of tensors) currently behaves inconsistently across execution modes. Under eager execution, tf.stack silently returns the single Tensor unstacked, whereas under jit_compile=True or autoclustering, it raises a TypeError from the underlying Pack op.

Fix

Updated tf.stack in tensorflow/python/ops/array_ops_stack.py to check if values is an instance of Tensor or CompositeTensor and normalize it into a list [values] prior to graph/op construction, ensuring consistent stacking behavior across both eager and compiled graph execution paths.

@google-ml-butler google-ml-butler Bot added the size:XS CL Change Size: Extra Small label Aug 15, 2026
@google-ml-butler
google-ml-butler Bot requested a review from cantonios August 15, 2026 02:39
@google-ml-butler google-ml-butler Bot added the awaiting review Pull request awaiting review label Aug 15, 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 modifies tensorflow/python/ops/array_ops_stack.py to wrap a single Tensor or CompositeTensor in a list when passed to tf.stack. The reviewer noted that the type check using isinstance does not account for tf.Variable objects (such as ResourceVariable), which are common tensor-like objects. They suggested using ops.is_tensor(values) instead to ensure robust handling of both Tensor and Variable objects.

Comment thread tensorflow/python/ops/array_ops_stack.py Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review Pull request awaiting review size:XS CL Change Size: Extra Small

Projects

None yet

2 participants