{"record":{"id":"7d7c1834ffc511e2","repo":"jax-ml/jax","slug":"subclasses-should-implement-this-method","errorCode":null,"errorMessage":"Subclasses should implement this method.","messagePattern":"Subclasses should implement this method\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/_src/sharding.py","lineNumber":106,"sourceCode":"            s1._internal_device_list == s2._internal_device_list)\n  else:\n    return hlo_s_eq and mem_eq\n\n\n@use_cpp_class(xc.Sharding)\nclass Sharding:\n  \"\"\"Describes how a :class:`jax.Array` is laid out across devices.\n  \"\"\"\n\n  # Abstract methods below that subclasses should implement.\n  @property\n  def device_set(self) -> set[Device]:\n    \"\"\"The set of devices that this :class:`Sharding` spans.\n\n    In multi-controller JAX, the set of devices is global, i.e., includes\n    non-addressable devices from other processes.\n    \"\"\"\n    raise NotImplementedError('Subclasses should implement this method.')\n\n  @property\n  def is_fully_replicated(self) -> bool:\n    \"\"\"Is this sharding fully replicated?\n\n    A sharding is fully replicated if each device has a complete copy of the\n    entire data.\n    \"\"\"\n    raise NotImplementedError('Subclasses should implement this method.')\n\n  @property\n  def is_fully_addressable(self) -> bool:\n    \"\"\"Is this sharding fully addressable?\n\n    A sharding is fully addressable if the current process can address all of\n    the devices named in the :class:`Sharding`. ``is_fully_addressable`` is\n    equivalent to \"is_local\" in multi-process JAX.\n    \"\"\"","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/sharding.py#L88-L124","documentation":"Base Sharding.device_set() raises NotImplementedError: the base jax.sharding.Sharding class does not implement it; only concrete subclasses (NamedSharding, SingleDeviceSharding, GSPMDSharding, ...) do. Hitting it means you instantiated the abstract base or an incomplete subclass.","triggerScenarios":"Calling Sharding().device_set(), or subclassing Sharding without overriding device_set, then calling it (often indirectly via addressable_devices).","commonSituations":"Custom Sharding subclass missing required methods; accidentally returning base-class instances from factory code.","solutions":["Use a concrete sharding (NamedSharding, SingleDeviceSharding, PositionalSharding, GSPMDSharding) instead of the base class","If subclassing, implement device_set (and the other abstract members) in your subclass"],"exampleFix":"# before\nsh = jax.sharding.Sharding()\nsh.device_set()\n\n# after\nfrom jax.sharding import NamedSharding, PartitionSpec as P\nsh = NamedSharding(mesh, P('data'))\nsh.device_set()","handlingStrategy":"type-guard","validationCode":"from jax.sharding import Sharding, NamedSharding\nassert not type(s) is Sharding, 'base Sharding is abstract'","typeGuard":"def is_concrete_sharding(s) -> bool:\n    from jax.sharding import Sharding\n    return isinstance(s, Sharding) and type(s) is not Sharding and getattr(type(s).device_set, '__isabstractmethod__', False) is False","tryCatchPattern":null,"preventionTips":["Never instantiate jax.sharding.Sharding directly","For custom shardings, subclass NamedSharding/GSPMDSharding to inherit required methods"],"tags":["jax","sharding","not-implemented","abstract-method"],"backgroundTag":"abstract-method-not-implemented","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}