iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐍

Installing google/jax with Poetry

に公開

Background

I was troubled because google/jax does not support PEP 503.
https://github.com/google/jax/issues/5410

There is also an issue on the Poetry side.

https://github.com/python-poetry/poetry/issues/5481

It seems that something equivalent to pip's --find-links has been implemented since version 1.2.0.
https://github.com/python-poetry/poetry/issues/1391
https://github.com/python-poetry/poetry/pull/5517

It looks like it can be installed from this version onwards.

Installation Method

$ poetry source add jax https://storage.googleapis.com/jax-releases/jax_releases.html
$ poetry add --source jax jaxlib
$ poetry add jax

With this, 0.3.20+cuda11.cudnn82 of jaxlib was installed, and JAX can now recognize CUDA.

How It Works

jax[cuda] and jax[tpu] are installation methods using a mechanism called extras.

https://peps.python.org/pep-0508/#extras

On the package side, this can be specified by writing extras_require in setup.py.

https://github.com/google/jax/blob/09720b9bcbf07c1318774033f1cb4f4751e37895/setup.py#L78-L98

JAX's mechanism seems to switch backends by changing the jaxlib implementation depending on the extras.

Discussion