2018-11-17 18:03:33 -08:00
|
|
|
# Copyright 2018 Google LLC
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2019-07-29 15:06:05 -04:00
|
|
|
|
|
|
|
# This module is largely a wrapper around `jaxlib` that performs version
|
|
|
|
# checking on import.
|
|
|
|
|
2020-06-04 15:27:48 -07:00
|
|
|
__all__ = [
|
2020-12-05 00:07:04 +01:00
|
|
|
'cuda_prng', 'cusolver', 'rocsolver', 'jaxlib', 'lapack',
|
2021-02-04 15:13:39 -08:00
|
|
|
'pocketfft', 'pytree', 'tpu_client', 'version', 'xla_client'
|
2020-06-04 15:27:48 -07:00
|
|
|
]
|
|
|
|
|
2021-03-15 21:07:59 -04:00
|
|
|
try:
|
|
|
|
import jaxlib
|
|
|
|
except ModuleNotFoundError as err:
|
|
|
|
raise ModuleNotFoundError(
|
|
|
|
'jax requires jaxlib to be installed. See '
|
|
|
|
'https://github.com/google/jax#installation for installation instructions.'
|
|
|
|
) from err
|
2019-07-29 15:06:05 -04:00
|
|
|
|
2020-09-15 10:45:15 +02:00
|
|
|
# Must be kept in sync with the jaxlib version in build/test-requirements.txt
|
2021-03-16 12:13:41 -04:00
|
|
|
_minimum_jaxlib_version = (0, 1, 62)
|
2019-07-29 15:06:05 -04:00
|
|
|
try:
|
|
|
|
from jaxlib import version as jaxlib_version
|
2020-03-09 22:06:12 +02:00
|
|
|
except Exception as err:
|
2019-07-29 15:06:05 -04:00
|
|
|
# jaxlib is too old to have version number.
|
|
|
|
msg = 'This version of jax requires jaxlib version >= {}.'
|
2020-03-09 22:06:12 +02:00
|
|
|
raise ImportError(msg.format('.'.join(map(str, _minimum_jaxlib_version)))
|
|
|
|
) from err
|
2019-07-29 15:06:05 -04:00
|
|
|
|
2019-09-04 16:24:32 -04:00
|
|
|
version = tuple(int(x) for x in jaxlib_version.__version__.split('.'))
|
2019-07-29 15:06:05 -04:00
|
|
|
|
|
|
|
# Check the jaxlib version before importing anything else from jaxlib.
|
|
|
|
def _check_jaxlib_version():
|
|
|
|
if version < _minimum_jaxlib_version:
|
|
|
|
msg = 'jaxlib is version {}, but this version of jax requires version {}.'
|
2019-10-15 08:52:21 -04:00
|
|
|
|
|
|
|
if version == (0, 1, 23):
|
2020-08-19 18:39:25 +02:00
|
|
|
msg += ('\n\nA common cause of this error is that you installed jaxlib '
|
|
|
|
'using pip, but your version of pip is too old to support '
|
|
|
|
'manylinux2010 wheels. Try running:\n\n'
|
|
|
|
'pip install --upgrade pip\n'
|
|
|
|
'pip install --upgrade jax jaxlib\n')
|
2019-07-29 15:06:05 -04:00
|
|
|
raise ValueError(msg.format('.'.join(map(str, version)),
|
|
|
|
'.'.join(map(str, _minimum_jaxlib_version))))
|
|
|
|
|
|
|
|
_check_jaxlib_version()
|
|
|
|
|
|
|
|
from jaxlib import xla_client
|
|
|
|
from jaxlib import lapack
|
2021-02-04 15:13:39 -08:00
|
|
|
from jaxlib import pocketfft
|
2021-01-14 14:21:01 -05:00
|
|
|
|
2021-01-20 12:43:00 -08:00
|
|
|
xla_extension = xla_client._xla
|
2021-01-14 14:21:01 -05:00
|
|
|
pytree = xla_client._xla.pytree
|
|
|
|
jax_jit = xla_client._xla.jax_jit
|
2021-01-16 17:57:39 +01:00
|
|
|
pmap_lib = xla_client._xla.pmap_lib
|
2020-12-05 00:07:04 +01:00
|
|
|
|
|
|
|
try:
|
2021-01-13 13:02:53 -08:00
|
|
|
from jaxlib import cusolver # pytype: disable=import-error
|
2020-12-05 00:07:04 +01:00
|
|
|
except ImportError:
|
|
|
|
cusolver = None
|
|
|
|
|
|
|
|
try:
|
2020-12-17 14:01:04 -08:00
|
|
|
from jaxlib import rocsolver # pytype: disable=import-error
|
2020-12-05 00:07:04 +01:00
|
|
|
except ImportError:
|
|
|
|
rocsolver = None
|
|
|
|
|
2019-11-24 13:06:23 -05:00
|
|
|
try:
|
2021-01-13 13:02:53 -08:00
|
|
|
from jaxlib import cuda_prng # pytype: disable=import-error
|
2019-11-24 13:06:23 -05:00
|
|
|
except ImportError:
|
|
|
|
cuda_prng = None
|
2020-05-12 11:05:03 -07:00
|
|
|
|
2021-01-05 13:23:57 -08:00
|
|
|
# Jaxlib code is split between the Jax and the Tensorflow repositories.
|
|
|
|
# Only for the internal usage of the JAX developers, we expose a version
|
|
|
|
# number that can be used to perform changes without breaking the master
|
|
|
|
# branch on the Jax github.
|
|
|
|
_xla_extension_version = getattr(xla_client, '_version', 0)
|
|
|
|
|
2020-05-12 11:05:03 -07:00
|
|
|
try:
|
|
|
|
from jaxlib import tpu_client # pytype: disable=import-error
|
|
|
|
except:
|
|
|
|
tpu_client = None
|