Pathways is a distributed runtime for [JAX](https://docs.jax.dev/en/latest/)
that uses a single-controller execution model to orchestrate large-scale,
multitask, and sparsely activated machine learning (ML) workloads across one or
more TPU slices. It lets a single Python process (the controller) coordinate
computations across thousands or tens of thousands of TPU chips and dynamically
allocate compute across tasks.

Instead of running a separate copy of your Python program on every TPU VM, your
JAX workload runs in a **client CPU process** (the controller) and communicates
over gRPC with a Pathways control plane on a **CPU head node**, which is a
dedicated CPU-only VM in your cluster that hosts the Pathways coordination and
compilation services. The control plane compiles your code and dispatches
computations to Pathways workers running on your TPU VMs.

Google uses Pathways internally to train large models such as Gemini.
Pathways on Cloud brings the same architecture to Google Cloud customers.

## Before you begin

You can run Pathways on Google Kubernetes Engine (GKE) or on a
[Cluster Director](https://cloud.google.com/products/cluster-director)
cluster with Slurm. Select the tab for your platform to see the prerequisites.

### GKE

Complete the following prerequisites:

- [Install Kubernetes tools](https://kubernetes.io/docs/tasks/tools/).
- [Install the Google Cloud CLI](https://docs.cloud.google.com/sdk/docs/install).
- [Enable the
  Kubernetes Engine API](https://console.cloud.google.com/flows/enableapi?apiid=container.googleapis.com).

This document assumes that you're already familiar with using
[TPUs in GKE](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/tpus.md.txt#type-node-pool),
including both single-slice and
[multislice TPUs on GKE](https://docs.cloud.google.com/kubernetes-engine/docs/how-to/tpu-multislice.md.txt),
and have general experience with
[multislice TPUs](https://docs.cloud.google.com/tpu/docs/multislice-introduction.md.txt).

To create a cluster, see
[Create a GKE cluster with
Pathways](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/pathways-on-cloud/create-gke-cluster).

### Cluster Director

Complete the following prerequisites:

- [Install the gcloud CLI](https://docs.cloud.google.com/sdk/docs/install).
- [Enable the
  Hypercompute Cluster API](https://console.cloud.google.com/flows/enableapi?apiid=hypercomputecluster.googleapis.com).

This document assumes that you're already familiar with
[Cluster Director](https://docs.cloud.google.com/cluster-director/docs/overview.md.txt),
[TPU machines in Cluster Director](https://docs.cloud.google.com/cluster-director/docs/tpu-machines.md.txt),
and running jobs with [Slurm](https://docs.cloud.google.com/cluster-director/docs/orchestration.md.txt) and
have general experience with
[multislice TPUs](https://docs.cloud.google.com/tpu/docs/multislice-introduction.md.txt).

To create a cluster, see
[Create a Cluster Director cluster with
Pathways](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/pathways-on-cloud/create-cluster-director-cluster).

## Single-controller and multi-controller

Distributed ML workloads on TPUs use either a multi-controller execution model
(the default in JAX) or a single-controller execution model (used by Pathways).
The two models differ in where your Python code runs, how your program views
accelerators, and how workloads are coordinated across TPU slices.

### Multi-controller workloads (JAX default)

In the multi-controller model, every TPU VM in your TPU slices runs the same
Python script. Each TPU VM acts as an independent controller for the TPU chips
directly attached to that host. Multi-controller workloads have the following
characteristics:

- **Distributed control**: Every TPU VM executes a copy of your Python script in lockstep and coordinates collective operations across processes.
- **Localized device view** : Each Python process directly manages only the TPU chips attached to its local VM (`jax.local_devices()`), while `jax.devices()` lists all devices across the cluster.
- **Single program, multiple data (SPMD) execution**: Because every host runs the same script simultaneously, multi-controller workloads primarily follow the SPMD paradigm. Orchestrating different operations on different subsets of TPU slices requires custom multi-host coordination logic.
- **Host-coupled lifecycle**: Because the Python controllers run directly on the TPU VMs, if any TPU VM is preempted or fails, all controller processes must stop and restart together.

### Single-controller workloads (Pathways)

In the Pathways single-controller model, a single Python process acts as the
central controller for your entire workload. Your JAX program (the controller)
runs on a CPU host, such as a batch container on a CPU head node or an external
client VM, and communicates with the Pathways runtime over gRPC instead of
running directly on your TPU VMs. Single-controller workloads have the following characteristics:

- **Centralized control**: You run and monitor one Python controller process that dispatches computations to the Pathways runtime, which manages execution across all TPU VMs.
- **Unified device view** : Your JAX program sees all TPU slices as a single unified system. In your code, `jax.process_index()` is always `0`, and both `jax.devices()` and `jax.local_devices()` return every TPU chip across all allocated slices as if they were attached to one large machine.
- **Flexible computation patterns**: In addition to standard SPMD training, a single controller can schedule different computations across distinct subsets of accelerators, supporting asymmetrical pipeline parallelism, multitask workloads, and computational sparsity.
- **Decoupled controller lifecycle** : Because your Python program runs outside the TPU VMs, the controller process can stay running while the Pathways resource manager recovers or replaces preempted TPU slices. When you do need to run host-local Python code on the TPU VMs---such as high-throughput data loading, preprocessing, or checkpointing---you can use [colocated Python](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/pathways-on-cloud/colocated-python.md.txt) to execute specific Python functions on the TPU host CPUs through a sidecar server.

## Pathways components

The Pathways architecture distributes components across three environments: your
client CPU environment, a CPU head node, and the TPU worker VMs. The following
diagram illustrates how these components interact and where each component runs:
[![Architecture diagram showing how the user JAX program and embedded
IFRT proxy client communicate with the IFRT proxy server, embedded
Pathways client, and Pathways resource manager on the CPU head node, and
how those components dispatch work to the Pathways worker, optional
sidecar server, and attached Cloud TPU chips on each Cloud TPU worker
VM.](https://docs.cloud.google.com/ai-hypercomputer/images/pathways-components.png)](https://docs.cloud.google.com/ai-hypercomputer/images/pathways-components.png) Pathways components and host placement

### Client CPU environment

Runs in a workload container on the CPU head node (typical for batch jobs on
GKE), or in a separate client container, Slurm job, or external
CPU VM (for interactive workloads or Cluster Director):

- **User program (controller)**: Your Python JAX process, which defines your model, training loop, and device sharding and sees all TPU chips across slices as local devices.
- **IFRT proxy client** : An open-source [Interim Framework Runtime (IFRT)](https://github.com/openxla/xla/blob/main/xla/python/ifrt/README.md) library embedded in your JAX process. When you import `pathwaysutils` and set `JAX_PLATFORMS=proxy`, it decouples your code from the underlying runtime and sends requests over [gRPC](https://grpc.io/) to the IFRT proxy server.

### CPU head node

Runs on a dedicated CPU-only VM in your cluster (a CPU node pool node on
GKE, or a CPU compute node on Cluster Director):

- **IFRT proxy server** : A [gRPC](https://grpc.io/) server container that receives requests from the IFRT proxy client and forwards them to its embedded Pathways client library.
- **Pathways client** : An [IFRT](https://github.com/openxla/xla/blob/main/xla/python/ifrt/README.md) runtime library embedded inside the IFRT proxy server container. It sends High-Level Optimizer (HLO) programs to the compilation service in the Pathways resource manager and coordinates placement over gRPC. It then dispatches execution requests and tensor data to Pathways workers and presents a unified device view to JAX.
- **Pathways resource manager** : The central control plane container. It manages accelerator slices, monitors worker health, schedules jobs, and hosts the Pathways compilation service, which compiles HLO programs into XLA executables stored in the compilation cache under `--gcs_scratch_location`.

### Cloud TPU worker VMs

Each TPU worker VM manages its attached Cloud TPU chips (which execute compiled
XLA computations) through host CPU containers:

- **Pathways worker**: Loads compiled executables from the compilation cache and receives execution requests and tensor data from the Pathways client over gRPC. It runs computations on the attached Cloud TPU chips, exchanges data with other workers over high-speed interconnects, and reports health to the resource manager.
- **Sidecar server** (optional, GKE only): A gRPC container (`colocated-python-sidecar`) that runs user-specified Python functions (such as data loading and checkpointing) on the TPU VM. It exchanges tensor buffers with the local Pathways worker through zero-copy shared host memory. See [Run colocated Python with Pathways](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/pathways-on-cloud/colocated-python.md.txt).

## Pathways components on GKE

On GKE, the `pathways-head` Pod runs on a CPU node pool and hosts
`pathways-rm` and `pathways-proxy` (plus your batch workload container, when
applicable). Each TPU worker Pod runs `worker` (or `pathways-worker`) and, when
colocated Python is enabled, `colocated-python-sidecar`.

You can find Pathways container images at the following locations:

| Container type | Location |
|---|---|
| IFRT proxy server | `us-docker.pkg.dev/cloud-tpu-v2-images/cloud-pathways/proxy_server:jax-JAX_VERSION` |
| Pathways resource manager and worker | `us-docker.pkg.dev/cloud-tpu-v2-images/cloud-pathways/server:jax-JAX_VERSION` |
| Colocated Python sidecar (optional) | `us-docker.pkg.dev/cloud-tpu-v2-images/cloud-pathways/colocated_python_sidecar:jax-JAX_VERSION` |

### Pathways resource manager

After you
[create a GKE cluster](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/pathways-on-cloud/create-gke-cluster.md.txt),
you can use the following `containerSpec` to deploy the Pathways resource
manager:

```yaml
  - name: pathways-rm
    image: us-docker.pkg.dev/cloud-tpu-v2-images/cloud-pathways/server:latest
    imagePullPolicy: Always
    env:
    - name: HOST_ADDRESS
      valueFrom:
        fieldRef:
          fieldPath: "metadata.labels['jobset.sigs.k8s.io/coordinator']"
    - name: TPU_SKIP_MDS_QUERY
      value: "true"
    args:
    - --server_port=29001
    - --node_type=resource_manager
    - --instance_count=WORKLOAD_NODEPOOL_COUNT
    - --instance_type=SLICE_TOPOLOGY
    - --gcs_scratch_location=gs://BUCKET_NAME
```

Replace the following:

- `WORKLOAD_NODEPOOL_COUNT`: the number of TPU slices.
- `SLICE_TOPOLOGY`: the TPU type and topology of the slice, in the format `tpuTPU_TYPE:TOPOLOGY`---for example, `tpuv5e:4x4`.
- `BUCKET_NAME`: the Cloud Storage bucket used for temporary files.

The container also uses the following arguments:

- `--server_port`: the port that the Pathways resource manager uses to communicate with other Pathways components (`29001` in this example).
- `--node_type`: the node type. Set this argument to `resource_manager` for the Pathways resource manager. It isn't needed for the other containers.

### IFRT proxy server

You can use the following `containerSpec` to deploy an IFRT proxy server:

```yaml
  - name: pathways-proxy
    image: us-docker.pkg.dev/cloud-tpu-v2-images/cloud-pathways/proxy_server:latest
    imagePullPolicy: Always
    env:
    - name: PATHWAYS_HEAD
      valueFrom:
        fieldRef:
          fieldPath: "metadata.labels['jobset.sigs.k8s.io/coordinator']"
    args:
    - --resource_manager_address=$(PATHWAYS_HEAD):29001
    - --server_port=29000
    - --gcs_scratch_location=gs://BUCKET_NAME
    ports:
    - containerPort: 29000
```

Replace `BUCKET_NAME` with the name of the
Cloud Storage bucket used for temporary files.

The container also uses the following arguments:

- `--resource_manager_address`: the hostname and port that the proxy server uses to communicate with the Pathways resource manager. The port must match the `--server_port` value used for the Pathways resource manager container.
- `--server_port`: the port that the IFRT proxy server uses to communicate with the IFRT proxy client (`29000` in this example).
- `--gcs_scratch_location`: the Cloud Storage path used for temporary files.

### Pathways worker

You can use the following `containerSpec` to deploy Pathways workers:

```yaml
- name: worker
  image: us-docker.pkg.dev/cloud-tpu-v2-images/cloud-pathways/server:latest
  imagePullPolicy: Always
  env:
  - name: PATHWAYS_HEAD
    valueFrom:
      fieldRef:
        fieldPath: "metadata.labels['jobset.sigs.k8s.io/coordinator']"
  - name: MEGASCALE_NUM_SLICES
    valueFrom:
      fieldRef:
        fieldPath: "metadata.labels['jobset.sigs.k8s.io/replicatedjob-replicas']"
  - name: MEGASCALE_SLICE_ID
    valueFrom:
      fieldRef:
        fieldPath: "metadata.labels['jobset.sigs.k8s.io/job-index']"
  - name: MEGASCALE_COORDINATOR_ADDRESS
    value: "$(PATHWAYS_HEAD)"
  args:
  - --server_port=29001
  - --resource_manager_address=$(PATHWAYS_HEAD):29001
  - --gcs_scratch_location=gs://BUCKET_NAME
  ports:
  - containerPort: 29001
  resources:
    limits:
      google.com/tpu: "4"
```

Replace `BUCKET_NAME` with the name of the
Cloud Storage bucket used for temporary files.

The container also uses the following arguments:

- `--server_port`: the port that the workers use to communicate with the proxy server and Pathways resource manager (`29001` in this example).
- `--resource_manager_address`: the hostname and port that the TPU workers use to communicate with the Pathways resource manager. The port must match the `--server_port` value used for the Pathways resource manager container.
- `--gcs_scratch_location`: the Cloud Storage path used for temporary files.

The Pathways resource manager, IFRT proxy server, and Pathways workers can all
have different ports, but in this example, the Pathways resource manager and the
Pathways worker share the same port.

## Pathways components on Cluster Director

This section maps Pathways components to Slurm jobs on a
Cluster Director cluster.

The Pathways scripts run the Pathways components with Enroot. The `setup_env.sh`
script uses the following container images, which match the JAX version
(`0.11.1`) of the Python environment that it builds:

| Container type | Location |
|---|---|
| IFRT proxy server | `us-docker.pkg.dev/cloud-tpu-v2-images/cloud-pathways/proxy_server:jax-0.11.1` |
| Pathways resource manager and worker | `us-docker.pkg.dev/cloud-tpu-v2-images/cloud-pathways/server:jax-0.11.1` |

You start the Pathways components by submitting the `start_pathways.sh` script
as the Pathways service job. You don't write the following commands yourself.
The scripts derive the arguments from the environment variables that you set
when you submit `start_pathways.sh`, such as `SLICE_SHAPE`, `MIN_SLICES`,
`MAX_SLICES`, and `GCS_BUCKET`.

### Pathways resource manager

The Pathways service job runs the Pathways resource manager on one CPU node.
It runs the following command in the Pathways server container:

```bash
/pathways/server \
    --server_port=29001 \
    --node_type=resource_manager \
    --instance_type=tpuTPU_TYPE:TOPOLOGY \
    --instance_count=MAX_SLICES \
    --gcs_scratch_location=gs://BUCKET_NAME/pathways-scratch/shared \
    --enable_gcs_olm=false
```

The script populates the following placeholders in the command:

- `TPU_TYPE` and `TOPOLOGY`: the TPU type and topology of each slice, derived from `SLICE_SHAPE`---for example, `SLICE_SHAPE=2x4` sets `tpuv6e:2x4`.
- `MAX_SLICES`: the maximum number of TPU slices, from `MAX_SLICES`.
- `BUCKET_NAME`: your Cloud Storage bucket name, from `GCS_BUCKET`.

The command uses the following arguments:

- `--server_port`: the port that the Pathways resource manager listens on. The IFRT proxy server and the Pathways workers connect to this port.
- `--node_type`: the node type, `resource_manager`. Only the Pathways resource manager sets this argument.
- `--instance_type`: the TPU type and topology of each slice.
- `--instance_count`: the number of TPU slices.
- `--gcs_scratch_location`: the Cloud Storage path used for temporary files such as the compilation cache.
- `--enable_gcs_olm`: whether Pathways creates Cloud Storage object lifecycle rules to clean up old compilation cache entries. The script turns this off because it requires additional permissions on the bucket.

### IFRT proxy server

The Pathways service job runs the IFRT proxy server on the same CPU node as the
Pathways resource manager. It runs the following command in the IFRT proxy
server container:

```bash
/pathways/proxy_server \
    --server_port=29000 \
    --resource_manager_address=RM_IP:29001 \
    --gcs_scratch_location=gs://BUCKET_NAME/pathways-scratch/shared \
    --num_elastic_instances=MAX_SLICES
```

The script populates the following placeholders in the command:

- `RM_IP`: the internal IP address of the CPU node running the Pathways resource manager.
- `BUCKET_NAME`: your Cloud Storage bucket name, from `GCS_BUCKET`.
- `MAX_SLICES`: the maximum number of TPU slices, from `MAX_SLICES`.

The command uses the following arguments:

- `--server_port`: the port that the IFRT proxy server listens on. Your JAX program connects to this port.
- `--resource_manager_address`: the address and port of the Pathways resource manager.
- `--gcs_scratch_location`: the same Cloud Storage path as the Pathways resource manager.
- `--num_elastic_instances`: the number of slices that can be unavailable without stopping the IFRT proxy session, from `MAX_SLICES`. Your workload enforces `MIN_SLICES`.

When at least `MIN_SLICES` slices are running, the service job writes the IFRT
proxy server address to `~/pathways/cluster.env`. Your JAX program, the IFRT
proxy client, reads this file to connect to Pathways. The JAX program runs as
your workload---for example, `run_maxtext.sh`---or in a Jupyter notebook.

### Pathways worker

The Pathways service job submits a Slurm job array (`run_worker_slice.sh`) with
one array task for each TPU slice. Each array task runs the following command
in the Pathways server container on every TPU VM in its slice:

```bash
/pathways/server \
    --server_port=29001 \
    --resource_manager_address=RM_IP:29001 \
    --gcs_scratch_location=gs://BUCKET_NAME/pathways-scratch/shared \
    --enable_gcs_olm=false
```

The script populates `RM_IP` with the internal IP address
of the CPU node and `BUCKET_NAME` with your
Cloud Storage bucket name.

The command uses the following arguments:

- `--server_port`: the port that the Pathways worker listens on. The Pathways resource manager and the IFRT proxy server connect to this port.
- `--resource_manager_address`: the address of the Pathways resource manager, the same as for the IFRT proxy server.
- `--gcs_scratch_location` and `--enable_gcs_olm`: the same as for the [Pathways resource manager](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/pathways-on-cloud/pathways-intro.md.txt#pathways-resource-manager-cluster-director).

The script also sets the TPU topology and `MEGASCALE_*` environment variables
for each worker from the slice's nodes and the array task index.

If a TPU slice is preempted or fails, Slurm requeues its array task. If you
have [passwordless
`sudo`](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/pathways-on-cloud/create-cluster-director-cluster#before-you-begin)
on the cluster nodes, the service job also powers down the slice's nodes so that
Slurm can recreate them. The Pathways resource manager and IFRT proxy server
keep running, so your JAX program doesn't need to connect to a new address.

## What's next

- [Create a GKE cluster with
  Pathways](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/pathways-on-cloud/create-gke-cluster)
- [Create a Cluster Director cluster with
  Pathways](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/pathways-on-cloud/create-cluster-director-cluster)
- [Run a batch workload with
  Pathways](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/pathways-on-cloud/batch-workload)
- [Run an interactive workload with
  Pathways](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/pathways-on-cloud/pathways-interactive-mode)
- [Resilient training with
  Pathways](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/pathways-on-cloud/resilient-training)
- [Port JAX workloads to
  Pathways](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/pathways-on-cloud/porting-jax-workloads)
- [Run colocated Python with
  Pathways](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/pathways-on-cloud/colocated-python)
- [Troubleshoot Pathways on
  Cloud](https://docs.cloud.google.com/ai-hypercomputer/docs/workloads/pathways-on-cloud/troubleshooting-pathways)
- [Run workloads with Pathways in
  Cluster Toolkit](https://docs.cloud.google.com/cluster-toolkit/docs/deploy/gke/run-workloads-pathways)