{"record":{"id":"eb0176ebc2fdcf0c","repo":"keras-team/keras","slug":"if-num-processes-is-greater-than-num-model-repl","errorCode":null,"errorMessage":"If `num_processes` is greater than `num_model_replicas`, `num_processes` must be divisible by `num_model_replicas`. Got num_processes={self.num_processes}, num_model_replicas={self.num_model_replicas}.","messagePattern":"If `num_processes` is greater than `num_model_replicas`, `num_processes` must be divisible by `num_model_replicas`\\. Got num_processes=(.+?), num_model_replicas=(.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/distribution/distribution_lib.py","lineNumber":645,"sourceCode":"        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`. \"\n                f\"Got num_processes={self.num_processes}, \"\n                f\"num_model_replicas={self.num_model_replicas}.\"\n            )\n\n    @property\n    def num_model_replicas(self):\n        mesh_batch_dim_index = self.device_mesh.axis_names.index(\n            self.batch_dim_name\n        )\n        return self.device_mesh.shape[mesh_batch_dim_index]\n\n    def get_data_layout(self, data_shape):\n        data_shard_spec = [None] * len(data_shape)\n        data_shard_spec[0] = self.batch_dim_name  # Shard on the first dim\n        return TensorLayout(data_shard_spec, self.device_mesh)\n","sourceCodeStart":627,"sourceCodeEnd":663,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/distribution/distribution_lib.py#L627-L663","documentation":"Error \"If `num_processes` is greater than `num_model_replicas`, `num_processes` must be divisible by `num_model_replicas`. Got num_processes={self.num_processes}, num_model_replicas={self.num_model_replicas}.\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/distribution/distribution_lib.py:645 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}