Skip to content

tf2xla: Incompatible shapes: [4] vs. [8] under jit_compile=True (eager succeeds) #122052

Closed

Description

@jasminetrail

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

No

Source

source

TensorFlow version

tf 2.21.0

Custom code

Yes

OS platform and distribution

Linux, 22.04.1-Ubuntu

Mobile device

No response

Python version

3.10.12

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

A graph mixing tf.experimental.numpy.hstack / broadcasting ops compiles and runs in eager but fails XLA compilation with Incompatible shapes: [4] vs. [8]. The eager/XLA shape inference disagree.

Standalone code to reproduce the issue

import tensorflow as tf
tf.random.set_seed(1699)
t4400 = tf.complex(tf.random.normal([8], dtype=tf.float32), tf.random.normal([8], dtype=tf.float32))

def model_1699(t4400):
    t4403 = tf.experimental.numpy.hstack((5, 5, 5, 5))
    t4401 = tf.experimental.numpy.logical_xor(t4400, t4400)
    t4410 = tf.experimental.numpy.allclose(t4403, t4401, atol=-2.92515058314041)
    return t4410

_args = (t4400,)

# --- minimal driver: eager then XLA jit_compile ---
eager_out = model_1699(*_args)
xla_out = tf.function(model_1699, jit_compile=True)(*_args)
print('OK', eager_out.shape, xla_out.shape)

Relevant log output

Traceback (most recent call last):
  File "/home/bug_reports/_repros/repro_690dce2f.py", line 15, in <module>
    xla_out = tf.function(model_1699, jit_compile=True)(*_args)
  File "/home/.venv/lib/python3.10/site-packages/tensorflow/python/util/traceback_utils.py", line 167, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/home/.venv/lib/python3.10/site-packages/tensorflow/python/eager/execute.py", line 53, in quick_execute
    tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [4] vs. [8]
	 [[{{node Equal_1}}]]
	tf2xla conversion failed while converting __inference_model_1699_169[_XlaMustCompile=true,config_proto=13561319589895757934,executor_type=11160318154034397263]. Run with TF_DUMP_GRAPH_PREFIX=/path/to/dump/dir and --vmodule=xla_compiler=2 to obtain a dump of the compiled functions. [Op:__inference_model_1699_169]

Activity

  1. added
    2.21.0
    on Jun 26, 2026
  2. furk4neg3 commented on Jul 4, 2026

    @furk4neg3
    Contributor

    I can take a look at this issue.

    From my initial investigation, the failure seems to happen because tf.experimental.numpy.allclose eventually builds an equality comparison for inputs with statically known non-broadcastable shapes. In eager/non-XLA execution, Tensor equality handles this case by returning a scalar False, but under jit_compile=True the incompatible Equal op reaches XLA and fails during compilation.

    I’m planning to try a narrow fix in tf.experimental.numpy.allclose: when both input shapes are statically known and non-broadcastable, avoid constructing the incompatible equality op and return scalar False for the existing non-inexact comparison path. I’ll also add a focused XLA regression test for the reported case.

    I’ll keep the change scoped to allclose and avoid changing general Tensor equality or XLA lowering behavior unless maintainers think that would be the better direction.

  3. furk4neg3 commented on Jul 4, 2026

    @furk4neg3
    Contributor

    I opened a PR with a narrow fix for this: #122605

    The change keeps the fix scoped to tf.experimental.numpy.allclose by avoiding construction of the incompatible equality op when the input shapes are statically known to be non-broadcastable in the non-inexact comparison path. I also added an XLA regression test for the reported case.

  4. removed
    awaiting PR merge
    on Sep 25, 2026
  5. Venkat6871 commented on Sep 30, 2026

    @Venkat6871
    Contributor

    Hi @jasminetrail,
    Apologies for the delay. This issue has been fixed on master and the fix is included in v2.22.0-rc0 and tf-nightly.

    In TensorFlow 2.21.0, tf.experimental.numpy.isclose could behave differently between eager execution and tf.function(jit_compile=True) for non-broadcastable shapes [4] and [8]: eager execution returned False, while XLA raised an InvalidArgumentError.

    The fix from PR #122605 (landed in commit 35fd349) and the follow-up PR #123867 (commit 09a3302) updated tf.experimental.numpy.isclose and added regression coverage for this case.

    I also verified the original reproducer with v2.22.0-rc0 and tf-nightly, where the incompatible shapes now consistently raise a shape-mismatch error. I’ve included the verification results in this gist for your reference.

    Could you please verify this on your side as well and let us know if you still see the issue?
    Thank you!

  6. added
    stat:awaiting response
    on Sep 30, 2026
  7. github-actions commented on Oct 8, 2026

    @github-actions

    This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you.

  8. added
    stale
    on Oct 8, 2026
  9. github-actions commented on Oct 16, 2026

    @github-actions

    This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further.

  10. google-ml-butler commented on Oct 16, 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.21.0comp:xlastalestat:awaiting responsetype:bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions