Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Can TPUs be used with PyTorch or Keras for large-scale AI projects


Can TPUs be used with PyTorch or Keras for large-scale AI projects


Yes, TPUs can be used with both PyTorch and Keras for large-scale AI projects.

PyTorch on TPUs

PyTorch can run on TPUs, thanks to collaborations between Google's TPU team and PyTorch developers. This integration is facilitated by tools like PyTorch Lightning, which allows PyTorch code to run on TPUs without modifications. PyTorch Lightning uses XLA (Accelerated Linear Algebra) to translate calculations for different accelerators, enabling efficient use of TPUs. However, TPUs are typically accessed through Google Cloud services, and they are not available for purchase as standalone hardware for personal use[1][3].

Keras on TPUs

Keras, being a multi-framework API, can also leverage TPUs, especially when used with TensorFlow or JAX as the backend. Keras models can be easily adapted to run on TPUs by switching the backend to JAX, which supports large-scale TPU training. This flexibility allows developers to write Keras code that can be executed on various platforms, including Google Cloud TPUs[2][5]. However, not all Keras operations are compatible with TPUs; for example, UpSampling2D is not fully supported[7].

In summary, both PyTorch and Keras can utilize TPUs for large-scale AI projects, but the setup and compatibility may vary depending on the specific use case and backend framework chosen.

Citations:
[1] https://www.reddit.com/r/MachineLearning/comments/faahsp/news_you_can_now_run_pytorch_code_on_tpus/
[2] https://towardsdatascience.com/multi-framework-ai-ml-development-with-keras-3-cf7be29eb23d/
[3] https://discuss.pytorch.org/t/pytorch-tpu-support/25504
[4] https://www.pickl.ai/blog/pytorch-vs-tensorflow-vs-keras/
[5] https://keras.io/about/
[6] https://massedcompute.com/faq-answers/?question=Can+TPUs+be+used+with+TensorFlow+and+PyTorch+for+deep+learning+tasks%3F
[7] https://stackoverflow.com/questions/53215477/where-can-i-identify-which-keras-methods-are-tpu-compatible-methods
[8] https://www.linkedin.com/pulse/comparison-ai-frameworks-tensorflow-vs-pytorch-keras-emma-al-naw5f