keras-team/keras · error · ValueError

You must specify a layout_map argument.

Error message

You must specify a layout_map argument.

What it means

Raised in the constructor of the layout-based distribution class in keras/src/distribution/distribution_lib.py: unlike the base Distribution, this class requires a LayoutMap (it maps tensor paths to sharding layouts). layout_map was None, so there is no way to derive sharding specs, and the constructor refuses to continue.

Solutions

  1. Construct a LayoutMap with a device mesh and pass layout_map=... to the constructor
  2. Use the base Distribution class if you don't need path-based layout mapping
  3. Populate the LayoutMap with ['kernel|.*'] style keys before use
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

            (of the `layout_map` object)
            that will be used to distribute data. If unspecified, the
            first axis from the device mesh will be used.
        auto_shard_dataset: Automatically shard the dataset amongst
            processes in a multi-process setting. Set to `False` if the dataset
            is already sharded across hosts.  Defaults to `True`.
    """

    def __init__(
        self,
        *,
        layout_map=None,
        batch_dim_name=None,
        auto_shard_dataset=True,
        **kwargs,
    ):
        kwargs.pop("device_mesh", None)
        if layout_map is None:
            raise ValueError("You must specify a layout_map argument.")
        if not isinstance(layout_map, LayoutMap):
            raise ValueError(
                "Argument `layout_map` must be a `LayoutMap` instance. "
                f"Received: layout_map={layout_map}"
            )
        device_mesh = layout_map.device_mesh
        batch_dim_name = batch_dim_name or device_mesh.axis_names[0]
        super().__init__(device_mesh, batch_dim_name, auto_shard_dataset)
        self._layout_map = layout_map

        if (
            self._is_multi_process
            and self.num_processes > self.num_model_replicas
            and self.num_processes % self.num_model_replicas != 0
        ):
            raise ValueError(
                "If `num_processes` is greater than `num_model_replicas`, "
                "`num_processes` must be divisible by `num_model_replicas`. "

View on GitHub (pinned to 7a34a03db6)