{"record":{"id":"3f6ed0e306537f02","repo":"jax-ml/jax","slug":"expected-mesh-of-type-jax-sharding-abstractmesh","errorCode":null,"errorMessage":"Expected mesh of type `jax.sharding.AbstractMesh`. Got type: {type(mesh)}","messagePattern":"Expected mesh of type `jax\\.sharding\\.AbstractMesh`\\. Got type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/mesh.py","lineNumber":614,"sourceCode":"    @jax.jit\n    def f(x):\n      return x * 2\n\n    with jax.sharding.use_abstract_mesh(abstract_mesh):\n      # Note: `f` will be traced and lowered for TPU platform.\n      f.trace(inp).lower()\n      # Note: `f` will be traced for TPU and lowered for CPU.\n      f.trace(inp).lower(lowering_platforms=('cpu',))\n\n  Note: In the example above, setting the abstract mesh at the top level only\n        takes effect if all mesh axes are Explicit. This is temporary until we\n        fix the underlying issues.\n  \"\"\"\n  __slots__ = ['mesh', 'prev']\n\n  def __init__(self, mesh: AbstractMesh):\n    if not isinstance(mesh, AbstractMesh):\n      raise ValueError(\n          \"Expected mesh of type `jax.sharding.AbstractMesh`. Got type:\"\n          f\" {type(mesh)}\")\n    self.mesh = mesh\n\n  def __enter__(self):\n    self.prev = jax_config.abstract_mesh_context_manager.swap_local(self.mesh)\n    if (self.prev is not config_ext.unset and\n        not self.prev.empty and not self.mesh.empty and\n        self.prev.size != self.mesh.size):\n      jax_config.abstract_mesh_context_manager.set_local(self.prev)\n      raise ValueError(\n          \"use_abstract_mesh cannot change the size of the mesh. Got new mesh:\"\n          f\" {self.mesh} with size={self.mesh.size} and prev mesh:\"\n          f\" {self.prev} with size={self.prev.size}\")\n\n  def __exit__(self, exc_type, exc_value, traceback):\n    jax_config.abstract_mesh_context_manager.set_local(self.prev)\n","sourceCodeStart":596,"sourceCodeEnd":632,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/mesh.py#L596-L632","documentation":"The use_abstract_mesh context manager validates its argument with isinstance(mesh, AbstractMesh) and raises ValueError otherwise. Note the target type is AbstractMesh specifically — passing a concrete Mesh is also an error here (in most versions).","triggerScenarios":"Calling jax.experimental.../mesh use_abstract_mesh(Mesh(...)) with a concrete Mesh, None, or a duck-typed object.","commonSituations":"Confusion over the dual mesh types introduced for autosharding: developers pass a physical Mesh where an abstract (name/axis-only) mesh is expected; migrating configs where the same variable holds either type.","solutions":["Construct an AbstractMesh(axis_names, axis_sizes) and pass that","If you meant to set a concrete mesh, use jax.set_mesh / Mesh context instead","Check isinstance before entering the context in generic code"],"exampleFix":"# before\nwith use_abstract_mesh(jax.sharding.Mesh(devs, ('data','model'))):\n  ...\n\n# after\nfrom jax.sharding import AbstractMesh\nwith use_abstract_mesh(AbstractMesh(('data','model'), (8, 4))):\n  ...","handlingStrategy":"type-guard","validationCode":"from jax.sharding import AbstractMesh\nassert isinstance(mesh, AbstractMesh), 'use_abstract_mesh needs AbstractMesh'","typeGuard":"from jax.sharding import AbstractMesh\ndef is_abstract_mesh(m) -> bool:\n    return isinstance(m, AbstractMesh)","tryCatchPattern":null,"preventionTips":["Keep separate variables for concrete Mesh vs AbstractMesh","Construct AbstractMesh(axis_names, axis_sizes) for context use"],"tags":["jax","mesh","type-validation","abstract-mesh"],"backgroundTag":"invalid-argument-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}