{"record":{"id":"882ee6197b0dedd0","repo":"keras-team/keras","slug":"expect-mesh-to-be-an-instance-of-devicemesh-r","errorCode":null,"errorMessage":"Expect `mesh` to be an instance of `DeviceMesh`. Received: mesh={device_mesh} (of type {type(device_mesh)})","messagePattern":"Expect `mesh` to be an instance of `DeviceMesh`\\. Received: mesh=(.+?) \\(of type (.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/distribution/distribution_lib.py","lineNumber":478,"sourceCode":"            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__(self, device_mesh=None, devices=None, auto_shard_dataset=True):\n        if device_mesh:\n            self._initialize_with_device_mesh(device_mesh, auto_shard_dataset)\n        elif devices:\n            self._initialize_mesh_from_devices(devices, auto_shard_dataset)\n        else:\n            self._initialize_mesh_from_list_devices(auto_shard_dataset)\n\n    @property\n    def num_model_replicas(self):\n        return self.device_mesh.devices.size\n\n    def _initialize_with_device_mesh(self, device_mesh, auto_shard_dataset):\n        if not isinstance(device_mesh, DeviceMesh):\n            raise ValueError(\n                \"Expect `mesh` to be an instance of `DeviceMesh`. \"\n                f\"Received: mesh={device_mesh} (of type {type(device_mesh)})\"\n            )\n        super().__init__(\n            device_mesh, device_mesh.axis_names[0], auto_shard_dataset\n        )\n        if self.device_mesh.devices.ndim != 1:\n            warnings.warn(\n                \"Expect the input mesh to be 1D, but received \"\n                \"mesh.devices.ndim=%d. \"\n                \"The first axis will be used for data-parallel sharding.\",\n                device_mesh.devices.ndim,\n            )\n\n    def _initialize_mesh_from_devices(self, devices, auto_shard_dataset):\n        devices = np.array(devices)\n        device_mesh = DeviceMesh(\n            shape=devices.shape,","sourceCodeStart":460,"sourceCodeEnd":496,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/distribution/distribution_lib.py#L460-L496","documentation":"Error \"Expect `mesh` to be an instance of `DeviceMesh`. Received: mesh={device_mesh} (of type {type(device_mesh)})\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/distribution/distribution_lib.py:478 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"}