-
Notifications
You must be signed in to change notification settings - Fork 19.7k
Description
Related Keras Version
keras==3.13.1, keras==3.10.0
The Conv1D layer shows inconsistent behavior between eager and symbolic execution. When given parameters that are invalid for the input shape (e.g., a dilation_rate that makes the effective kernel larger than the input), it correctly raises an error in eager mode.
However, in symbolic mode, it fails silently and returns a KerasTensor with a zero-dimension shape (e.g., (None, 0, 1)). This can mask configuration errors during model construction, leading to downstream issues that are difficult to debug. The symbolic path should perform the same validation and fail fast.
This issue is observed across different backends (TensorFlow==2.20.0, PyTorch==2.10.0+cu128).
Code to Reproduce
import keras
print(f"Keras version: {keras.__version__}")
# Eager execution
try:
eager_input = keras.random.normal(shape=(2, 10, 3))
layer = keras.layers.Conv1D(
filters=1,
kernel_size=2,
strides=1,
padding='valid',
dilation_rate = 10,
activation="relu"
)
eager_output = layer(eager_input)
print("Eager output shape:", eager_output.shape)
except Exception as e:
print("Error during eager execution:", e)
# Symbolic execution
symbolic_input = keras.Input(shape=(10, 3))
symbolic_output = layer(symbolic_input)
print("Symbolic output shape:", symbolic_output.shape)Actual Behavior
Eager execution fails with a descriptive error, but symbolic execution proceeds and produces a tensor with a zero dimension.
Keras version: 3.13.1
Error during eager execution: "The convolution operation resulted in an empty output. Output shape: (2, 0, 1)..."
Symbolic output shape: (None, 0, 1)
(Note: The exact error message varies by backend, but the eager failure is consistent.)
Expected Behavior
Symbolic execution should also raise an error during graph construction, mirroring the eager behavior. This would provide immediate feedback that the layer configuration is invalid.
Keras version: 3.13.1
Error during eager execution: "The convolution operation resulted in an empty output..."
# Followed by a similar error during the symbolic call:
# layer(symbolic_input)
# -> raises ValueError: "The convolution parameters are invalid for the given input shape..."