{"record":{"id":"ea76d93517312113","repo":"keras-team/keras","slug":"cannot-create-sharding-when-device-mesh-is-not-set","errorCode":null,"errorMessage":"Cannot create sharding when device mesh is not set for TensorLayout.","messagePattern":"Cannot create sharding when device mesh is not set for TensorLayout\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/jax/distribution_lib.py","lineNumber":216,"sourceCode":"        A `jax.sharding.Mesh` instance.\n    \"\"\"\n    shape = device_mesh.devices.shape\n    devices = [_to_backend_device(d) for d in device_mesh.devices.flatten()]\n    devices = np.array(devices).reshape(shape)\n    return jax.sharding.Mesh(devices, device_mesh.axis_names)\n\n\ndef _to_backend_layout(tensor_layout):\n    \"\"\"Convert the TensorLayout to JAX backend specific Sharding.\n\n    Args:\n        tensor_layout: TensorLayout instance to convert.\n\n    Returns:\n        A `jax.sharding.NamedSharding` instance.\n    \"\"\"\n    if tensor_layout.device_mesh is None:\n        raise ValueError(\n            \"Cannot create sharding when device mesh is not set \"\n            \"for TensorLayout.\"\n        )\n    partition_spec = jax.sharding.PartitionSpec(*tensor_layout.axes)\n    jax_mesh = tensor_layout.device_mesh.backend_mesh\n    return jax.sharding.NamedSharding(jax_mesh, partition_spec)\n","sourceCodeStart":198,"sourceCodeEnd":223,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/jax/distribution_lib.py#L198-L223","documentation":"Error \"Cannot create sharding when device mesh is not set for TensorLayout.\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/backend/jax/distribution_lib.py:216 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"}