Skip to content

keras.ops.pad fails on TensorFlow eager tensors when pad_width=0 #22540

@AGFACBNNR

Description

@AGFACBNNR

Summary

keras.ops.pad() works for a Keras symbolic input with pad_width=0, but raises a TensorFlow PadV2 rank error for an eager tensor.

Reproduction

import keras
import tensorflow as tf

x = tf.constant([[[1., 2.], [3., 4.]]], dtype=tf.float64)

# Works
y1 = keras.ops.pad(keras.Input(shape=(2, 2), batch_size=1), 0, mode="constant", constant_values=0.5)
print(y1.shape)

# Fails
y2 = keras.ops.pad(x, 0, mode="constant", constant_values=0.5)
print(y2)

Expected behavior

pad_width=0 should be a no-op and return the input tensor unchanged for both eager tensors and Keras symbolic tensors.

Actual behavior

The eager TensorFlow path fails with:

The first dimension of paddings must be the rank of inputs [...] [Op:PadV2]

while the symbolic Keras input returns the original shape correctly.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions