get_torchtpu_env_vars#
- ray.util.tpu.get_torchtpu_env_vars(topology: str, worker_hostnames: str | List[str] | None = None, worker_id: int | None = None, slicebuilder_addresses: str | List[str] | None = None, slicebuilder_port: int = 8471, master_addr: str | None = None, tpu_resource_per_chip: int = 1, accelerator_type: str | None = None) Dict[str, str][source]#
Returns environment variables required for PyTorch/TPU (torch_tpu) execution.
Derived
TORCH_TPU_SLICEBUILDER_ADDRESSESentries are ordered host-major acrossworker_hostnameswithdevices_per_hostsequential ports per host starting atslicebuilder_port(torch_tpuindexesaddresses[RANK % len(addresses)]). Standardtorch.distributedrank variables (RANK,LOCAL_RANK,WORLD_SIZE,MASTER_PORT) are set by the caller or launcher (such astorchrun), and multi-slice workloads pair this withget_tpu_coordinator_env_vars().- Parameters:
topology (str) – The target TPU topology string (e.g. “4x4”, “2x4”, or “4,4,1”).
worker_hostnames (str | List[str] | None) – Optional comma-separated string or list of host IP addresses or DNS hostnames. When both
worker_hostnamesandslicebuilder_addressesare omitted, onlyTORCH_TPU_TOPOLOGY(plusMASTER_ADDRorTPU_WORKER_IDif explicitly passed) is returned for pairing with ambient container environment variables.worker_id (int | None) – Optional integer ID of the worker host (0-indexed, for passing to
torchrun-style launchers as--node_rank/NODE_RANK). Defaults to 0 for a single host; when omitted on multiple hosts,TPU_WORKER_IDis not set.slicebuilder_addresses (str | List[str] | None) – Optional comma-separated string or list of address:port strings. If omitted, derived from
worker_hostnamesandslicebuilder_port.slicebuilder_port (int) – Base port number for slicebuilder addresses (defaults to 8471).
master_addr (str | None) – Optional IP address or hostname of the rank-0 master node. If omitted, defaults to the first worker hostname.
tpu_resource_per_chip (int) – Logical TPU resources per physical chip (defaults to 1).
accelerator_type (str | None) – Optional TPU accelerator version or type (e.g. “v6e”, “v7x”).
- Returns:
A dictionary mapping PyTorch/TPU environment variables to their values.
- Raises:
TypeError – If
worker_id,slicebuilder_port, ortpu_resource_per_chipis not an integer.ValueError – If
topology,worker_hostnames,slicebuilder_addresses,slicebuilder_port,master_addr,worker_id, ortpu_resource_per_chipis invalid.
- Return type:
PublicAPI (alpha): This API is in alpha and may change before becoming stable.