{"record":{"id":"e737a341b9d90b43","repo":"jax-ml/jax","slug":"sharding-has-to-be-concrete-when-layout-is-of-type","errorCode":null,"errorMessage":"Sharding has to be concrete when layout is of type {type(layout)}. Please pass a `jax.sharding.NamedSharding` or `jax.sharding.SingleDeviceSharding` to the sharding argument. Got sharding {sharding}","messagePattern":"Sharding has to be concrete when layout is of type (.+?)\\. Please pass a `jax\\.sharding\\.NamedSharding` or `jax\\.sharding\\.SingleDeviceSharding` to the sharding argument\\. Got sharding (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/layout.py","lineNumber":138,"sourceCode":"  def check_compatible_aval(self, aval_shape: Shape):\n    if len(self.major_to_minor) != len(aval_shape):\n      raise ValueError(\n          f'Length of major_to_minor and the rank of the value should match.'\n          f' Got major_to_minor={self.major_to_minor} and shape={aval_shape}')\n\n\nLayoutOptions = Layout | None | AutoLayoutSingleton\nShardingOptions = Sharding | None\n\n\nclass Format:\n  __slots__ = ['layout', 'sharding']\n\n  def __init__(self, layout: LayoutOptions = None,\n               sharding: ShardingOptions = None):\n    # If layout is concrete and sharding is not, error.\n    if isinstance(layout, Layout) and sharding is None:\n      raise ValueError(\n          'Sharding has to be concrete when layout is of type'\n          f' {type(layout)}. Please pass a'\n          ' `jax.sharding.NamedSharding` or'\n          ' `jax.sharding.SingleDeviceSharding` to the sharding argument. Got'\n          f' sharding {sharding}'\n      )\n    if not isinstance(\n        layout, (Layout, type(None), AutoLayoutSingleton)):\n      raise TypeError(\n          'Invalid value received for the layout argument.'\n          ' Expected values are `None`, `Layout.AUTO` or an'\n          f' instance of `Layout`. Got {layout} of'\n          f' type {type(layout)}'\n      )\n    if not isinstance(sharding, (Sharding, type(None))):\n      raise TypeError(\n          'Invalid value received for the sharding argument. Expected values'\n          ' are `None` or an instance of `jax.Sharding`. Got'","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/layout.py#L120-L156","documentation":"When constructing a Layout with an explicit jax Layout object, a concrete sharding (NamedSharding or SingleDeviceSharding) must also be supplied. Layout without sharding is rejected.","triggerScenarios":"Layout(layout=Layout(major_to_minor=(1,0)), sharding=None) in APIs taking layout/sharding pairs (e.g. jax device placement or array creation options).","commonSituations":"Specifying memory layouts on multi-device JAX arrays without stating how the array is sharded.","solutions":["Pass a concrete sharding: jax.sharding.NamedSharding(mesh, P('x')) or jax.sharding.SingleDeviceSharding(jax.devices()[0])","Or omit the explicit Layout and let JAX infer layout from the sharding (AUTO)"],"exampleFix":"# before\nLayout(Layout(major_to_minor=(1,0)), sharding=None)\n# after\nimport jax\nLayout(Layout(major_to_minor=(1,0)),\n       sharding=jax.sharding.SingleDeviceSharding(jax.devices()[0]))","handlingStrategy":"validation","validationCode":"import jax\nfrom jax._src.layout import Layout\nif isinstance(layout, Layout):\n    assert sharding is not None and isinstance(sharding, jax.sharding.Sharding)","typeGuard":"import jax\nfrom jax._src.layout import Layout\ndef has_concrete_sharding(layout, sharding):\n    return not isinstance(layout, Layout) or isinstance(sharding, jax.sharding.Sharding)","tryCatchPattern":null,"preventionTips":["Pair explicit layouts with NamedSharding/SingleDeviceSharding","Or rely on auto layout inference"],"tags":["jax","layout","sharding","validation"],"backgroundTag":"layout-requires-sharding","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}