{"record":{"id":"b03089a79f7310c4","repo":"jax-ml/jax","slug":"expected-mode-of-type-layoutmode-got-type-typ","errorCode":null,"errorMessage":"Expected mode of type `LayoutMode`. Got type: {type(mode)}","messagePattern":"Expected mode of type `LayoutMode`\\. Got type: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/layout.py","lineNumber":48,"sourceCode":"  def __repr__(self):\n    return \"AutoLayout\"\nAutoLayout = AutoLayoutSingleton()\n\n\nclass LayoutMode(enum.Enum):\n  AUTO = enum.auto()\n  JAX = enum.auto()\n  PALLAS_TPU = enum.auto()\n  PALLAS_GPU = enum.auto()\n\ndef get_layout_mode():\n  val = jax_config.layout_tracing_mode.value\n  return LayoutMode.AUTO if val is None else val\n\n@contextmanager\ndef use_layout_mode(mode):\n  if not isinstance(mode, LayoutMode):\n    raise TypeError(\n        f'Expected mode of type `LayoutMode`. Got type: {type(mode)}')\n  prev_mode = jax_config.layout_tracing_mode.swap_local(mode)\n  try:\n    yield\n  finally:\n    jax_config.layout_tracing_mode.set_local(prev_mode)\n\n\nclass Layout:\n  major_to_minor: tuple[int, ...]\n  tiling: tuple[tuple[int, ...], ...] | None\n  sub_byte_element_size_in_bits: int\n\n  AUTO = AutoLayout\n\n  def __init__(self, major_to_minor: tuple[int, ...],\n                tiling: tuple[tuple[int, ...], ...] | None = None,\n                sub_byte_element_size_in_bits: int = 0):","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/layout.py#L30-L66","documentation":"jax._src.layout.use_layout_mode is a context manager that only accepts jax._src.layout.LayoutMode enum values. Passing a string like 'default' or any other type raises TypeError.","triggerScenarios":"Calling use_layout_mode('major') or use_layout_mode(None) instead of a LayoutMode enum member.","commonSituations":"Custom tracing pipelines or libraries wrapping JAX's layout tracing configuration; passing config strings read from user settings.","solutions":["Import and use LayoutMode members: from jax._src.layout import LayoutMode; use_layout_mode(LayoutMode.AUTO)","Map user strings to enum values before calling"],"exampleFix":"# before\nuse_layout_mode('major')\n# after\nfrom jax._src.layout import LayoutMode\nuse_layout_mode(LayoutMode.MAJOR)","handlingStrategy":"type-guard","validationCode":"from jax._src.layout import LayoutMode\nassert isinstance(mode, LayoutMode)","typeGuard":"import jax._src.layout as L\ndef is_layout_mode(m): return isinstance(m, L.LayoutMode)","tryCatchPattern":null,"preventionTips":["Map config strings to enum members at the API boundary"],"tags":["jax","layout","type-validation","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}