keras-team/keras · error · ValueError

Cannot unroll a RNN if the time dimension is undefined. - I

Error message

Cannot unroll a RNN if the time dimension is undefined. 
- If using a Sequential model, specify the time dimension by passing an `Input()` as your first layer.
- If using the functional API, specify the time dimension by passing a `shape` or `batch_shape` argument to your `Input()`.

What it means

Error "Cannot unroll a RNN if the time dimension is undefined. - If using a Sequential model, specify the time dimension by passing an `Input()` as your first layer. - If using the functional API, specify the time dimension by passing a `shape` or `batch_shape` argument to your `Input()`." thrown in keras-team/keras.

Source

Thrown at keras/src/layers/rnn/rnn.py:371

            initial_state,
            go_backwards=self.go_backwards,
            mask=mask,
            unroll=self.unroll,
            input_length=sequences.shape[1],
            zero_output_for_mask=self.zero_output_for_mask,
            return_all_outputs=self.return_sequences,
        )

    def call(
        self,
        sequences,
        initial_state=None,
        mask=None,
        training=False,
    ):
        timesteps = sequences.shape[1]
        if self.unroll and timesteps is None:
            raise ValueError(
                "Cannot unroll a RNN if the "
                "time dimension is undefined. \n"
                "- If using a Sequential model, "
                "specify the time dimension by passing "
                "an `Input()` as your first layer.\n"
                "- If using the functional API, specify "
                "the time dimension by passing a `shape` "
                "or `batch_shape` argument to your `Input()`."
            )

        if initial_state is None:
            if self.stateful:
                initial_state = self.states
            else:
                initial_state = self.get_initial_state(
                    batch_size=ops.shape(sequences)[0]
                )
        if self.stateful:

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/layers/rnn/rnn.py:371 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/87019b5c311a7e29. Report an issue: GitHub.