{"record":{"id":"0465323421c289d5","repo":"jax-ml/jax","slug":"shard-map-requires-a-jax-sharding-mesh-or-a-jax","errorCode":null,"errorMessage":"shard_map requires a `jax.sharding.Mesh` or a `jax.sharding.AbstractMesh` instance for its second argument, but got {mesh} of type {type(mesh)}.","messagePattern":"shard_map requires a `jax\\.sharding\\.Mesh` or a `jax\\.sharding\\.AbstractMesh` instance for its second argument, but got (.+?) of type (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/shard_map.py","lineNumber":379,"sourceCode":"  return P(*[None] * axis + [axis_name])\n\n\ndef _shmap_checks(mesh, axis_names, in_specs, out_specs, _smap):\n  if mesh is None:\n    mesh = get_abstract_mesh()\n    if mesh.empty:\n      raise ValueError(\n          \"The context mesh cannot be empty. Use\"\n          \" `jax.set_mesh(mesh)` to enter into a mesh context\")\n  else:\n    ctx_mesh = get_abstract_mesh()\n    if not ctx_mesh.empty and mesh.abstract_mesh != ctx_mesh:\n      raise ValueError(\n          f\"The context mesh {ctx_mesh} should match the mesh passed to\"\n          f\" shard_map {mesh}\")\n\n  if not isinstance(mesh, (Mesh, AbstractMesh)):\n    raise TypeError(\"shard_map requires a `jax.sharding.Mesh` or a \"\n                    \"`jax.sharding.AbstractMesh` instance for its \"\n                    f\"second argument, but got {mesh} of type {type(mesh)}.\")\n  if mesh.empty:\n    raise ValueError(f\"shard_map requires a non-empty mesh. Got {mesh}\")\n\n  mesh_axis_names_wo_vmap = (\n      frozenset(mesh.axis_names) - core.get_axis_env().explicit_mesh_axis_names\n  )\n\n  if not isinstance(axis_names, (frozenset, set)):\n    raise TypeError(\n        \"`axis_names` argument of shard_map should be of type `frozenset` or\"\n        f\" `set`. Got type: {type(axis_names)}\")\n  if isinstance(axis_names, set):\n    axis_names = frozenset(axis_names)\n  if not axis_names:\n    axis_names = mesh_axis_names_wo_vmap\n  if not axis_names.issubset(mesh_axis_names_wo_vmap):","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/shard_map.py#L361-L397","documentation":"shard_map's mesh argument (second argument) must be a jax.sharding.Mesh or jax.sharding.AbstractMesh instance. Passing anything else — dict, tuple, NamedSharding, a device list — raises this TypeError showing the offending value and its type.","triggerScenarios":"Calling shard_map(f, mesh=P('i'), ...), mesh={'i': 4}, mesh=(devices,), or passing a jax.sharding.NamedSharding where the Mesh itself is expected.","commonSituations":"Confusing Mesh with NamedSharding (the latter is built FROM a mesh); constructing pseudo-meshes from raw device arrays; typos passing in_specs as the mesh argument positionally.","solutions":["Create a real mesh: mesh = Mesh(jax.devices(), axis_names=('i',)) and pass that","If you already have a NamedSharding, extract its mesh or rebuild one over the same devices"],"exampleFix":"// before\njax.shard_map(f, mesh={'i': 4}, in_specs=P('i'), out_specs=P('i'))(x)\n\n// after\nmesh = jax.sharding.Mesh(jax.devices(), axis_names=('i',))\njax.shard_map(f, mesh=mesh, in_specs=P('i'), out_specs=P('i'))(x)","handlingStrategy":"type-guard","validationCode":"from jax.sharding import Mesh, AbstractMesh\nassert isinstance(mesh, (Mesh, AbstractMesh)), type(mesh)","typeGuard":"def is_valid_mesh(m) -> bool:\n    return isinstance(m, (jax.sharding.Mesh, jax.sharding.AbstractMesh))","tryCatchPattern":null,"preventionTips":["Build meshes with jax.sharding.Mesh(jax.devices(), axis_names=...)","Don't pass NamedSharding or dicts where a Mesh is required"],"tags":["jax","shard-map","mesh","type-error","distributed"],"backgroundTag":"invalid-argument-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}