{"record":{"id":"972c7bf88c158cd2","repo":"jax-ml/jax","slug":"inf","errorCode":null,"errorMessage":"inf","messagePattern":"inf","errorType":"exception","errorClass":"InternalFloatingPointError","httpStatus":null,"severity":"error","filePath":"jax/_src/dispatch.py","lineNumber":313,"sourceCode":"  if needs_check_special():\n    for buf in bufs:\n      _check_special(name, buf.dtype, buf)\n\n\ndef check_special_array(name: str, arr: array.ArrayImpl) -> array.ArrayImpl:\n  if needs_check_special():\n    if dtypes.issubdtype(arr.dtype, np.inexact):\n      for buf in arr._arrays:\n        _check_special(name, buf.dtype, buf)\n  return arr\n\n\ndef _check_special(name: str, dtype: np.dtype, buf: basearray.Array) -> None:\n  if dtypes.issubdtype(dtype, np.inexact):\n    if config.debug_nans.value and np.any(np.isnan(np.asarray(buf))):\n      raise InternalFloatingPointError(name, \"nan\")\n    if config.debug_infs.value and np.any(np.isinf(np.asarray(buf))):\n      raise InternalFloatingPointError(name, \"inf\")\n\ndef _device_put_reshard(x): return x\n\n\n@util.cache(max_size=2048, trace_context_in_key=False)\ndef _cached_logical_device_ids(\n    inp_device_list: xc.DeviceList,\n    target_device_list: xc.DeviceList\n) -> tuple[int, ...]:\n  device_to_index = {d: i for i, d in enumerate(target_device_list)}\n  return tuple(device_to_index[d] for d in inp_device_list)\n\n\ndef _different_device_order_reshard(\n    x: array.ArrayImpl, target_sharding: NamedSharding, copy: ArrayCopySemantics\n) -> array.ArrayImpl:\n  x._check_if_deleted()\n  inp_sharding = x.sharding","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/dispatch.py#L295-L331","documentation":"Raised when jax_debug_infs (debug_infs config) is enabled and a computed buffer contains infinity. Like the NaN check, it turns silent Inf values into an early InternalFloatingPointError at the op that produced them, at the cost of performance.","triggerScenarios":"Enabling jax_debug_infs while a computation overflows to ±Inf, e.g. exp(large), division by zero, or fp16 overflow; check_special inspects every op output buffer.","commonSituations":"Mixed-precision (bfloat16/fp16) training overflow; exp on large logits; division by near-zero denominators; enabled during numerical debugging sessions.","solutions":["Locate the overflowing op via traceback/jax.debug.print and guard it (clip logits, use logsumexp, epsilon in denominators)","Switch to a wider dtype (float32) or enable loss scaling for mixed precision","Turn off jax_debug_infs once resolved, as it disables caching and adds overhead"],"exampleFix":"# before\np = jnp.exp(logits)  # overflow with debug_infs\n# after\np = jax.nn.softmax(logits)  # uses stable logsumexp internally","handlingStrategy":"validation","validationCode":"import jax.numpy as jnp\ndef finite(x): return bool(jnp.isfinite(jnp.asarray(x, dtype=jnp.float32)).all())\nassert all(finite(a) for a in jax.tree_util.tree_leaves(inputs))","typeGuard":null,"tryCatchPattern":"try:\n    with jax.debug_infs(True):\n        out = f(x)\nexcept jax._src.dispatch.InternalFloatingPointError as e:\n    print('Inf produced by op:', e); raise","preventionTips":["Clip exponents: jnp.clip(x, -30, 30) before exp","Use float32 or loss scaling for mixed precision","Add epsilons to denominators"],"tags":["jax","inf","numerical-overflow"],"backgroundTag":"numerical-overflow","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}