Installation with TPU

vLLM supports Google Cloud TPUs using PyTorch XLA.

Requirements

  • Google Cloud TPU VM (single host)

  • TPU versions: v5e, v5p, v4

  • Python: 3.10

Installation options:

  1. Build a docker image with Dockerfile.

  2. Build from source.

Build a docker image with Dockerfile.tpu

Dockerfile.tpu is provided to build a docker image with TPU support.

  1. $ docker build -f Dockerfile.tpu -t vllm-tpu .

You can run the docker image with the following command:

  1. $ # Make sure to add `--privileged --net host --shm-size=16G`.
  2. $ docker run --privileged --net host --shm-size=16G -it vllm-tpu

Build from source

You can also build and install the TPU backend from source.

First, install the dependencies:

  1. $ # (Recommended) Create a new conda environment.
  2. $ conda create -n myenv python=3.10 -y
  3. $ conda activate myenv
  4. $ # Clean up the existing torch and torch-xla packages.
  5. $ pip uninstall torch torch-xla -y
  6. $ # Install PyTorch and PyTorch XLA.
  7. $ export DATE="+20240713"
  8. $ pip install https://storage.googleapis.com/pytorch-xla-releases/wheels/tpuvm/torch-nightly${DATE}-cp310-cp310-linux_x86_64.whl
  9. $ pip install https://storage.googleapis.com/pytorch-xla-releases/wheels/tpuvm/torch_xla-nightly${DATE}-cp310-cp310-linux_x86_64.whl
  10. $ # Install JAX and Pallas.
  11. $ pip install torch_xla[tpu] -f https://storage.googleapis.com/libtpu-releases/index.html
  12. $ pip install torch_xla[pallas] -f https://storage.googleapis.com/jax-releases/jax_nightly_releases.html -f https://storage.googleapis.com/jax-releases/jaxlib_nightly_releases.html
  13. $ # Install other build dependencies.
  14. $ pip install packaging aiohttp

Next, build vLLM from source. This will only take a few seconds:

  1. $ VLLM_TARGET_DEVICE="tpu" python setup.py develop

Tip

If you encounter the following error:

  1. from torch._C import * # noqa: F403
  2. ImportError: libopenblas.so.0: cannot open shared object file: No such file or directory

Please install OpenBLAS with the following command:

  1. $ sudo apt-get install libopenblas-base libopenmpi-dev libomp-dev