jax-ml/jax · error · RuntimeError

Backend already initialized

Error message

Backend {name} already initialized

What it means

Raised by register_backend_factory when a backend factory for `name` is registered after that backend has already been initialized; backend factories are only consulted at init time, so late registration would silently have no effect.

Solutions

  1. Register backend factories before any JAX operation triggers backend initialization
  2. Set JAX_PLATFORMS (or jax.config.update('jax_platforms', ...)) at program start instead of registering backends later
  3. Restart the process if a factory must be (re-)registered after initialization
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at jax/_src/xla_bridge.py:307 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/d0594bd30c4de243. Report an issue: GitHub.

Appendix: source

Thrown at jax/_src/xla_bridge.py:307

# Send a PR if you would like to be added.
#
# It is fine for a plugin not to implement every feature that JAX uses, provided
# that a reasonable feature set is implemented and the plugin fails gracefully
# for unimplemented features. Wrong outputs are not acceptable.
_nonexperimental_plugins: set[str] = {'cuda', 'rocm'}

# The set of known experimental plugins that have registrations in JAX codebase.
_experimental_plugins: set[str] = {"oneapi"}

def register_backend_factory(name: str, factory: BackendFactory, *,
                             priority: int = 0,
                             fail_quietly: bool = True,
                             experimental: bool = False,
                             make_topology: TopologyFactory | None = None,
                             c_api: Any | None = None) -> None:
  with _backend_lock:
    if name in _backends:
      raise RuntimeError(f"Backend {name} already initialized")
  _backend_factories[name] = BackendRegistration(
    factory, priority, fail_quietly, experimental, c_api)
  if make_topology is not None:
    _topology_factories[name] = make_topology


def make_cpu_client(
    collectives: _jax.CpuCollectives | None = None,
) -> xla_client.Client:
  """Creates a CPU client with the requested collectives implementation.

  The implementation of CPU collectives used by the client is determined by the
  flag `--jax_cpu_collectives_implementation` - unless `collectives` is
  provided, in which case the flag is overridden and `collectives` is used.

  Args:
    collectives: An optional CPU collectives implementation, used by the client
      if provided.

View on GitHub (pinned to 1e1c6a8fc0)