{"record":{"id":"067bb5d950ae32f6","repo":"jax-ml/jax","slug":"encountered-dimension-variable-self-var-that-i","errorCode":null,"errorMessage":"Encountered dimension variable '{self.var}' that is not appearing in the shapes of the function arguments.\\nThe following dimension variables are appearing in the shapes of the function arguments: {list(env.keys())}.\\nPlease see https://docs.jax.dev/en/latest/export/shape_poly.html#dimension-variables-must-be-solvable-from-the-input-shapes for more details.","messagePattern":"Encountered dimension variable '(.+?)' that is not appearing in the shapes of the function arguments\\.\\\\nThe following dimension variables are appearing in the shapes of the function arguments: (.+?)\\.\\\\nPlease see https://docs\\.jax\\.dev/en/latest/export/shape_poly\\.html#dimension-variables-must-be-solvable-from-the-input-shapes for more details\\.","errorType":"exception","errorClass":"UnexpectedDimVar","httpStatus":null,"severity":"error","filePath":"jax/_src/export/shape_poly.py","lineNumber":230,"sourceCode":"  def evaluate(self, env: DimVarEnv, scope: SymbolicScope):\n    from jax._src.lax import lax\n\n    if self.var is not None:\n      try:\n        return env[self.var]\n      except KeyError:\n        # Perhaps there is a normalization rule for this variable\n        normalized_var = _DimExpr._from_var(self.var, scope)\n        if core.is_constant_dim(normalized_var):\n          return normalized_var\n        non_trivial_normalization = (v1 := normalized_var._to_var()) is None or v1 != self.var  # pyrefly: ignore[missing-attribute]\n        if non_trivial_normalization:\n          return normalized_var._evaluate(env)  # pyrefly: ignore[missing-attribute]\n        err_msg = (\n            f\"Encountered dimension variable '{self.var}' that is not appearing in the shapes of the function arguments.\\n\"\n            f\"The following dimension variables are appearing in the shapes of the function arguments: {list(env.keys())}.\\n\"\n            \"Please see https://docs.jax.dev/en/latest/export/shape_poly.html#dimension-variables-must-be-solvable-from-the-input-shapes for more details.\")\n        raise UnexpectedDimVar(err_msg)\n    else:\n      operand_values = [opnd._evaluate(env) for opnd in self.operands]\n      if self.operation == _DimFactor.FLOORDIV:\n        return divmod(*operand_values)[0]\n      elif self.operation == _DimFactor.MOD:\n        return divmod(*operand_values)[1]\n      elif self.operation == _DimFactor.MAX:\n        op1, op2 = operand_values\n        if core.is_constant_dim(op1) and core.is_constant_dim(op2):\n          return max(op1, op2)\n        if core.is_symbolic_dim(op1) or core.is_symbolic_dim(op2):\n          return core.max_dim(op1, op2)\n        # In the context of `evaluate` dimension variables may be mapped to\n        # JAX Tracers.\n        return lax.max(op1, op2)\n      elif self.operation == _DimFactor.MIN:\n        op1, op2 = operand_values\n        if core.is_constant_dim(op1) and core.is_constant_dim(op2):","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/export/shape_poly.py#L212-L248","documentation":"During polymorphic export evaluation, JAX solved dimension expressions against the shapes of the concrete (or specified) arguments. A dimension variable like 'n' appeared in an intermediate shape but never in any input argument shape, so its value cannot be solved.","triggerScenarios":"Exporting with polymorphic shapes where an equation produces a dim var (e.g. via random epochs or reshape) that is not present in any input dimension, e.g. shape '(n, n*2)' but computing something like a dimension derived from an internal constant divisible by a var.","commonSituations":"Using jax.export with shape polymorphism where a variable only appears on an output or inside jnp.arange, or specifying polymorphic_shapes strings that omit a variable used internally (e.g. random-wrapper epochs defaulting to a symbolic var).","solutions":["Make the variable appear in at least one input argument's shape (e.g. add a dummy argument of shape (n,) or restructure so the var is derived from an input)","Use a constant instead of the unsolvable variable for that dimension","Rework polymorphic_shapes so all internal dim vars are expressible from input shapes; see linked shape_poly docs section"],"exampleFix":"# before\ndef f(x):  # x: (m,)\n    return jnp.arange(x.shape[0] * 2)\njax.export.export(jax.export.shapes('n,'))(f)(x)  # n never in args\n# after\ndef f(x, hint):  # hint: (n,)\n    return jnp.arange(x.shape[0] * 2)\njax.export.export(jax.export.shapes('n,n,'))(f)(x, jnp.zeros(n))","handlingStrategy":"validation","validationCode":"# ensure every dim var used internally appears in an input shape\nimport jax.export as jex\nused = collect_dim_vars(fn)  # e.g. by test-tracing with symbolic shapes\nprovided = set(''.join(c for c in s if c.isalpha()) for s in polymorphic_shapes)\nassert used <= provided, f'unsolvable vars: {used - provided}'","typeGuard":null,"tryCatchPattern":"try:\n    exp = jax.export.export(shapes)(fn)\nexcept jax.export.shape_poly.UnexpectedDimVar as e:\n    add_dummy_input_exposing_var(str(e))","preventionTips":["Parameterize every internal quantity as a function of input-shape variables","Write a smoke export test with symbolic shapes before production runs"],"tags":["jax","export","shape-polymorphism","dimension-variables"],"backgroundTag":"symbolic-shape-unsolvable-dimension-variable","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}