Skip to content

tf.while_loop condition with tuple indexing x[(0,0)] fails in eager but works under XLA [Recent/Qwen] #125538

Closed

Description

@MRiffiAslett

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

No

Source

source

TensorFlow version

2.20.0-dev0 (self-built, 20250806 snapshot)

Custom code

Yes

OS platform and distribution

Ubuntu 24.04.4 LTS (x86_64)

Mobile device

No response

Python version

3.12.3

Bazel version

Not recoverable from available build logs for this self-built wheel.

GCC/compiler version

gcc 13.3.0

CUDA/cuDNN version

CPU-only environment

GPU model and memory

CPU-only environment

Current behavior?

A tf.while_loop condition indexes its loop variable with x[(0, 0)], valid 2D indexing into a (1, 1) tensor. In eager, this raises IndexError claiming the tensor only has 1 dimension. Under jit_compile=True and under autoclustering, the same code runs fine and both agree on the result.

Standalone code to reproduce the issue

import tensorflow as tf

x = tf.constant([[-2.0]], shape=[1, 1])

def compute(x):
    condition = lambda x: tf.cast(x[(0, 0)], tf.bool)
    body = lambda x: tf.nn.relu(x)
    return tf.while_loop(condition, body, [x])

print("eager:")
try:
    print(compute(x))
except Exception as e:
    print("FAILED:", str(e)[:200])

print("jit_compile=True:", tf.function(compute, jit_compile=True)(x))

Relevant log output

eager:
FAILED: Index out of range using input dim 1; input has only 1 dims [Op:StridedSlice]

jit_compile=True: [<tf.Tensor: shape=(1, 1), dtype=float32, numpy=array([[0.]], dtype=float32)>]

Activity

  1. added
    2.20.0
    on Aug 20, 2026
  2. Kayyuri commented on Aug 20, 2026

    @Kayyuri

    Hi @MRiffiAslett, Thank you for reporting this issue!
    A PR has been submitted to fix this issue, and it will be resolved once merged.

    Thank you to @AnupamKumar-1 for working on the fix contributions.

  3. google-ml-butler commented on Aug 31, 2026

    @google-ml-butler

    Are you satisfied with the resolution of your issue?
    Yes
    No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

2.20.0awaiting PR mergecomp:xlatype:bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions