{"record":{"id":"78eb6108c4dad46e","repo":"jax-ml/jax","slug":"logical-shape-self-logical-shape-cannot-be-bigge","errorCode":null,"errorMessage":"Logical shape {self.logical_shape} cannot be bigger than content shape {self.content.shape}.","messagePattern":"Logical shape (.+?) cannot be bigger than content shape (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic/interpret/shared_memory.py","lineNumber":254,"sourceCode":"  def __init__(\n      self,\n      content: np.ndarray,\n      ref_count: int = 1,\n      logical_shape: tuple[int, ...] | None = None,\n  ):\n    super().__init__()\n\n    self._content = content\n    self._ref_count = ref_count\n\n    if logical_shape is None:\n      self._logical_shape = tuple(self._content.shape)\n    else:\n      self._logical_shape = logical_shape\n\n    for dim, ldim in zip(self.content.shape, self.logical_shape, strict=True):\n      if ldim > dim:\n        raise ValueError(\n            f\"Logical shape {self.logical_shape} cannot be bigger than content\"\n            f\" shape {self.content.shape}.\"\n        )\n\n  @property\n  def content(self) -> np.ndarray:\n    return self._content\n\n  @property\n  def ref_count(self) -> int:\n    return self._ref_count\n\n  @property\n  def logical_shape(self) -> tuple[int, ...]:\n    return self._logical_shape\n\n  def decrease_ref_count(self):\n    # We should never decrease the `ref_count` to below zero.","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic/interpret/shared_memory.py#L236-L272","documentation":"A shared-memory Buffer in Mosaic interpret mode was constructed with a logical_shape dimension larger than the underlying content array's shape. The logical shape may shrink (view a subregion) but can never exceed the allocated content.","triggerScenarios":"Creating interpret shared_memory.Buffer(content, logical_shape=...) where some logical dimension > the corresponding content.shape dimension; typically from BlockMapping with block shapes exceeding allocated SMEM.","commonSituations":"Mismatch between the BlockMapping's logical block shape and the allocated shared-memory buffer size in a Mosaic kernel; off-by-one or transposed block dims; changes to memory space allocation after a refactor.","solutions":["Check that every dim of logical_shape <= the corresponding dim of the allocation; fix the allocation size or the logical shape","Inspect the kernel's BlockMapping and shared memory allocations for transposed or wrong-shape blocks","If writing tests that build Buffers directly, allocate content with the max needed shape"],"exampleFix":"// before\nbuf = Buffer(content=np.zeros((16, 32)), logical_shape=(32, 32))\n// after\nbuf = Buffer(content=np.zeros((32, 32)), logical_shape=(16, 32))","handlingStrategy":"validation","validationCode":"assert all(l <= c for l, c in zip(logical_shape, content.shape, strict=True)), 'logical_shape exceeds content shape'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always derive logical shapes by slicing/shrinking the allocation, never enlarging","Keep BlockMapping block shapes consistent with SMEM allocation sizes"],"tags":["jax","pallas","mosaic","shared-memory","shape-mismatch","interpret-mode"],"backgroundTag":"shape-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}