{"record":{"id":"7de90565a567e4cb","repo":"jax-ml/jax","slug":"start-and-end-must-fit-in-int32","errorCode":null,"errorMessage":"start and end must fit in int32","messagePattern":"start and end must fit in int32","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/triton/lowering.py","lineNumber":1502,"sourceCode":"    if i != dimension:\n      iota = _expand_dims(iota, i)\n  return _bcast_to(iota, shape)\n\n\ndef _element_type(t: ir.Type) -> ir.Type:\n  if isinstance(t, ir.RankedTensorType):\n    return ir.RankedTensorType(t).element_type\n  else:\n    return t\n\n\ndef _make_range(start: int, end: int) -> ir.Value:\n  if end <= start:\n    raise ValueError(\n        f\"end must be greater than start, but got: {end} <= {start}\"\n    )\n  if max(start, end) >= 2**32:\n    raise ValueError(\"start and end must fit in int32\")\n  return tt_dialect.make_range(\n      ir.RankedTensorType.get([end - start], ir.IntegerType.get_signless(32)),\n      start,\n      end,\n  )\n\n\ndef _full(t: ir.Type, v: Any) -> ir.Value:\n  element_type = _element_type(t)\n  if isinstance(element_type, ir.IntegerType):\n    result = arith_dialect.constant(element_type, int(v))\n  elif isinstance(element_type, ir.FloatType):\n    result = arith_dialect.constant(element_type, float(v))\n  else:\n    raise NotImplementedError\n\n  if isinstance(t, ir.RankedTensorType):\n    return tt_dialect.splat(t, result)","sourceCodeStart":1484,"sourceCodeEnd":1520,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/triton/lowering.py#L1484-L1520","documentation":"Triton's make_range op materializes int32 ranges, so _make_range rejects start/end values >= 2**32. Any iota, arange, offset computation, or argreduce whose bounds exceed int32 range fails during lowering with this ValueError.","triggerScenarios":"jnp.arange(0, N) inside a Pallas kernel with N >= 2**32; block/grid offset computations (e.g. program_id * large_stride) whose resulting start/end values overflow int32; argreduce on tensors with more than 2**32 elements along the reduced axis.","commonSituations":"Very large tensors (e.g. >4B element dimensions) on big-memory GPUs; integer overflow from multiplying program_id by a large block size; 64-bit index arithmetic assumed to work on TPU but not Triton.","solutions":["Split the range into 32-bit-sized chunks and process in multiple blocks/steps so each make_range call stays below 2**32","Keep per-kernel iteration spaces under 2**32; move the large-axis reduction across multiple kernel launches or use a different algorithm (tree reduction)","Check that intermediate offset products (program_id * block_size) don't silently overflow before reaching _make_range"],"exampleFix":"// before\nidx = jnp.arange(0, n)  # n >= 2**32\n// after\n# chunked over grid so each block's range fits in int32\nidx = jnp.arange(block_start, block_end)  # block_end - block_start < 2**31","handlingStrategy":"validation","validationCode":"INT32_MAX = 2**31 - 1\nassert all(0 <= start < end < 2**31 for start, end in ranges), 'range must fit in int32'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep per-block iteration spaces below 2**31 elements; chunk large axes across the grid","Watch for program_id * block_size products overflowing int32 before lowering"],"tags":["jax","pallas","triton","int32-overflow","arange","large-tensors"],"backgroundTag":"integer-overflow-range","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}