{"record":{"id":"72a1d069d3e8efe9","repo":"jax-ml/jax","slug":"integer-constant-out-of-range-for-i64-v","errorCode":null,"errorMessage":"Integer constant out of range for i64: {v}","messagePattern":"Integer constant out of range for i64: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic_gpu/lowering.py","lineNumber":4452,"sourceCode":"  ):\n    if isinstance(t, (ir.IntegerType, ir.IndexType)):\n      v = int(v)\n    else:\n      assert isinstance(t, ir.FloatType)\n      v = float(v)\n    return arith_dialect.constant(t, v)\n  raise NotImplementedError(f\"Unsupported constant: {v!r}\")\n\n\ndef _i32_constant(v: int) -> ir.Value:\n  if v < jnp.iinfo(jnp.int32).min or v > jnp.iinfo(jnp.int32).max:\n    raise ValueError(f\"Integer constant out of range for i32: {v}\")\n  return arith_dialect.constant(ir.IntegerType.get_signless(32), v)\n\n\ndef _i64_constant(v: int) -> ir.Value:\n  if v < jnp.iinfo(jnp.int64).min or v > jnp.iinfo(jnp.int64).max:\n    raise ValueError(f\"Integer constant out of range for i64: {v}\")\n  return arith_dialect.constant(ir.IntegerType.get_signless(64), v)\n\n\ndef _as_index(v: object) -> ir.Value:\n  match v:\n    case int():\n      return arith_dialect.constant(ir.IndexType.get(), v)\n    case ir.Value() if isinstance(v.type, ir.IndexType):\n      return v\n    case ir.Value() if isinstance(v.type, ir.IntegerType):\n      return arith_dialect.index_cast(ir.IndexType.get(), v)\n    case mgpu.FragmentedArray(layout=mgpu.WGSplatFragLayout()):\n      return _as_index(v.registers.item())\n    case jax_literals.TypedNdArray() if (\n        np.issubdtype(v.dtype, np.integer) and v.ndim == 0\n    ):\n      return arith_dialect.constant(ir.IndexType.get(), int(v))\n    case _:","sourceCodeStart":4434,"sourceCodeEnd":4470,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic_gpu/lowering.py#L4434-L4470","documentation":"Raised when building an i64 MLIR integer constant in the Mosaic GPU lowering layer and the Python int falls outside the int64 range. This is an internal invariant check while lowering Pallas/Mosaic GPU kernels; it indicates the JAXpr itself contained an out-of-range integer index/constant. End users essentially never trigger it through supported APIs.","triggerScenarios":"Calling a Mosaic GPU (plgpu) kernel whose computation contains an integer constant exceeding 2**63-1 or below -2**63, e.g. an enormous python int used as an index or offset inside the kernel.","commonSituations":"Passing Python ints produced by overflow-prone arithmetic (e.g. large shapes/strides multiplied together) into pallas kernels; bugs in user code computing indices.","solutions":["Inspect the kernel code for huge integer literals or index computations that overflow int64","Compute indices with numpy int64/jnp.int64 and clamp/validate before use","If shapes are genuinely enormous, restructure the kernel to use smaller per-block indices"],"exampleFix":"// before\noffset = 2**70  # passed into kernel\n// after\noffset = np.int64(min(2**63 - 1, computed_offset))","handlingStrategy":"validation","validationCode":"import numpy as np\nassert np.iinfo(np.int64).min <= v <= np.iinfo(np.int64).max, f\"int64 overflow: {v}\"","typeGuard":"def is_i64(v) -> bool:\n    return isinstance(v, int) and -2**63 <= v < 2**63","tryCatchPattern":null,"preventionTips":["Validate large computed indices before passing them into kernels","Use np.int64 arithmetic so overflow surfaces as numpy errors"],"tags":["pallas","mosaic-gpu","integer-overflow","jax"],"backgroundTag":"integer-overflow","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}