{"record":{"id":"a259bf9aba76fd1a","repo":"jax-ml/jax","slug":"mode-slice-is-not-valid-for-polymorphic-shapes","errorCode":null,"errorMessage":"mode='slice' is not valid for polymorphic shapes.","messagePattern":"mode='slice' is not valid for polymorphic shapes\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/indexing.py","lineNumber":382,"sourceCode":"      else:\n        new_indices.append(idx)\n    return NDIndexer(indices=new_indices, shape=self.shape)\n\n  def to_static_slice(\n      self, *,\n      arr_is_sharded: bool = False,\n      normalize_indices: bool = True,\n      mode: str | slicing.GatherScatterMode | None) -> _StaticSliceIndexer:\n    \"\"\"Convert to StaticSliceIndexer data structure.\n\n    If this is not possible, raise a ValueError, TypeError, or IndexError.\n    \"\"\"\n    if mode is None:\n      parsed_mode = slicing.GatherScatterMode.PROMISE_IN_BOUNDS\n    else:\n      parsed_mode = slicing.GatherScatterMode.from_any(mode)\n    if any(core.is_symbolic_dim(s) for s in self.shape):\n      raise ValueError(\"mode='slice' is not valid for polymorphic shapes.\")\n\n    if parsed_mode not in [\n        slicing.GatherScatterMode.PROMISE_IN_BOUNDS, slicing.GatherScatterMode.CLIP]:\n      raise ValueError(\"static_slice requires mode='promise_in_bounds' or mode='clip'\")\n\n    # Validation of the unmodified user indices.\n    if parsed_mode == slicing.GatherScatterMode.PROMISE_IN_BOUNDS:\n      self.validate_static_indices(normalize_indices=normalize_indices)\n    self.validate_slices()\n\n    # For sharded inputs, indexing (like x[0]) and partial slices (like x[:2] as\n    # opposed to x[:]) lead to incorrect sharding semantics when computed via slice.\n    # TODO(yashkatariya): fix slice with sharding\n    if arr_is_sharded and self.has_partial_slices():\n      raise ValueError(\"static_slice with partial slices does not support nontrivial array sharding.\")\n\n    for position, pidx in enumerate(self.indices):\n      if pidx.typ in [IndexType.INTEGER, IndexType.ELLIPSIS, IndexType.SLICE, IndexType.NONE]:","sourceCodeStart":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/indexing.py#L364-L400","documentation":"to_static_slice refuses to produce a static slice when any dimension of the array's shape is symbolic (polymorphic, e.g. from jax2ts or shape polymorphism with axis names like 'n'). Static slicing requires concrete sizes, so mode='slice' paths bail out with this ValueError.","triggerScenarios":"Using shape-polymorphic jit (e.g. jax.jit(f, axis_arg/ shape annotations like 'n') or jax2ts export) and indexing/slicing x within the traced function via the static-slice path.","commonSituations":"JAX shape-polymorphism / TorchExport workflows where a dynamic batch dim ('n') is declared and code slices that axis.","solutions":["Avoid slicing the polymorphic axis; use full-axis ops or lax.dynamic_slice with static size where supported","Mark that dimension as static (concrete int) if slicing is essential","Reorganize computation so the sliced output size remains static"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't slice polymorphic (symbolic) dimensions under shape-polymorphic jit/export","Keep sliced dims concrete in shape annotations"],"tags":["jax","polymorphic-shapes","export","slicing"],"backgroundTag":"polymorphic-shape-limitation","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}