get_torchtpu_env_vars#

SlicePlacementGroup.get_torchtpu_env_vars(worker_id: int | None = None, slice_index: int = 0, worker_hostnames: str | List[str] | None = None, slicebuilder_addresses: str | List[str] | None = None, slicebuilder_port: int = 8471, master_addr: str | None = None) → Dict[str, str][source]#

Returns the PyTorch/TPU (torch_tpu) environment variables for this slice.

See get_torchtpu_env_vars() for details on address ordering and required torch.distributed rank variables.

Parameters:
  • worker_id (int | None) – Optional integer ID of the worker within the slice (0-indexed), between 0 and hosts_per_slice - 1. Defaults to 0 on a single-host slice; when omitted on a multi-host slice, TPU_WORKER_ID is not set.

  • slice_index (int) – The 0-based index of the TPU slice.

  • worker_hostnames (str | List[str] | None) – Optional comma-separated string or list of host IP addresses or DNS hostnames. If omitted, resolved from placement group bundles in this slice.

  • slicebuilder_addresses (str | List[str] | None) – Optional explicit comma-separated string or list of address:port strings for this slice.

  • 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, slice 0 uses its first worker hostname and other slices resolve the placed IP of slice 0’s host 0 (pass spg.get_worker_addrs(slice_index)[0] once that slice is ready when running independent single-slice worlds).

Returns:

A dictionary mapping PyTorch/TPU environment variables to their values.

Raises:
  • TypeError – If worker_id or slicebuilder_port is not an integer.

  • ValueError – If slice_index, worker_id, or any address or port argument is invalid.

  • RuntimeError – If worker hostnames or slice 0’s master address cannot be resolved.

Return type:

Dict[str, str]