2022-09-22 12:26:48 -07:00
|
|
|
# Copyright 2018 The JAX Authors.
|
2018-11-17 18:03:33 -08:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2020-07-10 08:11:48 -07:00
|
|
|
# Set default logging level before any logging happens.
|
|
|
|
import os as _os
|
|
|
|
_os.environ.setdefault('TF_CPP_MIN_LOG_LEVEL', '1')
|
|
|
|
del _os
|
|
|
|
|
2021-03-05 14:57:36 -08:00
|
|
|
# Set Cloud TPU env vars if necessary before transitively loading C++ backend
|
2021-11-24 07:47:48 -08:00
|
|
|
from jax._src.cloud_tpu_init import cloud_tpu_init as _cloud_tpu_init
|
2021-03-05 14:57:36 -08:00
|
|
|
try:
|
|
|
|
_cloud_tpu_init()
|
|
|
|
except Exception as exc:
|
|
|
|
# Defensively swallow any exceptions to avoid making jax unimportable
|
|
|
|
from warnings import warn as _warn
|
|
|
|
_warn(f"cloud_tpu_init failed: {repr(exc)}\n This a JAX bug; please report "
|
|
|
|
f"an issue at https://github.com/google/jax/issues")
|
|
|
|
del _warn
|
|
|
|
del _cloud_tpu_init
|
|
|
|
|
2021-04-19 08:52:48 -07:00
|
|
|
# Confusingly there are two things named "config": the module and the class.
|
|
|
|
# We want the exported object to be the class, so we first import the module
|
|
|
|
# to make sure a later import doesn't overwrite the class.
|
2021-11-24 07:47:48 -08:00
|
|
|
from jax import config as _config_module
|
2021-04-19 08:52:48 -07:00
|
|
|
del _config_module
|
|
|
|
|
2022-09-23 09:59:46 -07:00
|
|
|
from jax._src.basearray import Array as Array
|
|
|
|
|
2021-11-24 07:47:48 -08:00
|
|
|
from jax._src.config import (
|
2021-08-30 14:35:22 -07:00
|
|
|
config as config,
|
|
|
|
enable_checks as enable_checks,
|
|
|
|
check_tracer_leaks as check_tracer_leaks,
|
|
|
|
checking_leaks as checking_leaks,
|
|
|
|
enable_custom_prng as enable_custom_prng,
|
2022-03-28 17:17:33 -07:00
|
|
|
enable_custom_vjp_by_custom_transpose as enable_custom_vjp_by_custom_transpose,
|
2021-08-30 14:35:22 -07:00
|
|
|
debug_nans as debug_nans,
|
|
|
|
debug_infs as debug_infs,
|
|
|
|
log_compiles as log_compiles,
|
2022-06-02 10:33:53 -07:00
|
|
|
default_device as default_device,
|
2021-08-30 14:35:22 -07:00
|
|
|
default_matmul_precision as default_matmul_precision,
|
2021-10-07 19:15:43 -07:00
|
|
|
default_prng_impl as default_prng_impl,
|
2022-05-26 10:56:09 -07:00
|
|
|
numpy_dtype_promotion as numpy_dtype_promotion,
|
2021-08-30 14:35:22 -07:00
|
|
|
numpy_rank_promotion as numpy_rank_promotion,
|
2022-02-14 13:11:26 -08:00
|
|
|
jax2tf_associative_scan_reductions as jax2tf_associative_scan_reductions,
|
|
|
|
transfer_guard as transfer_guard,
|
|
|
|
transfer_guard_host_to_device as transfer_guard_host_to_device,
|
|
|
|
transfer_guard_device_to_device as transfer_guard_device_to_device,
|
|
|
|
transfer_guard_device_to_host as transfer_guard_device_to_host,
|
2021-04-19 08:52:48 -07:00
|
|
|
)
|
2022-01-10 20:57:56 -08:00
|
|
|
from .core import eval_context as ensure_compile_time_eval
|
2022-09-12 15:39:33 -07:00
|
|
|
from jax._src.environment_info import print_environment_info as print_environment_info
|
2021-11-24 07:47:48 -08:00
|
|
|
from jax._src.api import (
|
2020-05-07 17:24:19 -04:00
|
|
|
ad, # TODO(phawkins): update users to avoid this.
|
2022-05-16 18:55:52 -07:00
|
|
|
effects_barrier,
|
2021-12-14 11:02:14 -08:00
|
|
|
block_until_ready,
|
2021-08-30 14:35:22 -07:00
|
|
|
checkpoint as checkpoint,
|
|
|
|
checkpoint_policies as checkpoint_policies,
|
2022-07-20 15:09:47 -07:00
|
|
|
clear_backends as clear_backends,
|
2021-08-30 14:35:22 -07:00
|
|
|
closure_convert as closure_convert,
|
2020-05-07 17:24:19 -04:00
|
|
|
curry, # TODO(phawkins): update users to avoid this.
|
2021-08-30 14:35:22 -07:00
|
|
|
custom_gradient as custom_gradient,
|
|
|
|
custom_jvp as custom_jvp,
|
|
|
|
custom_vjp as custom_vjp,
|
|
|
|
default_backend as default_backend,
|
|
|
|
device_count as device_count,
|
|
|
|
device_get as device_get,
|
|
|
|
device_put as device_put,
|
|
|
|
device_put_sharded as device_put_sharded,
|
|
|
|
device_put_replicated as device_put_replicated,
|
|
|
|
devices as devices,
|
|
|
|
disable_jit as disable_jit,
|
|
|
|
eval_shape as eval_shape,
|
2020-05-07 17:24:19 -04:00
|
|
|
flatten_fun_nokwargs, # TODO(phawkins): update users to avoid this.
|
2021-08-30 14:35:22 -07:00
|
|
|
float0 as float0,
|
|
|
|
grad as grad,
|
|
|
|
hessian as hessian,
|
|
|
|
host_count as host_count,
|
|
|
|
host_id as host_id,
|
|
|
|
host_ids as host_ids,
|
|
|
|
jacobian as jacobian,
|
|
|
|
jacfwd as jacfwd,
|
|
|
|
jacrev as jacrev,
|
|
|
|
jit as jit,
|
|
|
|
jvp as jvp,
|
|
|
|
local_device_count as local_device_count,
|
|
|
|
local_devices as local_devices,
|
|
|
|
linearize as linearize,
|
|
|
|
linear_transpose as linear_transpose,
|
|
|
|
make_jaxpr as make_jaxpr,
|
|
|
|
named_call as named_call,
|
2022-05-25 12:02:35 -07:00
|
|
|
named_scope as named_scope,
|
2021-08-30 14:35:22 -07:00
|
|
|
pmap as pmap,
|
|
|
|
process_count as process_count,
|
|
|
|
process_index as process_index,
|
2022-08-15 17:05:27 -07:00
|
|
|
pure_callback as pure_callback,
|
2020-05-07 17:24:19 -04:00
|
|
|
pxla, # TODO(phawkins): update users to avoid this.
|
2021-08-30 14:35:22 -07:00
|
|
|
remat as remat,
|
|
|
|
ShapedArray as ShapedArray,
|
|
|
|
ShapeDtypeStruct as ShapeDtypeStruct,
|
2021-09-14 13:55:55 -07:00
|
|
|
value_and_grad as value_and_grad,
|
|
|
|
vjp as vjp,
|
|
|
|
vmap as vmap,
|
2020-05-07 17:24:19 -04:00
|
|
|
xla, # TODO(phawkins): update users to avoid this.
|
2021-09-14 13:55:55 -07:00
|
|
|
xla_computation as xla_computation,
|
2020-05-07 17:24:19 -04:00
|
|
|
)
|
2022-09-27 10:06:10 -07:00
|
|
|
|
|
|
|
from jax._src.array import (
|
|
|
|
make_array_from_single_device_arrays as make_array_from_single_device_arrays,
|
|
|
|
make_array_from_callback as make_array_from_callback,
|
|
|
|
)
|
|
|
|
|
2021-11-24 07:47:48 -08:00
|
|
|
from jax.version import __version__ as __version__
|
2022-04-05 12:42:43 -07:00
|
|
|
from jax.version import __version_info__ as __version_info__
|
2020-05-07 17:24:19 -04:00
|
|
|
|
2022-07-07 11:41:46 -07:00
|
|
|
from jax._src.tree_util import (
|
2022-07-28 11:33:01 -07:00
|
|
|
tree_map as tree_map,
|
|
|
|
# TODO(jakevdp): remove these deprecated routines after October 2022
|
2022-07-07 11:41:46 -07:00
|
|
|
_deprecated_treedef_is_leaf as treedef_is_leaf,
|
|
|
|
_deprecated_tree_flatten as tree_flatten,
|
|
|
|
_deprecated_tree_leaves as tree_leaves,
|
|
|
|
_deprecated_tree_structure as tree_structure,
|
|
|
|
_deprecated_tree_transpose as tree_transpose,
|
|
|
|
_deprecated_tree_unflatten as tree_unflatten,
|
|
|
|
)
|
|
|
|
|
2020-05-19 20:40:03 +01:00
|
|
|
# These submodules are separate because they are in an import cycle with
|
|
|
|
# jax and rely on the names imported above.
|
2021-11-24 07:47:48 -08:00
|
|
|
from jax import abstract_arrays as abstract_arrays
|
|
|
|
from jax import api_util as api_util
|
|
|
|
from jax import distributed as distributed
|
2022-07-26 14:47:36 -07:00
|
|
|
from jax import debug as debug
|
2021-11-24 07:47:48 -08:00
|
|
|
from jax import dtypes as dtypes
|
|
|
|
from jax import errors as errors
|
|
|
|
from jax import image as image
|
|
|
|
from jax import lax as lax
|
|
|
|
from jax import nn as nn
|
|
|
|
from jax import numpy as numpy
|
|
|
|
from jax import ops as ops
|
|
|
|
from jax import profiler as profiler
|
|
|
|
from jax import random as random
|
2022-09-27 10:06:10 -07:00
|
|
|
from jax import sharding as sharding
|
2022-03-14 19:38:23 -07:00
|
|
|
from jax import stages as stages
|
2021-11-24 07:47:48 -08:00
|
|
|
from jax import tree_util as tree_util
|
|
|
|
from jax import util as util
|
2020-05-07 17:24:19 -04:00
|
|
|
|
2021-09-23 06:33:25 -07:00
|
|
|
import jax.lib # TODO(phawkins): remove this export.
|
2022-09-09 07:05:30 -07:00
|
|
|
|
|
|
|
del jax._src
|