{"record":{"id":"57c53e78fcb2bcfd","repo":"jax-ml/jax","slug":"reduce-precision-exponent-bits-must-be-positive","errorCode":null,"errorMessage":"reduce_precision: exponent_bits must be positive; got {exponent_bits}","messagePattern":"reduce_precision: exponent_bits must be positive; got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/lax.py","lineNumber":8815,"sourceCode":"mlir.register_lowering(reduce_prod_p, partial(_unary_reduce_lower, hlo.MulOp,\n                                              _get_prod_identity))\nmlir.register_lowering(reduce_or_p, partial(_unary_reduce_lower, hlo.OrOp,\n                                            _get_bitwise_or_identity))\nmlir.register_lowering(reduce_and_p, partial(_unary_reduce_lower, hlo.AndOp,\n                                             _get_bitwise_and_identity))\nmlir.register_lowering(reduce_xor_p, partial(_unary_reduce_lower, hlo.XorOp,\n                                             _get_bitwise_or_identity))\nmlir.register_lowering(reduce_min_p, partial(_unary_reduce_lower, mlir.min_hlo,\n                                             _get_min_identity))\nmlir.register_lowering(reduce_max_p, partial(_unary_reduce_lower, mlir.max_hlo,\n                                             _get_max_identity))\n\n\ndef _reduce_precision_shape_rule(operand, *, exponent_bits, mantissa_bits):\n  exponent_bits = operator.index(exponent_bits)\n  mantissa_bits = operator.index(mantissa_bits)\n  if exponent_bits < 1:\n    raise ValueError(f\"reduce_precision: exponent_bits must be positive; got {exponent_bits}\")\n  if mantissa_bits < 0:\n    raise ValueError(f\"reduce_precision: mantissa_bits must be non-negative; got {mantissa_bits}\")\n  return operand.shape\n\ndef _reduce_precision_sharding_rule(operand, *, exponent_bits, mantissa_bits):\n  return operand.sharding\n\ndef _reduce_precision_memory_space_rule(operand, *, exponent_bits, mantissa_bits):\n  return operand.memory_space\n\ndef _reduce_precision_ur_rule(operand, *, exponent_bits, mantissa_bits):\n  out_unreduced = core.getu(operand)\n  kind = UnreducedKind.sum if out_unreduced else None\n  return out_unreduced, core.getr(operand), kind\n\nreduce_precision_p = standard_primitive(\n    _reduce_precision_shape_rule,\n    partial(unop_dtype_rule, _identity, _float, 'reduce_precision'),","sourceCodeStart":8797,"sourceCodeEnd":8833,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/lax.py#L8797-L8833","documentation":"reduce_precision's exponent_bits parameter must be >= 1 after operator.index() conversion. exponent_bits controls the target float format's exponent field; zero or negative values describe no representable format.","triggerScenarios":"lax.reduce_precision(x, exponent_bits=0, mantissa_bits=10), or passing a float/negative exponent_bits that indexes to a non-positive int. Fires in the shape rule during tracing.","commonSituations":"Simulating low-precision formats (bf16/fp8-style) with computed bit budgets where the exponent allocation math yields 0; parameter sweeps that include invalid corners.","solutions":["Validate exponent_bits >= 1 before calling; clamp or skip invalid configurations.","For bf16 simulation use exponent_bits=8, mantissa_bits=7.","Check the arithmetic that splits a total bit budget between exponent and mantissa (reserve at least 1 exponent bit)."],"exampleFix":"# before\ny = lax.reduce_precision(x, exponent_bits=0, mantissa_bits=7)\n# after\ny = lax.reduce_precision(x, exponent_bits=8, mantissa_bits=7)","handlingStrategy":"validation","validationCode":"assert exponent_bits >= 1, exponent_bits\ny = lax.reduce_precision(x, exponent_bits, mantissa_bits)","typeGuard":"def valid_reduce_precision_params(e, m):\n    return operator.index(e) >= 1 and operator.index(m) >= 0","tryCatchPattern":null,"preventionTips":["Clamp sweep parameters before calling reduce_precision.","Use known format constants (bf16: e=8, m=7)."],"tags":["jax","reduce-precision","bit-manipulation","validation"],"backgroundTag":"invalid-argument-range","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}