{"record":{"id":"0fcd6e7d1f3f4d82","repo":"jax-ml/jax","slug":"the-layout-of-shapedarray-should-not-be-autolayou","errorCode":null,"errorMessage":"The layout of ShapedArray should not be `AutoLayout` when layout mode is {cur_layout_mode}","messagePattern":"The layout of ShapedArray should not be `AutoLayout` when layout mode is (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/core.py","lineNumber":2449,"sourceCode":"                       unreduced_kind=kind)\n\n  @property\n  def empty(self):\n    return self is empty_mat\n\n  def invarying(self, mesh) -> frozenset:\n    return frozenset(mesh.manual_axes) - (\n        self.varying | self.unreduced | self.reduced)\n\n  @property\n  def vur(self) -> frozenset:\n    return self.varying | self.unreduced | self.reduced\n\ndef get_layout(layout):\n  cur_layout_mode = get_layout_mode()\n  if (cur_layout_mode is not LayoutMode.AUTO and\n      isinstance(layout, AutoLayoutSingleton)):\n    raise ValueError(\n        \"The layout of ShapedArray should not be `AutoLayout` when layout mode\"\n        f\" is {cur_layout_mode}\")\n  return layout\n\n\nempty_mat = ManualAxisType()\n\n@functools.cache\ndef _empty_sharding(ndim):\n  return NamedSharding(mesh_lib.empty_abstract_mesh, P(*[None] * ndim))\n\n\n@immutable\nclass ShapedArray(AbstractValue):\n  # inherits slots from parent\n  __slots__ = ['shape', 'dtype', 'weak_type', 'sharding', 'manual_axis_type',\n               'memory_space', 'layout', '_stripped_weak_type', '__weakref__']\n  array_abstraction_level = 2","sourceCodeStart":2431,"sourceCodeEnd":2467,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/core.py#L2431-L2467","documentation":"get_layout rejects AutoLayout (the placeholder 'deferred' layout) when the global layout mode is not AUTO. In explicit/deferred layout modes, an aval must carry a concrete layout, not the Auto sentinel.","triggerScenarios":"Constructing avals with layout=AutoLayout while jax.config or the layout mode context sets LayoutMode.EXPLICIT (e.g. via jax.layout_mode or experimental layout APIs); usually in custom primitives or tests toggling modes.","commonSituations":"Enabling experimental layout inference/mode flags; code that worked under default AUTO mode then running under a different mode; mixing explicit-layout APIs with default avals.","solutions":["Supply a concrete layout instead of AutoLayout when layout mode is explicit","Avoid flipping global layout mode around code that creates default avals","Wrap mode-dependent construction so AUTO mode is only used where AutoLayout is allowed"],"exampleFix":"// before\naval = ShapedArray._create(shape, dtype, ..., layout=AutoLayout())  # under EXPLICIT mode\n\n// after\naval = ShapedArray._create(shape, dtype, ..., layout=concrete_layout)","handlingStrategy":"validation","validationCode":"from jax._src.core import get_layout_mode, AutoLayoutSingleton\nif get_layout_mode() is not LayoutMode.AUTO and isinstance(layout, AutoLayoutSingleton):\n    layout = concrete_layout","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never store AutoLayout when running under explicit layout mode","Scope layout-mode changes narrowly with a context manager"],"tags":["jax","layout","auto-layout","configuration"],"backgroundTag":"configuration-mode-conflict","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}