jax-ml/jax · error · ValueError
Number of processes must be defined.
Error message
Number of processes must be defined.
What it means
jax.distributed.initialize requires num_processes (total world size) to be explicitly set; it has no default. Omitting it raises this ValueError before any connection is attempted.
Source
Thrown at jax/_src/distributed.py:139
local_device_ids = list(map(int, env_ids.split(",")))
if (cluster_detection_method != 'deactivate' and
None in (coordinator_address, num_processes, process_id, local_device_ids)):
(coordinator_address, num_processes, process_id, local_device_ids) = (
clusters.ClusterEnv.auto_detect_unset_distributed_params(
coordinator_address,
num_processes,
process_id,
local_device_ids,
cluster_detection_method,
initialization_timeout,
)
)
if coordinator_address is None:
raise ValueError('coordinator_address should be defined.')
if num_processes is None:
raise ValueError('Number of processes must be defined.')
if process_id is None:
raise ValueError('The process id of the current process must be defined.')
if not isinstance(process_id, int):
raise TypeError("process_id must be a nonnegative int. "
f"Got process_id={process_id} of type {type(process_id)}.")
if not isinstance(num_processes, int):
raise TypeError("num_processes must be a positive int. "
f"Got num_processes={num_processes} of type {type(num_processes)}.")
if not (0 <= process_id < num_processes):
raise ValueError("process_id and num_processes must be nonnegative, with process_id < num_processes. "
f"Got process_id={process_id}, num_processes={num_processes}.")
self.coordinator_address = coordinator_address
# The default value of [::]:port tells the coordinator to bind to all
# available addresses on the same port as coordinator_address.
default_coordinator_bind_address = '[::]:' + coordinator_address.rsplit(':', 1)[1]
coordinator_bind_address = (coordinator_bind_address orView on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Pass num_processes equal to the launcher's world size, e.g. int(os.environ['NRANKS']) or WORLD_SIZE
- Use a cluster_detection_method that infers process counts (slurm/torchrun)
- Double-check that every process passes the same num_processes value
Example fix
# before
jax.distributed.initialize(coordinator_address=addr)
# after
jax.distributed.initialize(coordinator_address=addr,
num_processes=int(os.environ['WORLD_SIZE']),
process_id=int(os.environ['RANK'])) Defensive patterns
Strategy: validation
Validate before calling
import os
np_ = int(os.environ.get('WORLD_SIZE', os.environ.get('NRANKS', 0)))
assert np_ > 0, 'num_processes unresolved' Prevention
- Derive world size from the launcher, never hardcode partially
- Assert all three (address, num_processes, process_id) before initialize
When it happens
Trigger: jax.distributed.initialize(coordinator_address=...) without num_processes; passing num_processes=None explicitly.
Common situations: Single-script multi-GPU launches where the user assumed JAX infers world size; missing plumbing from torchrun/mpirun env vars (NRANKS/WORLD_SIZE).
Understand the failure class
Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.
Related errors
- coordinator_address should be defined.
- The process id of the current process must be defined.
- num_processes must be a positive int. Got num_processes={num
- Mapped away dimension of inputs passed to vmap should be sha
- invalid truth value {val!r} for environment {varname!r}
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/efddeefc2771f1fa.
Report an issue: GitHub.