tensorflow / tensorflow/tensorflow
Nondeterministic behavior with tf.concat on zipped tensors: Eager sometimes works, sometimes fails with InvalidArgumentError
@Venkat6871 is already working on this.
Since Nov 26, 2025.
- Dominant language
- C++
- Stars
- 200k
- Forks
- 76.9k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 433
Description
Issue type
Bug
Have you reproduced the bug with TensorFlow Nightly?
Yes
Source
binary
TensorFlow version
2.20.0
Custom code
Yes
OS platform and distribution
linux ubuntu 24.04
Mobile device
No response
Python version
3.9
Bazel version
No response
GCC/compiler version
No response
CUDA/cuDNN version
CUDA Version 13.0
GPU model and memory
No response
Current behavior?
I encountered a nondeterministic behavior in TensorFlow 2.20.0
The same script produces two completely different results on two consecutive runs:
Run 1:
Eager mode: runs successfully
XLA compile mode (jit_compile=True): fails with OperatorNotAllowedInGraphError
Run 2:
Eager mode: fails with InvalidArgumentError (ConcatV2 kernel type mismatch)
Error does not appear in Run 1
This indicates nondeterministic execution paths inside AutoGraph/XLA when Python
builtins (filter/map/zip) are used with Tensors.
The model uses zip() to combine two Tensor lists, and tf.concat() on the resulting list.
In the first run, TensorFlow internally coerces the zipped tuples into tensors.
In the second run, TensorFlow attempts to run ConcatV2 with an incorrect dtype (DT_QINT32),
leading to:
Expected behavior:
Eager mode should be deterministic and should either always succeed or always raise a type error.
Kernel dtype should never unexpectedly switch to DT_QINT32.
Graph/XLA mode should fail with a stable error message, not vary between runs.
This inconsistent behavior may indicate nondeterministic paths in AutoGraph or graph construction.
Standalone code to reproduce the issue
import tensorflow as tf
class TestModel(tf.keras.Model):
def __init__(self):
super().__init__()
self.d1 = tf.keras.layers.Dense(32, activation='relu')
self.d2 = tf.keras.layers.Dense(16, activation='tanh')
self.d3 = tf.keras.layers.Dense(8)
def call(self, x):
filtered_features = list(filter(lambda z: tf.reduce_sum(z) > 0.5, [x, x * 2, x * 3]))
mapped_features = list(map(lambda z: tf.nn.sigmoid(z), filtered_features))
zipped_data = list(zip(mapped_features, [tf.ones_like(x) for _ in range(len(mapped_features))]))
combined = tf.concat(zipped_data, axis=-1)
return self.d3(combined)
def get_default_model():
return TestModel()
def get_sample_inputs():
x = tf.random.normal([4, 16])
return (x,)
def main():
model = get_default_model()
inputs = get_sample_inputs()
eager_out = model(*inputs)
print('Eager Input shape:', inputs[0].shape)
print('Eager Output shape:', eager_out.shape)
@tf.function(jit_compile=True)
def compiled_forward(*args):
return model(*args)
compiled_out = compiled_forward(*inputs)
print('XLA Output shape:', compiled_out.shape)
if __name__ == '__main__':
main()
‵‵‵
Relevant log output
- Run 1:
- Eager mode: runs successfully
- XLA compile mode (jit_compile=True): fails with OperatorNotAllowedInGraphError
OperatorNotAllowedInGraphError: Exception encountered when calling TestModel.call().
Using a symbolic `tf.Tensor` as a Python `bool` is not allowed. You can attempt the following resolutions to the problem: If you are running in Graph mode, use Eager execution mode or decorate this function with @tf.function. If you are using AutoGraph, you can try decorating this function with @tf.function. If that does not work, then you may be using an unsupported feature or your source code may not be visible to AutoGraph. See https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/autograph/g3doc/reference/limitations.md#access-to-source-code for more information.
Arguments received by TestModel.call():
• x=tf.Tensor(shape=(4, 16), dtype=float32)
- Run 2:
- Eager mode: fails with InvalidArgumentError (ConcatV2 kernel type mismatch)
- Error does not appear in Run 1
tensorflow.python.framework.errors_impl.InvalidArgumentError: Exception encountered when calling TestModel.call().
OpKernel 'ConcatV2' has constraint on attr 'T' not in NodeDef '[N=0, Tidx=DT_INT32]', KernelDef: 'op: "ConcatV2" device_type: "CPU" constraint { name: "T" allowed_values { list { type: DT_QINT32 } } } host_memory_arg: "axis"' [Op:ConcatV2] name: concat
Arguments received by TestModel.call():
• x=tf.Tensor(shape=(4, 16), dtype=float32)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.