Google Cloud TPU Runtime Library

0.0.39 · active · verified Sat Apr 11

The `libtpu` library is a low-level runtime component that provides the interface for Python-based machine learning frameworks (such as JAX and PyTorch/XLA) to communicate with Google Cloud TPUs. It is primarily a dependency managed by these high-level frameworks rather than a library intended for direct user application development. The current version is 0.0.39 and it requires Python >= 3.11. It has no strict release cadence, with updates typically coinciding with changes in underlying TPU infrastructure or integrations with ML frameworks.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to verify the presence and configuration of TPU devices using JAX, which is the most common way users interact with the capabilities provided by `libtpu`. Running this code on a Google Cloud TPU instance with `jax[tpu]` installed will confirm `libtpu`'s operational status.

import os

# This quickstart demonstrates checking for TPU devices using JAX,
# which implicitly relies on `libtpu` being correctly installed and configured.
# Direct usage of `libtpu`'s API for application logic is rare.

try:
    import jax
    # The following line will only succeed if libtpu is correctly installed
    # and a TPU device is available and configured in the environment.
    tpu_devices = jax.devices('tpu')
    print(f"Found {len(tpu_devices)} TPU devices: {tpu_devices}")
    if tpu_devices:
        print("libtpu is likely working correctly with JAX on a TPU.")
    else:
        print("No TPU devices found. libtpu may be installed, but no TPU is available or configured.")
except ImportError:
    print("JAX is not installed. Please install JAX with TPU support: pip install jax[tpu]")
except Exception as e:
    print(f"An error occurred while checking for TPU devices: {e}")
    print("This could indicate an issue with libtpu installation or TPU environment configuration.")

view raw JSON →