{"record":{"id":"090b2aa0f7b543b3","repo":"jax-ml/jax","slug":"mesh-of-an-aval-must-be-an-abstractmesh-got-out","errorCode":null,"errorMessage":"Mesh of an aval must be an AbstractMesh. Got {out_s.mesh} of type {type(out_s.mesh)}","messagePattern":"Mesh of an aval must be an AbstractMesh\\. Got (.+?) of type (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/core.py","lineNumber":2300,"sourceCode":"\n  Some modifications/checks include:\n    * Making the length of specs the same as ndim\n    * If a mesh axis is mentioned in pspec is Auto/Manual, replace it with None\n    * Checking for len(spec)-ndim match\n    * Checking if the mesh is an AbstractMesh.\n  \"\"\"\n  ndim = len(shape)\n  if sharding is None:\n    return _empty_sharding(ndim)\n\n  out_s = _maybe_modify_sharding(sharding, ndim)\n  if len(out_s.spec) != ndim:\n    raise ValueError(\n        f\"Length of sharding.spec ({len(out_s.spec)}) must be equal to aval's\"\n        f\" ndim ({ndim}). Got sharding.spec {out_s.spec}, aval.ndim {ndim} and\"\n        f\" sharding {out_s}\")\n  if not isinstance(out_s.mesh, mesh_lib.AbstractMesh):\n    raise ValueError(\"Mesh of an aval must be an AbstractMesh. \"\n                     f\"Got {out_s.mesh} of type {type(out_s.mesh)}\")\n  _check_divisibility(out_s, shape)\n  if out_s.memory_kind is not None:\n    raise ValueError(\n        \"sharding with memory_kind is not allowed. Please use `jax.device_put`\"\n        f\" to transfer to different memory spaces. Got {sharding=}\")\n  return out_s\n\n\n@cache(max_size=4096,\n       trace_context_in_key=lambda: config.remove_size_one_mesh_axis_from_type.value)\ndef get_mat(mat, mesh):\n  if mesh.empty:\n    assert mat.empty, mat\n    return mat\n\n  axis_env = get_axis_env()\n  in_axis_env = lambda i: axis_env.axis_exists(i) and i not in mesh._name_to_type","sourceCodeStart":2282,"sourceCodeEnd":2318,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/core.py#L2282-L2318","documentation":"When an abstract value carries a sharding, JAX requires its mesh to be an AbstractMesh (the named-axis mesh used inside traced/computation avals). A concrete runtime mesh or other object type is rejected because aval-level shardings only describe logical named-axis layouts.","triggerScenarios":"Constructing avals or calling internal APIs like get_sharding/aval constructors with a sharding whose .mesh is a concrete Mesh or a user object; passing a NamedSharding created from a physical Mesh into aval-level code paths.","commonSituations":"Mixing jax.sharding.Mesh (concrete) with jax.mesh_utils / AbstractMesh APIs; version upgrades where internal invariants on aval shardings became enforced; writing custom primitives that attach shardings to avals.","solutions":["Use jax.make_mesh(..., abstract=True) or an AbstractMesh when building shardings destined for avals","Don't attach runtime NamedSharding objects to abstract values; only user-level APIs (device_put, jit in_sharding) should","Upgrade JAX so mesh-handling matches the current API surface"],"exampleFix":"// before\nmesh = jax.make_mesh((4,), ('x',))  # concrete mesh\naval_sharding = NamedSharding(mesh, P('x'))  # then used on an aval\n\n// after\namesh = jax.make_mesh((4,), ('x',), abstract=True)\naval_sharding = NamedSharding(amesh, P('x'))","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"from jax._src import mesh_lib\n\ndef is_abstract_mesh_sharding(s):\n    return isinstance(getattr(s, 'mesh', None), mesh_lib.AbstractMesh)","tryCatchPattern":"try:\n    aval_with_sharding(s)\nexcept ValueError as e:\n    if 'AbstractMesh' in str(e):\n        s = rebuild_with_abstract_mesh(s)","preventionTips":["Use make_mesh(..., abstract=True) for aval-level shardings","Never attach concrete-mesh shardings to avals","Keep runtime vs abstract sharding usage separated in code"],"tags":["jax","sharding","mesh","abstract-mesh","type-mismatch"],"backgroundTag":"invalid-sharding-configuration","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}