{"record":{"id":"608c3c82a23d8d00","repo":"jax-ml/jax","slug":"explicitly-requested-dtype-is-not-available-608c3c","errorCode":null,"errorMessage":"Explicitly requested dtype {}{} is not available, and will be truncated to dtype {}. To enable more dtypes, set the jax_enable_x64 configuration option or the JAX_ENABLE_X64 shell environment variable. See https://github.com/jax-ml/jax#current-gotchas for more.","messagePattern":"Explicitly requested dtype (.+?)(.+?) is not available, and will be truncated to dtype (.+?)\\. To enable more dtypes, set the jax_enable_x64 configuration option or the JAX_ENABLE_X64 shell environment variable\\. See https://github\\.com/jax-ml/jax#current-gotchas for more\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"jax/_src/dtypes.py","lineNumber":980,"sourceCode":"  canonical_dtype = canonicalize_dtype(dtype)\n  if canonical_dtype == dtype:\n    return dtype\n  fun_name = f\" requested in {fun_name}\" if fun_name else \"\"\n  if allow == config.ExplicitX64Mode.ERROR:\n    msg = (\"Explicitly requested dtype {}{} is not available. To enable more \"\n           \"dtypes, set the jax_enable_x64 or allow_explicit_x64_dtypes \"\n           \"configuration options.\"\n          \"See https://github.com/jax-ml/jax#current-gotchas for more.\")\n    msg = msg.format(dtype, fun_name, canonical_dtype.name)\n    raise ValueError(msg)\n  else:  # WARN\n    msg = (\"Explicitly requested dtype {}{} is not available, \"\n          \"and will be truncated to dtype {}. To enable more dtypes, set the \"\n          \"jax_enable_x64 configuration option or the JAX_ENABLE_X64 shell \"\n          \"environment variable. \"\n          \"See https://github.com/jax-ml/jax#current-gotchas for more.\")\n    msg = msg.format(dtype, fun_name, canonical_dtype.name)\n    warnings.warn(msg, stacklevel=4)\n    return canonical_dtype\n\n\n_types_whose_dtype_should_not_be_canonicalized: tuple[type, ...] = (\n    Array,\n)\n\ndef register_type_whose_dtype_should_not_be_canonicalized(typ: type):\n  global _types_whose_dtype_should_not_be_canonicalized\n  _types_whose_dtype_should_not_be_canonicalized += (typ,)\n\ndef dtype(x: Any) -> DType:\n  \"\"\"Return the dtype object for a value or type.\n\n  Python scalars, Python scalar types, NumPy scalar type, NumPy dtypes, and\n  non-JAX arrays will have their dtypes canonicalized.\n\n  Note: this is not the same function as jax.numpy.dtype, which simply aliases","sourceCodeStart":962,"sourceCodeEnd":998,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/dtypes.py#L962-L998","documentation":"You explicitly requested a 64-bit dtype (e.g. float64/int64/complex128) but JAX's x64 mode is disabled (the default), so the dtype is truncated to its 32-bit canonical equivalent (float32/int32/complex64). JAX warns so silent precision loss doesn't go unnoticed.","triggerScenarios":"Passing dtype=jnp.float64 (or int64/uint64/complex128) to jnp.array, jnp.zeros, jax.random functions, searchsorted, etc., without jax_enable_x64=True; every explicit 64-bit request goes through _maybe_canonicalize_explicit_dtype and warns.","commonSituations":"Porting NumPy code that assumes int64 indices/default float64; scientific computing needing double precision; ML pipelines where silent downcast breaks numerics.","solutions":["Enable 64-bit mode at startup: jax.config.update('jax_enable_x64', True) (or export JAX_ENABLE_X64=true) before any JAX arrays are created.","If 32-bit is acceptable, change the requested dtype to float32/int32/complex64 to silence the warning.","Note x64 must be enabled before arrays/tracers are created; changing it late has no effect on existing arrays."],"exampleFix":"# before\nimport jax.numpy as jnp\nx = jnp.array([1.5, 2.5], dtype=jnp.float64)  # truncated to float32\n# after\nimport jax\njax.config.update('jax_enable_x64', True)\nimport jax.numpy as jnp\nx = jnp.array([1.5, 2.5], dtype=jnp.float64)  # true float64","handlingStrategy":"validation","validationCode":"import jax\nassert jax.config.jax_enable_x64 or not any(str(d).endswith('64') and 'complex' not in str(d) or str(d)=='complex128' for d in []), 'x64 off'\n# simpler: check before using 64-bit dtypes\nif not jax.config.jax_enable_x64:\n    raise SystemExit('enable x64 before using float64/int64')","typeGuard":"import jax.numpy as jnp\ndef is_64bit_available(dtype) -> bool:\n    import jax\n    return jax.config.jax_enable_x64 or jnp.zeros((), dtype=dtype).dtype == dtype","tryCatchPattern":"with warnings.catch_warnings(record=True) as w:\n    warnings.simplefilter('always')\n    x = jnp.array(vals, dtype=jnp.float64)\nif any('truncated to dtype' in str(i.message) for i in w):\n    # precision silently lost — enable x64 and rebuild arrays","preventionTips":["Call jax.config.update('jax_enable_x64', True) at program start, before any arrays.","Set JAX_ENABLE_X64=true in the environment for the whole job.","Assert on this warning in numerical-precision-sensitive tests."],"tags":["jax","dtype","precision","x64"],"backgroundTag":"dtype-precision-loss","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}