Skip to content

tf.reshape with two -1 dimensions is correctly rejected by eager and jit_compile=True, but autoclustering silently returns a result instead of raising [Recent/StarCoder] #124877

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

No response

GCC/compiler version

gcc 13.3.0

CUDA/cuDNN version

N/A, CPU-only environment

GPU model and memory

N/A, CPU-only environment

Current behavior?

tf.reshape only allows one component of shape to be -1. Calling tf.reshape(x, [-1, -1]) on a (4, 12) input correctly raises in both eager execution and explicit jit_compile=True:

InvalidArgumentError: Only one input size may be -1, not both 0 and 1 [Op:Reshape]

(eager), and the equivalent tf2xla conversion failed error during compilation (jit_compile=True).

Under TF_XLA_FLAGS=--tf_xla_auto_jit=2 (autoclustering), no error is raised — the same call returns a (48, 1) tensor of computed values instead of failing.

I haven't traced why autoclustering's shape-inference path accepts input that both eager and the explicit XLA path reject — flagging the observed divergence, not the exact mechanism.

Standalone code to reproduce the issue

import tensorflow as tf

print("tf:", tf.__version__)

x1 = tf.constant([[4.0, 5.0, 6.0, 7.0]] * 12, shape=[4, 12])

def compute(x1):
    x2 = tf.reshape(x1, [-1, -1])  # invalid: reshape allows at most one -1
    x3 = tf.transpose(x2, [-1, 0])
    x4 = tf.reshape(x3, [-1, 1])
    return tf.add(x4, 1)

print("--- naive (eager) ---")
try:
    print(compute(x1).numpy())
except Exception as e:
    print("FAILED:", str(e)[:200])

print("--- xla (jit_compile=True) ---")
try:
    print(tf.function(compute, jit_compile=True)(x1).numpy())
except Exception as e:
    print("FAILED:", str(e)[:200])

print("--- autocluster (run with TF_XLA_FLAGS=--tf_xla_auto_jit=2) ---")
try:
    print(tf.function(compute)(x1).numpy())
except Exception as e:
    print("FAILED:", str(e)[:200])

Relevant log output

tf: 2.20.0-dev0+selfbuilt

--- naive (eager) ---
FAILED: Only one input size may be -1, not both 0 and 1 [Op:Reshape]

--- xla (jit_compile=True) ---
FAILED: only one input size may be -1, not both 0 and 1

--- autocluster (TF_XLA_FLAGS=--tf_xla_auto_jit=2) ---
[[5.]
 [5.]
 [5.]
 [5.]
 [6.]
 [6.]
 [6.]
 [6.]
 [7.]
 [7.]
 [7.]
 [7.]
 [8.]
 [8.]
 [8.]
 [8.]
 [5.]
 [5.]
 [5.]
 [5.]
 [6.]
 [6.]
 [6.]
 [6.]
 [7.]
 [7.]
 [7.]
 [7.]
 [8.]
 [8.]
 [8.]
 [8.]
 [5.]
 [5.]
 [5.]
 [5.]
 [6.]
 [6.]
 [6.]
 [6.]
 [7.]
 [7.]
 [7.]
 [7.]
 [8.]
 [8.]
 [8.]
 [8.]]

Activity

  1. added
    2.20.0
    on Aug 10, 2026
  2. google-ml-butler commented on Aug 13, 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.0comp:xlatype:bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions