{"record":{"id":"7156dbe66cc46d9f","repo":"jax-ml/jax","slug":"sizes-passed-to-split-must-be-nonnegative-got-li","errorCode":null,"errorMessage":"Sizes passed to split must be nonnegative, got {list(sizes)}","messagePattern":"Sizes passed to split must be nonnegative, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/lax.py","lineNumber":7541,"sourceCode":"unstack_p = core.Primitive('unstack')\nunstack_p.multiple_results = True\nunstack_p.def_abstract_eval(\n    partial(standard_multi_result_abstract_eval, unstack_p, _unstack_shape_rule,\n            _unstack_dtype_rule, _unstack_weak_type_rule, _unstack_sharding_rule,\n            _unstack_vma_rule, _unstack_ur_rule, None))\nunstack_p.def_impl(partial(dispatch.apply_primitive, unstack_p))\nad.deflinear2(unstack_p, _unstack_transpose_rule)\nmlir.register_lowering(unstack_p, _unstack_lower)\n\nbatching.primitive_batchers[stack_p] = _stack_batch_rule\nbatching.primitive_batchers[unstack_p] = _unstack_batch_rule\n\n\ndef _split_shape_rule(operand, *, sizes, axis):\n  shapes = []\n  shape = list(operand.shape)\n  if any(s < 0 for s in sizes):\n    raise ValueError(\n      f\"Sizes passed to split must be nonnegative, got {list(sizes)}\")\n  if operand.shape[axis] != np.sum(sizes):\n    raise ValueError(\n      f\"Sum of sizes {np.sum(sizes)} must be equal to dimension {axis} of the \"\n      f\"operand shape {list(operand.shape)}\")\n  for size in sizes:\n    shape[axis] = size\n    shapes.append(tuple(shape))\n  return shapes\n\ndef _split_dtype_rule(operand, *, sizes, axis):\n  return (operand.dtype,) * len(sizes)\n\ndef _split_weak_type_rule(operand, *, sizes, axis):\n  return (operand.weak_type,) * len(sizes)\n\ndef _split_transpose_rule(cotangents, operand, *, sizes, axis):\n  assert ad.is_undefined_primal(operand)","sourceCodeStart":7523,"sourceCodeEnd":7559,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/lax.py#L7523-L7559","documentation":"jax.lax.split takes an explicit list of section sizes along an axis; every size must be >= 0. A negative size is meaningless (it would produce a negative dimension) and raises this ValueError immediately in the shape rule.","triggerScenarios":"jax.lax.split(x, sizes=[2, -1, 3]); computing sizes by subtraction that goes negative (e.g. total - used where used > total).","commonSituations":"Splitting a tensor into fixed + remainder chunks computed as dim - k when k exceeds dim; off-by-one in size arithmetic; sizes derived from config with bad values.","solutions":["Validate sizes before calling: assert all(s >= 0 for s in sizes)","Compute the last chunk as the remainder dim - sum(others) and check it's >= 0","Use jnp.split / array_split with integer section counts if you don't need explicit sizes"],"exampleFix":"# before\nparts = jax.lax.split(x, sizes=[k, dim - 2*k])  # negative if 2*k > dim\n# after\nrest = dim - 2*k\nassert rest >= 0, (dim, k)\nparts = jax.lax.split(x, sizes=[k, k, rest])","handlingStrategy":"validation","validationCode":"assert all(s >= 0 for s in sizes), sizes","typeGuard":"def valid_sizes(sizes) -> bool:\n    return all(s >= 0 for s in sizes)","tryCatchPattern":null,"preventionTips":["Compute remainder chunks as dim - sum(others) and validate >= 0","Validate config-derived sizes at load time"],"tags":["jax","split","negative-size","validation"],"backgroundTag":"invalid-split-sizes","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}