{"record":{"id":"18ab1859c0796331","repo":"jax-ml/jax","slug":"failed-to-infer-a-possible-set-of-layouts-this-sh","errorCode":null,"errorMessage":"Failed to infer a possible set of layouts. This should only happen if user-provided layout casts are unsatisfiable.","messagePattern":"Failed to infer a possible set of layouts\\. This should only happen if user-provided layout casts are unsatisfiable\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/mosaic/gpu/layout_inference.py","lineNumber":2789,"sourceCode":"              f\" {var.memory_space} != {site.memory_space}.\"\n          )\n        if site.shape != var.shape:\n          raise ValueError(\n              f\"Shape mismatch between variable and {site}:\"\n              f\" {var.shape} != {site.shape}.\"\n          )\n    global_constraint_system &= constraint_system\n    ctx.update(mapping)\n\n  for op in module.body:\n    traverse_op(op, gather_constraints)\n    # Short-circuit if we have an unsatisfiable constraint system, we won't\n    # construct anything useful anymore.\n    if isinstance(global_constraint_system, cs.Unsatisfiable):\n      break\n\n  if isinstance(global_constraint_system, cs.Unsatisfiable):\n    raise ValueError(\n        \"Failed to infer a possible set of layouts. This should only happen if \"\n        \"user-provided layout casts are unsatisfiable.\"\n    )\n\n  constraints = derive_relayout_constraints(ctx.value_sites_for_variable)\n  global_constraint_system &= cs.ConstraintSystem(constraints=constraints)\n  assert not isinstance(global_constraint_system, cs.Unsatisfiable)\n\n  # Add additional (redundant) constraints which helps the search converge\n  # faster.\n  global_constraint_system = cs.saturate_distinct_from_splat(\n      global_constraint_system\n  )\n  assert not isinstance(global_constraint_system, cs.Unsatisfiable)\n  global_constraint_system = (\n      cs.canonicalize_strict_non_splat_relayouts_to_equals(\n          global_constraint_system\n      )","sourceCodeStart":2771,"sourceCodeEnd":2807,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/mosaic/gpu/layout_inference.py#L2771-L2807","documentation":"The global layout constraint system became Unsatisfiable, meaning no assignment of layouts can satisfy all constraints; per the message this is only expected when user-provided layout casts conflict with each other.","triggerScenarios":"Two or more layout_casts (or explicit in/out layouts) that impose mutually exclusive constraints on the same value, e.g. requiring a register layout and a shared-memory layout simultaneously.","commonSituations":"Complex Mosaic kernels where users pin layouts at both ends of a computation that inference cannot reconcile.","solutions":["Remove or relax user-specified layout casts one at a time to find the conflicting pair","Make the casts compatible (chain them via intermediate casts instead of demanding both at once)","Let layout inference choose layouts automatically"],"exampleFix":"// before\nx = mgpu.layout_cast(x, layout_a)\ny = f(mgpu.layout_cast(x, layout_b))\n// after\nx = mgpu.layout_cast(x, layout_a)\ny = f(x)  # single consistent cast","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    infer_layouts(module)\nexcept ValueError as e:\n    if 'unsatisfiable' in str(e):\n        strip_user_casts_and_retry(module)","preventionTips":["Minimize explicit layout casts; let inference choose","Introduce casts one at a time when tuning layouts"],"tags":["jax","mosaic","layout","unsatisfiable-constraints"],"backgroundTag":"layout-inference-failure","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}