keras-team/keras · error · ValueError

already exist in the LayoutMap with value . Please make…

Error message

{key} already exist in the LayoutMap with value {self._layout_map[key]}. Please make sure to not use duplicated keys.

What it means

Raised by LayoutMap.__setitem__ in keras/src/distribution/distribution_lib.py: the map forbids re-assigning an existing key, and the key being inserted already has an entry (with the value shown). Inserting again would silently overwrite the previous TensorLayout, so the guard raises instead.

Solutions

  1. Use a distinct key/pattern for the new layout
  2. Delete or rebuild the LayoutMap if you truly need to replace a mapping
  3. Check loops that insert layouts for re-visited keys
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/distribution/distribution_lib.py:765 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/fe86d68cf43199cc. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/distribution/distribution_lib.py:765

                f"Path '{key}' matches multiple layout "
                f"specification keys: {matching_keys}. Please make "
                "sure each tensor/variable path only matches at most "
                "one layout specification key in the LayoutMap."
            )
        elif len(matching_keys) == 1:
            return self._layout_map[matching_keys[0]]
        return None

    def __setitem__(self, key, layout):
        """Insert TensorLayout to the LayoutMap.

        Args:
            key: String key for the `TensorLayout`.
            layout: The `TensorLayout`. As a shortcut, tuple of string and None
                are also acceptable, and will be converted to `TensorLayout`.
        """
        if key in self._layout_map:
            raise ValueError(
                f"{key} already exist in the LayoutMap with "
                f"value {self._layout_map[key]}. Please make sure to "
                "not use duplicated keys."
            )
        if isinstance(layout, tuple):
            layout = TensorLayout(axes=layout, device_mesh=None)

        if not isinstance(layout, TensorLayout):
            raise ValueError(
                f"{layout} should be a TensorLayout type, got {type(layout)}"
            )
        self._maybe_populate_device_mesh(layout)
        self._layout_map[key] = layout

    def __delitem__(self, key):
        # let the dict to handle the key missing error
        return self._layout_map.pop(key)

View on GitHub (pinned to 7a34a03db6)