get_jax_env_vars#

ray.util.tpu.get_jax_env_vars(worker_hostnames: str | List[str], worker_id: int | None = None, process_bounds: str | None = None, chips_per_process_bounds: str | None = None) → Dict[str, str][source]#

Returns the JAX / libtpu environment variables for one host of a TPU slice.

Works for full slices and subslices, and assumes one JAX process per TPU host (worker_id in 0..num_hosts - 1). TPU_PROCESS_PORT is taken from the calling process’s environment, falling back to 8471.

Parameters:
  • worker_hostnames (str | List[str]) – Comma-separated string or list of host IP addresses or DNS hostnames. Ports (e.g. “10.0.0.1:8471”) are stripped, since libtpu expects bare hostnames.

  • worker_id (int | None) – Optional integer ID of the worker host (0-indexed). Defaults to 0 for a single host; when omitted on multiple hosts, TPU_WORKER_ID is not set (valid for full slices whose hosts already have matching TPU_WORKER_ID in their environment).

  • process_bounds (str | None) – Optional process bounds string (e.g. “1,2,1”) for subslice execution.

  • chips_per_process_bounds (str | None) – Optional chips per process bounds string (e.g. “2,2,1”).

Returns:

A dictionary mapping JAX / libtpu environment variables to their values.

Raises:

ValueError – If no hosts are provided or if worker_id is out of bounds.

Return type:

Dict[str, str]

PublicAPI (alpha): This API is in alpha and may change before becoming stable.