jax-ml/jax · error · ValueError

AbstractMesh does not implement {name}

Error message

AbstractMesh does not implement {name}

What it means

AbstractMesh intentionally leaves most members (devices, local_devices, size, __enter__, etc.) unimplemented, raising ValueError through _raise_value_error. AbstractMesh exists only as a named placeholder for named-sharding computation before a concrete mesh exists; calling concrete-mesh APIs on it is a misuse.

Source

Thrown at jax/_src/mesh.py:579

  @property
  def local_devices(self):
    _raise_value_error("local_devices")

  @property
  def local_mesh(self):
    _raise_value_error("local_mesh")

  def __enter__(self):
    _raise_value_error("__enter__")

  def __exit__(self, exc_type, exc_value, traceback):
    _raise_value_error("__exit__")


# Create this indirection because pytype fails to recognize a property if a
# property raises an exception unconditionally. Remove this once that is fixed.
def _raise_value_error(name):
  raise ValueError(f"AbstractMesh does not implement {name}")

empty_abstract_mesh = AbstractMesh((), ())
empty_concrete_mesh = Mesh(np.empty((), dtype=object), ())

class use_abstract_mesh:
  """Sets a abstract mesh in a thread-local context.

  ``jax.sharding.use_abstract_mesh`` can be used as a context manager.

  For example::

    abstract_device = jax.sharding.AbstractDevice(
        device_kind='TPU v6 lite', num_cores=1, platform='tpu')
    abstract_mesh = jax.sharding.AbstractMesh((2,), ('x',), (AxisType.Explicit,),
                                               abstract_device=abstract_device)

    @jax.jit
    def f(x):

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Guard with isinstance(mesh, jax.sharding.Mesh) before using concrete-mesh attributes
  2. Exit the use_abstract_mesh context before accessing device-level properties
  3. When you need devices, require a concrete mesh (create Mesh(devices, names)) explicitly

Example fix

# before
mesh = jax.config.abstract_mesh_context_manager.value
devs = mesh.devices  # may be AbstractMesh -> ValueError

# after
mesh = jax.config.abstract_mesh_context_manager.value
if isinstance(mesh, jax.sharding.Mesh):
  devs = mesh.devices
else:
  devs = jax.devices()
Defensive patterns

Strategy: type-guard

Validate before calling

import jax
mesh = jax.config.abstract_mesh_context_manager.value
usable = isinstance(mesh, jax.sharding.Mesh)

Type guard

import jax
def is_concrete_mesh(m) -> bool:
    return isinstance(m, jax.sharding.Mesh)

Prevention

When it happens

Trigger: Accessing empty_abstract_mesh.devices, .device_ids, .is_multi_process, .local_devices, .local_mesh, or entering it as a context manager; getting an AbstractMesh from the config's abstract_mesh_context_manager and treating it like a Mesh.

Common situations: Code written against concrete Mesh being handed an abstract mesh from jax.config.abstract_mesh_context_manager (set via use_abstract_mesh); autosharding-mode pipelines where the ambient mesh is abstract; type checks that pass (Mesh-like) but attribute access then fails.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/1a647104010e08fd. Report an issue: GitHub.