{"record":{"id":"f14ebd093cbad47c","repo":"jax-ml/jax","slug":"range-rnge-is-at-least-partially-out-of-bounds","errorCode":null,"errorMessage":"Range {rnge} is (at least partially) out of bounds for allocation shape {self.shape}.","messagePattern":"Range (.+?) is \\(at least partially\\) out of bounds for allocation shape (.+?)\\.","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic/interpret/shared_memory.py","lineNumber":350,"sourceCode":"    rnge = rnge_or_none\n    shape_to_write = self.content[rnge].shape\n    self.content[rnge] = value[tuple(slice(0, s) for s in shape_to_write)]\n\n  def __setitem__(self, rnge: tuple[slice | int, ...], value: np.ndarray):\n    \"\"\"Updates `self.content` with `value`, if `rnge` is fully within `self.shape`.\n\n    Args:\n      rnge: The range to write.\n      value: The value to write.\n\n    Raises:\n      IndexError: If any part of `rnge` is out of bounds for the allocated array\n        in the `Buffer`, i.e. if any part of `rnge` is out of bounds for\n        `self.shape`.\n    \"\"\"\n    rnge = self._normalize_range(rnge)\n    if interpret_utils.is_range_out_of_bounds_for_shape(rnge, self.shape):\n      raise IndexError(\n          f\"Range {rnge} is (at least partially) out of bounds for\"\n          f\" allocation shape {self.shape}.\"\n      )\n\n    self._set_within_logical_shape(rnge, value)\n\n  def set_in_bounds_portion(\n      self, rnge: tuple[slice | int, ...], value: np.ndarray\n  ):\n    \"\"\"Updates `self.content` with `value` for the portion of `rnge` within `self.logical_shape`.\"\"\"\n    rnge = self._normalize_range(rnge)\n    self._set_within_logical_shape(rnge, value)\n\n\n@dataclasses.dataclass(frozen=True)\nclass ShapeAndDtype:\n  shape: Sequence[int]\n  dtype: np.dtype","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic/interpret/shared_memory.py#L332-L368","documentation":"Interpret-mode Buffer.__setitem__ received a write range that is at least partially outside the allocation shape. Unlike reads, any partial out-of-bounds write is rejected because it would silently corrupt or drop data.","triggerScenarios":"Writing to an interpret shared memory Buffer with a slice extending past the allocation extent, e.g. smem[112:128] on a 120-element buffer.","commonSituations":"Boundary tiles in tiled kernels where (index * block_size + block_size) exceeds the allocation; mismatched grid and buffer sizes; incorrect masking in store operations.","solutions":["Clip the write range to the allocation before storing (slice(min(start, size), min(stop, size)))","Add proper masking so partial edge tiles only write in-bounds elements","Enlarge the allocation or fix the block/grid size math so ranges fit"],"exampleFix":"// before\nsmem[off:off + block_size] = value\n// after\nsmem[off:min(off + block_size, smem.shape[0])] = value[:min(block_size, smem.shape[0] - off)]","handlingStrategy":"validation","validationCode":"from jax._src.pallas.mosaic.interpret import interpret_utils\nassert not interpret_utils.is_range_out_of_bounds_for_shape(rnge, buf.shape), 'write range partially OOB'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clip store ranges: smem[off:min(off + bs, size)] = value[:n]","Mask edge-tile writes instead of relying on allocation slack","Keep grid/block math aligned with allocation extents"],"tags":["jax","pallas","mosaic","index-error","out-of-bounds","write"],"backgroundTag":"index-out-of-bounds","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}