{"record":{"id":"397ea2717f9b7e39","repo":"jax-ml/jax","slug":"symbolic-dimension-cannot-be-raised-to-non-integer","errorCode":null,"errorMessage":"Symbolic dimension cannot be raised to non-integer powers: '{self}' ** '{power}'","messagePattern":"Symbolic dimension cannot be raised to non-integer powers: '(.+?)' \\*\\* '(.+?)'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/export/shape_poly.py","lineNumber":767,"sourceCode":"    return _DimExpr._normalize_sorted_terms(_DimExpr._coeff_to_sorted_terms(coeffs),\n                                            self.scope)\n\n  def __rmul__(self, other):\n    if isinstance(other, core.Tracer) or not _convertible_to_poly(other):\n      return self.__jax_array__().__rmul__(other)\n    if isinstance(other, int):\n      if other == 1: return self\n      if other == 0: return 0\n      return _DimExpr._linear_combination(self, other, 0, 0, self.scope)\n    return _ensure_poly(other, \"mul\", self.scope).__mul__(self)\n\n  def __pow__(self, power: core.DimSize, modulo=None):\n    if modulo is not None:\n      raise NotImplementedError(\"__pow__ modulo not implemented\")\n    if is_symbolic_dim(power):\n      return power.__rpow__(self)\n    if power != int(power):\n      raise ValueError(f\"Symbolic dimension cannot be raised to non-integer powers: '{self}' ** '{power}'\")\n    if power >= 0:\n      return functools.reduce(op.mul, [self] * power, 1)\n    # We don't support negative powers, because JAX does not allow negative\n    # powers for integers\n    raise ValueError(f\"Symbolic dimension cannot be raised to negative powers: '{self}' ** '{power}'\")\n\n  def __rpow__(self, other, modulo=None):\n    if modulo is not None:\n      raise NotImplementedError(\"__rpow__ modulo not implemented\")\n    return self.__jax_array__().__rpow__(other)\n\n  def __floordiv__(self, divisor):\n    if isinstance(divisor, core.Tracer) or not _convertible_to_poly(divisor):\n      return self.__jax_array__().__floordiv__(divisor)\n    return self._divmod(divisor)[0]\n\n  def __rfloordiv__(self, other):\n    if isinstance(other, core.Tracer) or not _convertible_to_poly(other):","sourceCodeStart":749,"sourceCodeEnd":785,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/export/shape_poly.py#L749-L785","documentation":"Symbolic dimensions may only be raised to integer powers; the polynomial algebra cannot represent non-integer exponents. A fractional (or otherwise non-integral) power triggers this ValueError.","triggerScenarios":"dim ** 0.5, dim ** 1.5, or np.float_power applied to a symbolic dim during polymorphic export; also dim ** np.float64(2.0)-like values that compare unequal to their int().","commonSituations":"Code computing square roots of dimensions (e.g. flattened image dims sqrt(h*w)) under jax.export shape polymorphism; passing numpy float scalars as exponents.","solutions":["Ensure the exponent is an int (cast: int(power)) when it is mathematically integral","Restructure to avoid non-integer powers of dims (pass sqrt dimension as a separate symbolic variable)","Drop polymorphism for that submodule (use concrete shapes)"],"exampleFix":"# before\nside = flat_dim ** 0.5\n# after\n# parameterize the side length itself in polymorphic_shapes\nside = 'h'  # and flat_dim = h * h via constraints or input shapes","handlingStrategy":"validation","validationCode":"assert float(power).is_integer(), 'exponent must be integral for symbolic dims'\npower = int(power)","typeGuard":"def integral_pow_ok(p) -> bool:\n    return isinstance(p, (int,)) or (isinstance(p, float) and p.is_integer())","tryCatchPattern":"try:\n    d = dim ** p\nexcept ValueError as e:\n    if 'non-integer powers' in str(e): d = dim ** int(p) if float(p).is_integer() else fallback()","preventionTips":["Cast exponents to int when mathematically integral","Parameterize derived dims (like sqrt sizes) as their own symbolic variables"],"tags":["jax","shape-polymorphism","pow","validation"],"backgroundTag":"symbolic-dimension-invalid-exponent","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}