keras-team/keras · error · ValueError

All layers added to a Sequential model should have unique na

Error message

All layers added to a Sequential model should have unique names. Name '{layer.name}' is already the name of a layer in this model. Update the `name` argument to pass a unique name.

What it means

Error "All layers added to a Sequential model should have unique names. Name '{layer.name}' is already the name of a layer in this model. Update the `name` argument to pass a unique name." thrown in keras-team/keras.

Source

Thrown at keras/src/models/sequential.py:103

        # use it to build an InputLayer.
        if not self._layers:
            if getattr(layer, "_input_shape_arg", None) is not None:
                self.add(InputLayer(shape=layer._input_shape_arg))

        # If we are passed a Keras tensor created by keras.Input(), we
        # extract the input layer from its keras history and use that.
        if hasattr(layer, "_keras_history"):
            origin_layer = layer._keras_history[0]
            if isinstance(origin_layer, InputLayer):
                layer = origin_layer
        if not isinstance(layer, Layer):
            raise ValueError(
                "Only instances of `keras.Layer` can be "
                f"added to a Sequential model. Received: {layer} "
                f"(of type {type(layer)})"
            )
        if not self._is_layer_name_unique(layer):
            raise ValueError(
                "All layers added to a Sequential model "
                f"should have unique names. Name '{layer.name}' is already "
                "the name of a layer in this model. Update the `name` argument "
                "to pass a unique name."
            )
        if (
            isinstance(layer, InputLayer)
            and self._layers
            and isinstance(self._layers[0], InputLayer)
        ):
            raise ValueError(
                f"Sequential model '{self.name}' has already been configured "
                f"to use input shape {self._layers[0].batch_shape}. You cannot "
                f"add a different Input layer to it."
            )

        self._layers.append(layer)
        if rebuild:

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/models/sequential.py:103 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/d48eab9a187c2572. Report an issue: GitHub.