{"record":{"id":"b825ebd9105be5a8","repo":"keras-team/keras","slug":"you-must-specify-a-layout-map-argument","errorCode":null,"errorMessage":"You must specify a layout_map argument.","messagePattern":"You must specify a layout_map argument\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/distribution/distribution_lib.py","lineNumber":629,"sourceCode":"            (of the `layout_map` object)\n            that will be used to distribute data. If unspecified, the\n            first axis from the device mesh will be used.\n        auto_shard_dataset: Automatically shard the dataset amongst\n            processes in a multi-process setting. Set to `False` if the dataset\n            is already sharded across hosts.  Defaults to `True`.\n    \"\"\"\n\n    def __init__(\n        self,\n        *,\n        layout_map=None,\n        batch_dim_name=None,\n        auto_shard_dataset=True,\n        **kwargs,\n    ):\n        kwargs.pop(\"device_mesh\", None)\n        if layout_map is None:\n            raise ValueError(\"You must specify a layout_map argument.\")\n        if not isinstance(layout_map, LayoutMap):\n            raise ValueError(\n                \"Argument `layout_map` must be a `LayoutMap` instance. \"\n                f\"Received: layout_map={layout_map}\"\n            )\n        device_mesh = layout_map.device_mesh\n        batch_dim_name = batch_dim_name or device_mesh.axis_names[0]\n        super().__init__(device_mesh, batch_dim_name, auto_shard_dataset)\n        self._layout_map = layout_map\n\n        if (\n            self._is_multi_process\n            and self.num_processes > self.num_model_replicas\n            and self.num_processes % self.num_model_replicas != 0\n        ):\n            raise ValueError(\n                \"If `num_processes` is greater than `num_model_replicas`, \"\n                \"`num_processes` must be divisible by `num_model_replicas`. \"","sourceCodeStart":611,"sourceCodeEnd":647,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/distribution/distribution_lib.py#L611-L647","documentation":"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.","triggerScenarios":"Thrown at keras/src/distribution/distribution_lib.py:629 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Construct a LayoutMap with a device mesh and pass layout_map=... to the constructor","Use the base Distribution class if you don't need path-based layout mapping","Populate the LayoutMap with ['kernel|.*'] style keys before use"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}