{"record":{"id":"ccaab44e822c2523","repo":"jax-ml/jax","slug":"prng-key-seed-must-be-an-integer-got-seed-r","errorCode":null,"errorMessage":"PRNG key seed must be an integer; got {seed!r}","messagePattern":"PRNG key seed must be an integer; got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/random/philox2x32.py","lineNumber":143,"sourceCode":"  \"\"\"Return True if the input is a valid Philox 2x32 PRNG key.\"\"\"\n  try:\n    return key.shape == (1,) and key.dtype == np.uint32\n  except AttributeError:\n    return False\n\n\ndef philox2x32_seed(seed: typing.Array) -> typing.Array:\n  \"\"\"Create a single Philox 2x32 PRNG key from an integer seed.\"\"\"\n  return _philox2x32_seed(seed)\n\n\n@api.jit(inline=True)\ndef _philox2x32_seed(seed: typing.Array) -> typing.Array:\n  \"\"\"Internal implementation of philox2x32_seed.\"\"\"\n  if seed.shape:\n    raise TypeError(f\"PRNG key seed must be a scalar; got {seed!r}.\")\n  if not np.issubdtype(seed.dtype, np.integer):\n    raise TypeError(f\"PRNG key seed must be an integer; got {seed!r}\")\n  convert = lambda k: lax.convert_element_type(k, np.uint32)\n  k0 = convert(\n      lax.shift_right_logical(seed, lax.convert_element_type(32, seed.dtype))\n  )\n  with config.numpy_dtype_promotion(\"standard\"):\n    k1 = convert(jnp.bitwise_and(seed, np.uint32(0xFFFFFFFF)))\n  # Hash through philox2x32 to mix the seed bits into a 1-word key.\n  # Use both seed halves as counter words so they both influence the output.\n  out0, _ = philox2x32_p.bind(np.uint32(0), k0, k1)\n  return jnp.array([out0], dtype=np.uint32)\n\n\ndef philox2x32_split(key: typing.Array, shape: prng.Shape) -> typing.Array:\n  \"\"\"Split a Philox 2x32 PRNG key into multiple sub-keys.\"\"\"\n  shape = tuple(map(core.concrete_dim_or_error, shape))\n  return _philox2x32_split(key, shape)\n\n","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/random/philox2x32.py#L125-L161","documentation":"When constructing a Philox 2x32 PRNG key, the seed must have an integer dtype (np.issubdtype(seed.dtype, np.integer)). Float, bool, or complex seeds raise this TypeError because the seed is bit-split into uint32 halves.","triggerScenarios":"jax.random.PRNGKey(42.0) or PRNGKey(np.float32(7)) with the philox2x32 implementation; passing a Python bool.","commonSituations":"Seeds loaded from JSON/config as floats; time-based seeds like time.time() passed directly; bool seeds from flag variables.","solutions":["Cast to an integer before use: int(seed) or np.uint64(seed)","Use jax.random.PRNGKey with an int (the top-level API also accepts uint64 shapes, but keep it integral)","Store seeds as int in configs to avoid silent rounding when casting floats"],"exampleFix":"# before\nkey = jax.random.PRNGKey(42.0)\n# after\nkey = jax.random.PRNGKey(int(42.0))","handlingStrategy":"validation","validationCode":"import numpy as np\nseed = int(seed) if not np.issubdtype(np.asarray(seed).dtype, np.integer) else seed\nkey = jax.random.PRNGKey(seed)","typeGuard":"def is_integer_seed(seed) -> bool:\n    import numpy as np\n    return np.issubdtype(np.asarray(seed).dtype, np.integer)","tryCatchPattern":null,"preventionTips":["Never pass time.time() directly — wrap int(time.time())","Centralize seed coercion in one helper"],"tags":["jax","prng","seed","dtype-validation"],"backgroundTag":"prng-seed-validation","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}