# Frequently Asked Questions - Cloud TPU

This document contains a list of frequently asked questions about Cloud TPUs. It
is broken up into sections:

1. Framework independent FAQs - questions about using Cloud TPUs regardless of what ML framework you are using.
2. JAX FAQs - questions about using Cloud TPUs with JAX.
3. PyTorch FAQs - questions about using Cloud TPUs with PyTorch.

## Framework independent FAQs

### How do I check which process is using the TPU on a Cloud TPU VM?

Run `tpu-info` on the Cloud TPU VM to print the process ID and
other information about the process using the TPU. See [supported metrics](https://docs.cloud.google.com/tpu/docs/tpu-monitoring-library.md.txt#list-all-supported-metric-names) for the metrics
and their corresponding definitions.

```bash
   tpu-info
```

The output from `tpu-info` is similar to the following:

```bash
   TPU Chips
   ┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━┓
   ┃ Chip        ┃ Type        ┃ Devices ┃ PID    ┃
   ┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━┩
   │ /dev/accel0 │ TPU v4 chip │ 1       │ 130007 │
   │ /dev/accel1 │ TPU v4 chip │ 1       │ 130007 │
   │ /dev/accel2 │ TPU v4 chip │ 1       │ 130007 │
   │ /dev/accel3 │ TPU v4 chip │ 1       │ 130007 │
   └─────────────┴─────────────┴─────────┴────────┘

   TPU Runtime Utilization
   ┏━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
   ┃ Device ┃ Memory usage         ┃ Duty cycle ┃
   ┡━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
   │ 0      │ 0.00 GiB / 31.75 GiB │      0.00% │
   │ 1      │ 0.00 GiB / 31.75 GiB │      0.00% │
   │ 2      │ 0.00 GiB / 31.75 GiB │      0.00% │
   │ 3      │ 0.00 GiB / 31.75 GiB │      0.00% │
   └────────┴──────────────────────┴────────────┘

   TensorCore Utilization
   ┏━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓
   ┃ Chip ID ┃ TensorCore Utilization ┃
   ┡━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
   │ 0       │                  0.00% │
   │ 1       │                  0.00% │
   │ 3       │                  0.00% │
   │ 2       │                  0.00% |
   └─────────┴────────────────────────┘

   Buffer Transfer Latency
   ┏━━━━━━━━━━━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━━┓
   ┃ Buffer Size ┃ P50 ┃ P90 ┃ P95 ┃ P999 ┃
   ┡━━━━━━━━━━━━━╇━━━━━╇━━━━━╇━━━━━╇━━━━━━┩
   │       8MB+  | 0us │ 0us │ 0us │  0us |
   └─────────────┴─────┴─────┴─────┴──────┘

```

### How do I add a persistent disk volume to a Cloud TPU VM?

For more information, see [Attach durable block storage to a TPU VM](https://docs.cloud.google.com/tpu/docs/attach-durable-block-storage-compute.md.txt).

### What storage options are supported or recommended for training with TPU VM?

For more information, see [Cloud TPU storage options](https://docs.cloud.google.com/tpu/docs/storage-options.md.txt).

## JAX FAQs

### How do I know if the TPU is being used by my program?

There are a few ways to double check JAX is using the TPU:

1. Use the `jax.devices()` function. For example:

   ```python
   assert jax.devices()[0].platform == 'tpu'
   ```
2. Profile your program and verify the profile contains TPU operations. For more
   information, see [Profiling JAX programs](https://github.com/google/jax/blob/main/docs/profiling.md)

For more information, see [JAX FAQ](https://jax.readthedocs.io/en/latest/faq.html)

## PyTorch FAQs

### How do I know if the TPU is being used by my program?

You can verify that PyTorch is using the TPU with TorchTPU in the following
ways:

1. Check the active accelerator device in Python:

   ```python
   import torch

   assert torch.accelerator.current_accelerator().type == "tpu"
   ```
2. Profile your workload with `torch.profiler` and verify that TPU operations
   appear in the trace. For more information, see
   [Performance profiling with XProf](https://torchtpu.readthedocs.io/en/latest/performance_profiling_with_xprof/).

For more information, see
[PyTorch on Cloud TPU](https://docs.cloud.google.com/tpu/docs/pytorch-on-tpu.md.txt), the
[TorchTPU documentation](https://torchtpu.readthedocs.io/en/latest/), and the
[TorchTPU FAQ](https://torchtpu.readthedocs.io/en/latest/faq/).